nick.recoil.org

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.

Low-power embedded hardware

A chap at Smoke and Mirrors, where I’m doing some Freelance work, is creating a system to bridge between video routers and a web-based status page. Most of the suites within the building are plumbed in via fibre-optic KVM connections, and depending on the schedule, different video processing systems can get presented in different rooms at different times. All it takes is a change on the routers.

Although complex, this enables the most cost-effective use of each system, marrying the functionality needed to the number of physical people required to attend the session for any given day. There is a large variation in price and functionality with certain high-end systems, so you always want to try and get maximal use from the systems you have chosen to invest in.

He’s looking at using one of the boards from the wonderfully named Acme Systems from Rome. The idea is to communicate with the video router via its RS-232 serial interface, and retrieve an ASCII representation of the current router configuration. It’s a fascinating area of software AND hardware as glue. A physical device which will run some bespoke code to bridge information from one system into another.

pico-itx_board

In related news, I’ve also received my Artigo Pico-ITX kit and am now a proud owner of the tiniest system running Linux that I’ve ever seen. It also seems to play happily with the DVB sticks that I had stability issues with on the older Mini-ITX M10k board.

The fan is noticable in a very quiet room, but as soon as there’s anything else to be heard, it’s drowned out, so it’s not quite suitable for your bedroom. They do a fanless system, but it’s half the clock speed. Installing it was done over PXE from my Mac, using the Ubuntu netboot downloads.

AppleTV & Ubuntu hacking

I’ve finally enabled SSH on my long dormant AppleTV, and am integrating it into my DVB / Rails / Beanstalk / MySQL system for processing data. I’ve used the Patchstick image available from atv4windows. I ended up unpacking and dd’ing the image from the Mac, but the process remains exactly the same. I now have Perian, ssh and a slew of other things enabled, and all I need now is to attempt the hack to get composite output working. I’ve yet to take the plunge and replace my old CRT with an LCD TV.

Incidentally, for anyone looking to figure out the ssh username and password for your freshly enabled ssh daemon, they are both frontrow, and that user has passwordless sudo privileges.

I also had a minor breakthrough with my x86_64 Ubuntu 8.04 machine. I have a Zyxel G-202 Wireless USB stick, to keep the number of trailing wires to a minimum, but I kept getting an error saying:

1
zd1211rw error ioread32(CF_REG1): -110

Which was exceedingly unhelpful. I eventually tried disabling hi-speed USB from the BIOS, and rebooted to find it sprang into life immediately. Great! What was even more strange that when I rebooted and reset the BIOS back to enable USB 2.0, the G-202 kept working. I’m unsure whether this is due to the device not being cold booted, and I’ve yet to see if it stops working after I power the system off, but so far so good, and I don’t need to resort to NDIS.

Saving my blown Seagate Barracuda 7200.10 hard drive

Whilst messing around with my Mini ITX box, I managed to touch the power connector onto the drive backwards, blowing one of the components near the connector. I noticed that the controller board is screwed on with standard torx screws, so I took them out, curious about the connector to the main chassis.

After removing them, the board came away easily, and uses pressure pads as a connection mechanism, rather than ribbon cable or other methods. This set me wondering about whether this would be a replaceable part. I contacted Seagate, who told me that they don’t supply them separately. I then wondered about getting an identical drive, and replacing the old board with one from the new drive, so I went ahead and ordered a replacement; I’d need it anyway, even if this attempt at data recovery failed.

After it arrived, and I’d done the swap, I turned on the machine, and back came my drive with all my data on it, safe and sound. I did worry about whether the IDE controller boards carry some kind of mapping table that’s specific to a particular set of platters, but this isn’t the case, it seems. Unfortunately I’ve no way of repairing the original blown board. Replacing surface mount components is tricky.

For anybody wondering, you can replace the controller board for a Seagate Barracuda 7200.10 500GB drive with no ill effects.

Flickr photostream

			Nick Ludlam posted a photo:	From the Android supplement from The Guardian on 29/08/2010. I was interviewed for a piece on the future trends in Mobile apps. www.guardian.co.uk/lg-talking-technology/the-future-of-apps			Nick Ludlam posted a photo:	My wonderful colleagues at BERG bought lots of cake for my birthday. And not just any old cake! This was from Konditor and Cook. It was delicious!We get bonus points for having to cut it with a craft knife, since it was either that or a scalpel.			Nick Ludlam posted a photo:	I've set up a custom Ruby script to scrape my balance information from the Three.co.uk website, and a custom app to receive the notifications. I've set it up to tell me my balance every day, since there is no automatic notification on Three as there is with O2.			Nick Ludlam posted a photo:	Just up the road from BRIG. Lovely coffee, and nice people serving it. The map shows you where it is!			Nick Ludlam posted a photo:	An image of an advertisement in the Sun Newspaper for Android phones sold by Carphone Warehouse here in the UK.Underneath is a section which lists 10 apps that "you need to get through the day". 8 are free, 1 is £1, and the last one did not even seem to be listed when I searched. "Where's The Train", the only non-free app, is listed as having "100 - 500 downloads"This is very typical of my experience with the Android Market. Unless your business model can support free applications, with your revenue coming from advertising, a website or service you sell, then you are unlikely to be able to recoup the time spent developing quality applications.			Nick Ludlam posted a photo:	I love their spoons. As you pull the spoon out of your mouth, you can feel the texture of the detailing on your top lip			Nick Ludlam posted a photo:	The girls pose for a quick picture before heading off to the race start line			Nick Ludlam posted a photo:	That 'Touch here if bicycle is damaged' button will be too tempting			Nick Ludlam posted a photo:	The new bike stands have just appeared on Shoreditch High St.

Delicious links