New beginnings

I’ve taken up the full time position of CTO at BERG, after working for them for many months of freelance work. The company trajectory is really exciting, and I feel really privileged to be working along side such great people. Over the coming months, there will be some exciting work that we’ll be unveiling, and I’ll be helping shape the technology side of that future work.

Augmenting your shell prompt with Git information

I use git, and from time to time I use the ‘stash’ feature. This is a boon when performing certain tasks, but can also get you into trouble if you don’t carefully manage what you’ve stashed. To this end, I modified my bash shell prompt to help me remember.

Normally my shell prompt gives me fairly standard information. Current working directory, time, hostname and current user.

[nick@20:47:31] dusk : ~/Work
$ 

When I’m inside a git repository, I see something like this.

[nick@20:47:31] dusk : ~/Work/git/MacRuby (master) [2]
$ 

The bracketed ‘master’ shows me what branch I have checked out, and the red ’2′ shows me that I have two stashed change-sets. This is accomplished by the following bashrc/profile code:

function parse_git_branch {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo "("${ref#refs/heads/}")"
}
 
function parse_git_stash_size {
  lines=$(git stash list -n 100 2> /dev/null) || return
  if [ "${#lines}" -gt 0 ]
  then
    count=$(echo "$lines" | wc -l | sed 's/^[ \t]*//') # strip tabs
    echo "["${count#}"]"
  fi
}
 
export PS1="[$red\u$NC@$green\t$NC] \h : $cyan\w $yellow\$(parse_git_branch) $RED\$(parse_git_stash_size)\n$NC\$ "

This has been invaluable in helping me keep track of what I’m working on, and helps me make fewer mistakes when managing git repositories.

Rackspace CloudSites and .htaccess maintenance mode

We’ve started using Rackspace’s CloudSites at BERG, and one of the problems we’ve been tackling is how to make deployment a painless process. Uploading to CloudSites is only allowed by FTP/SFTP, and is very slow at times, so we wanted to use a “maintenance” mode approach that is common in the Rails and Capistrano world.

CloudSites has some very customised Apache configuration, and we found that the standard mod_rewrite approach didn’t work. There was no mention of a solution within their support wiki, so for anyone else looking for a similar solution, I’m placing ours here:

RewriteEngine on
RewriteBase /
RewriteCond %{ENV:PHP_DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{REQUEST_FILENAME} !/maintenance.html
RewriteRule ^.*$    /maintenance.html [L]

We found that when checking the DOCUMENT_ROOT environment variable, it didn’t get the correct path to test for the presence of the maintenance.html file, but using ENV:PHP_DOCUMENT_ROOT, it did.