Archive for category Zend Framework
OpenVPN Setup tips
Posted by Stuart in Zend Framework on May 24, 2010
To send all traffic over an established VPN connection:
sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
sudo -s echo “1″ > /proc/sys/net/ipv4/ip_forward
sudo openvpn /etc/openvpn/server.conf
SSH Tunneling Tips: Now With More Awesome!
Posted by Stuart in Zend Framework on May 23, 2010
OK, that previous tip was pretty weak. Try this instead. Set up a SOCKS proxy and tunnel it through SSH!
Here’s how:
1. Open the SSH connection…
ssh -ND 8887 -p 22 rufus@83.27.411.896
2. Set your network to point to the proxy. On a Mac that would be…
a. Open Network Preferences…
b. Click Advanced…
c. Click Proxies…
d. Check the SOCKS Proxy box then in the SOCKS Proxy Server field enter localhost and the port you used (8887)
e. OK and Apply and you are done!
p.s. Bonus! You can enable gzip compression by setting the -C flag (ex. ssh -C -ND 8887 -p 22 rufus@83.27.411.896)
SSH Tunneling Tips
Posted by Stuart in Zend Framework on May 23, 2010
To tunnel one, single website over SSH:
ssh -L 8887:google.com:80 -p 22 -l rufus -N 83.27.411.896
Explanation:
The first port, 8887, is the one on your local machine that you are going to point your proxy to….
… next comes the website you are visiting…
… next is the port of the service on the remote computer you will be accessing
Web: HTTP 80
Web over SSL: HTTPS 443
Outgoing email: SMTP 25
Incoming email: POP3 110
Incoming email: IMAP 143
… next comes the port your SSH is set to (default is 22)…
… next is the user you will log in as…
… next is the address of the ssh server you are accessing.
That’s it. But you only gain access to Google. Try to go outside of that and you will get sent back to Google.
Mercurial – pushing changes to a remote site
Posted by Stuart in Zend Framework on April 28, 2010
OK, this was not straight forward but it was mainly because of paths and permissions issues.
My local repository is here: /Applications/MAMP/htdocs/aproj/
On the remote machine I need to get a copy of this so I issue the following:
sudo hg -v clone ssh://me@192.168.1.107//Applications/MAMP/htdocs/aproj/ /var/www/aproj/
This will clone the repository.
After making changes I try to push them from the local repo to the remote server using:
sudo hg push ssh://me@192.168.1.105//var/www/aproj/
but this will fail with the error:
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: abort: could not lock repository /var/www/aproj/: Permission denied
abort: unexpected response: empty string
This stems from the local repo having different owner (and group?) from the remote.
I can, however, do a pull from the remote repo (note I am inside var/www/aproj/:
sudo hg pull
Then update to implement the pulled changes:
sudo hg update
and that gets things working for the time being.
One really weird thing I ran into. on the local machine I can issue a command to mercurial with no problem. For example:
hg info
However, doing that via ssh from the remote server failed with the message that ‘hg could not be found’. The path to hg was set correctly (as evidence by ‘echo $PATH’) but I still had to symlink hg from /usr/bin/ in order to get it to work (from the remote machine… it worked fine locally).
Update: how to fix the untrusted user error… in your .hgrc add:
[trusted]
users=*
groups=*
Enable Color in Mac OS X Terminal
Posted by Stuart in Zend Framework on April 23, 2010
Want to colorize your ls output in Terminal? Stick this in your ~/.bashrc or ~/.bash_profile files:
export CLICOLOR=1
While you are at it add this alias to include invisible files in ls:
alias ls='ls -la'
Oh! One more useful one… to reload your .bash_profile without quitting and restarting the shell:
source ~/.bash_profile
The iTunes Window Extends Off Screen and I Can’t Resize It, Help!
Posted by Stuart in Zend Framework on April 22, 2010
So you thought you could click the little plus button at the window’s top left corner (the green one unless you use the alternate Mac color scheme) to resize and you discovered that that only opens a tiny control panel?
Here is the big secret… hold down the option key while clicking the button with the plus on it at top left. Done! I love easy.
Wrap many lines of text in list item tags using RegEx
Posted by Stuart in Zend Framework on April 16, 2010
So I have an email with a huge list of names. They are displayed one per line. I want to wrap them in list item tags so I can stick them in an unordered list. Here is how to do it fast and painlessly…
First, here is what I start with (just imagine 1000 names, rather than 3):
Bob Smith, Acme Corp, CEO Janet Johnson, Barton Inc, VP for Development and Shoe Sizes Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments
Here is the regex I will find and replace with:
Find:
(.*)\r
Replace (pretend that last “\r” is right next to the list item closing tag:
The find code looks for anything with a carriage return at the end and then grabs the bit in the parenthesis.
The replace code wraps that bit in the parenthesis (signified by the \1), wraps it in list item tags and sticks a carriage return on the end.
Now my list looks like:
Basic secure file copying using SCP
Posted by Stuart in Zend Framework on April 15, 2010
Securely copy a file from one computer to another (in this example on my local network):
$ sudo scp stuart@192.168.1.100:Downloads/somefile.iso /home/stuart/downloads
This will copy the file somefile.iso that is in my remote computer’s home dir’s Download directory ~/Downloads/ or put another way as the remote computer is a Mac /Users/stuart/Downloads/ over to the local computer’s dir at /home/stuart/downloads/
Zend Framework – Conditionally Load Javascript Files
Posted by Stuart in Snippets, Zend Framework, jquery on April 6, 2010
I needed to load javascript files on a per controller basis in a Zend Framework (ZF) based project. In the past I would have done this with some conditional logic that would load things based on a page number or name or some such. In ZF all that is needed is to stick some code in the controller’s init method, a line in the layout header and we are good to go.
Here is the code to stick in your controller:
public function init()
{
$this->view->headScript()->appendFile('/mysite/public/js/somefile.js')
->appendFile('/mysite/public/js/someother.js');
}
Here is the line you stick in the layout.phtml header:
echo $this->headScript();
That’s it! Now you can have controller specific js loaded and keep your sites code overhead under control by keeping uneeded js files out of your layout.phtml.
Interesting Article about Caching Models in Zend Framework
Posted by Stuart in Zend Framework on May 12, 2009
Interesting article over at http://www.contentwithstyle.co.uk/content/a-caching-pattern-for-models about implementing caching with Zend Framework models. In the comments there is a good point about how to refresh such a cache with the author suggesting using something like a $this->cache->clear() to clear the cache upon adding or updating content.





