Archive for the Work Category

Agile Development Workflow Part 2 - Love the sync

Continuation of Agile Development Workflow Part 1 - Setup (I’d start there). sync My lively-hood depends on the sync. It’s really what pulls all my projects together and unifies my workflow. It allows me to develop in numerous web technologies like Ruby On Rails, PHP, Django, Catalyst with relative ease, all at once. The Sync process is based on customized rsync commands. Assuming that you set up ssh properly (see Part 1), all we have to do now is create our shell script that does the heavy lifting for us. Essentially we’re pushing all of our changes up to the server as we see fit. Rsync can be customized to upload only the files that change with relative ease.

The first thing we’ll want to do is create the sync file which will be responsible for handling the rsync process. In the command line do:

macAttack: kb$ sudo touch /usr/bin/sync 
macAttack: kb$ sudo chmod +x /usr/bin/sync 
macAttack: kb$ mate /usr/bin/sync

You should be staring at an empty file. What we want to do is replicate the process you would usually do to push the site up live, or upload it to your development server via ftp.

It’s important that you have a consistent directory structure for your websites to get all of these “rules” setup (assuming that you’ll be working with multiple sites) properly. It will allow us to setup new rules with minimal effort.

I use Subversion (svn) for all of my projects and because of this I have a common directory structure for most of my web apps. It looks like this:

macAttack: kb$ /Development/Project/trunk/

For branches the directory structure looks like this:

macAttack: kb$ /Development/Project/branches/name

The beauty of syncing is all changes get moved over, overwriting the previous files so you rarely run into any sync errors and if you do it’s usually user error. :)

Here are the contents of my sync script (simplified)

#!/bin/bash

REPO=”" SRC=”" BRANCH=”" DEV=”Development” HOME=”/Users/kb”

case $1 in s) rsync –exclude-from=$HOME/.rsync-exclude -e “ssh” -ruv $HOME/$DEV/somedirection/trunk/blog/ serveradmin@mediatemple.com:~/domains/somedirection.com/html/ exit ;; *) echo “Unrecognized” ;; esac

Let’s break it down.

  1. –exclude-from=$HOME is setup to be the same path that relates to ~/. In my user home dir ~/ there’s a file named .rsync-exclude, this file is a line-break separated list of filenames we want to exclude in our sync. Check out my exclude list » rsync exclude. The exclude list prevents .svn (subversion dir’s) from being pushed to the remote server, so you can work on a checked out copy of your web project, but the server only gets what it needs without any unnecessary files.
  2. -e “ssh” tells rsync to go over ssh to sync the files, since we already set up ssh to enable auto-login to the remote server we won’t be prompted to provide a password on every sync (and you will sync alot).
  3. finally we pass the parameters -ruv -r, –recursive recurse into directories #this way you only have to pass a top level path -u, –update update only (don’t overwrite newer files) #it’s important that your computers internal clock matches the remote servers -v, –verbose increase verbosity
  4. The Local Path: $HOME/$DEV/somedirection/trunk/blog/
  5. The Remote Path: serveradmin@mediatemple.com:~/domains/somedirection.com/html/ => username@remotehost:remotepath
  6. If the following command is run from from Terminal:

    macAttack: kb$/usr/bin/sync s
    If all goes well you should get verbose output from your sync!

    Rsync is a powerful tool, can work wonders with backups as well.

    Let me know if you found this article helpful and give feedback. Stay tuned for Sync integration with TextMate that will really put your whole dev process in overdrive!

    Popularity: 20% [?]

PHP and Smarty First Impressions

Smarty Logo Recently I’ve begun work on a newer, cooler, better, version of Costumzee.com with the elite hax0rs over at Mech Media. Scott and I decided to utilize a php temple engine called Smarty for better separation of code and presentation. A couple things worth noting before I dig in here:

  1. The extent of my PHP knowledge is minimal - what I know of PHP is what I’ve done when tinkering with WordPress
  2. My knowledge of backend web development is also minimal. I’ve been a frontend guy my whole web career. I pwn xhtml/css/javascript, but server-side dev is completely new to me (I’m finally nipping that knowledge-gap in the butt).
  3. I do have knowledge of template engines. When I worked on Quibblo.com full time, we used the Perl Catalyst Framework and I got savvy with Template Toolkit which allowed me to dive into Smarty fairly quickly.
But without further ado.. Couple things I Love about Smarty
  • The {debug} function. At the drop of a hat I can see everything available to me and integrate it on the front end (.tpl files).
  • Plugins. I needed a way to paginate, and with minimal knowledge I was able to leverage SmartyPaginate to get the job done.
  • I was productive day 1. It’s PHP (which is not a challenging language to begin with) and there’s a separation of code and presentation. I’ve dabbled with ROR, and the learning curve of doing something productive, interesting, and unique is just so much easier, because you don’t have to worry “am I doing this the way they want me to?”.
  • Smarty documentation is awesome. It’s brief and concise with really world useful examples. When I do get tripped up with something Smarty related it’s a matter of referencing the documentation and in a couple minutes I’m on my way.

The very few things that I’ve gotten stuck on have been mostly due to a lack of my PHP knowledge and not so much a result of issues with Smarty so far. And unique to my situation, I had Scott right there to bounce questions off of when I hit a wall which was also great.

All in all it’s a great to leverage a templating engine like Smarty when you’re beginning to learn more about backend web development. I’ve always shied away from it because I was always working with other programmers that were more than capable in that area and my talents were always restricted to the front-side of the glorious interweb.

I was never interested much in PHP. I always felt like the future of the web was with a framework like Ruby On Rails, but I am pleasantly surprised with my Smarty experience so far and it’s made me excited to develop with PHP more down the road.

Currently, I’m developing with ROR and Smarty and I hope to compare and contrast the two in the future, stay tuned.

Popularity: 11% [?]