Songbird and multi-media keys under Linux

I’ve decided that under Linux I want to use Songbird as my music player. Unfortunately at the moment the latest developer release doesn’t support the multi-media keys on my keyboard 🙁 Not to be beaten I decided to do something about it and I’ve built my first XPCOM component along with some javascript glue to make it all work. Here is the Songbird extension, and here is the source. I won’t pretend it’s a great piece of work, but it does what I need it to do. The Play, Stop, Next and Previous buttons on my keyboard now work, but YMMV 😉


Working from Linux

I’ve been using Linux as my primary development environment in my day job for a couple of months now and for the most part I’m enjoying the change. It’s amazing that the same hardware running Linux seems to run so much faster than when running XP. Maybe I it’s just time for the semi-anual windows reinstall 😉 
I thought I’d go the whole hog and try using Emacs as well. I tooled up with all the various
Emacs bits and pirces I needed to make doing rails development under Emacs nice and off I went. It only took a couple of days to get used to the cursor movement and cut/copy/paste commands, but in the end I decided to go back to eclipse :(, and then spent the next day or so wondering why Ctrl-K and Alt-W didn’t do what I wanted 😉 I have to say I enjoyed the couple of weeks I spent with Emacs, but I’m still not ready to give up my modern UI addiction 😉 
Maybe one day I’ll give XEmacs a go…

Another reason to hate windows

Well, yesterday the task bar and start menu on my Windows dev box decided to crash. I’ve got my explorer set up to open new explorer windows in their own process, so I didn’t loose my opened windows and so loose my place in svn (as well as cvs and darcs). Ordinarily when this happens I just restart explorer and up comes my start menu. Not this time however. I put up with no start bar for the rest of the day as I was busy doing things and didn’t want to mess up my flow. It was an interesting experience. Everything seems to work quite happily without the task bar, however maximizing my windows didn’t use the area at the bottom of the screen reserved for the start menu. I started to find the empty space at the bottom of the screen quite distracting. 
This morning after taking my daughter for a swim at the local pool I decided that I’d had enough. I did a bit of research on the net to see if there were some magical command line arguments needed to pass to get my task bar back. I suppose I could have just rebooted the machine, but I was trying to avoid that as much as possible. Finally I thought to myself, “Everything is checked in to their various repositories, so I might as well close down all my explorer windows and see what happens when I start explorer.exe”. I did this and hey presto up came my task bar 🙂 It looks like if explorer starts and it doesn’t see any instances of itself running then it becomes the start bar and desk top. 
The more I use windows the more I miss my mac. I really need to get an intel mac so I can run ‘doze in a vm for those rare occasions I need to do something in Visual Studio .Net or some other windows only program.

TextMate and Flex 2

I’ve been having a bit of a play with Adobe’s Flex 2 command line compiler. After doing a quick search around the net I found a couple of hints for using it with TextMate. Unfortunately none of them did quite what I wanted, so I built my own. Hopefully it will be useful for others 🙂

TextMate bundle for Flex 2 coding

It adds a new language type for mxml files, a few snippets with mx as the tab trigger and a build command bound to Command-B.  By default it looks for your Flex install in the following places

  1. ~/Flex
  2. ~/flex_sdk_2
  3. /Developer/SDKs/Flex
  4. /Developer/SDKs/flex_sdk_2
  5. /Developer/Applications/Flex
  6. /Developer/Applications/flex_sdk_2
  7. /Applications/Flex
  8. /Applications/flex_sdk_2

Any errors or warnings are displayed in the output window and a click will take you to where the problem is.

Once your Flex app is building successfully it will be opened in Safari, or if you have a script called deploy in the same folder as your mxml file it will be executed instead.

Enjoy 🙂

before_create considered harmful

I had a fsck of a time today working with rails. Normally I love Ruby on Rails, but today it gave me the screaming shifts!

I had a model class to which I wanted to add some sensible default values to satisfy some constraints in the database.
The logical place for that was before_create, so I did something like the following

class MyModel < ActiveRecord::Base

def before_create ||= true ||=
self.baz ||= false



Now, I would have thought that would work, but whenever I tried to save an instance of my class to the database the save method would return false 🙁
Hmmmm. Ok, let’s add some logging code and see what the problem is… Are there any errors? Nope. Does the instance think it’s valid? Yes. OK, that’s weird. Maybe there is something going on and the exception is getting eaten by some other code in the application (there are three of us working on this code and we’re not all in the same state, so who knows what one of the others may have done 😉 ). I try creating an instance using the rails console. Same thing (which is to be expected, but I was starting to get a little desperate by this stage).

What was the next thing to do? Go through the code and remove things line by line until I start getting some exceptions. Finally in desperation I took out my before_create method, and lo and behold my error messages come back. It was then that I was struck by the thought that Ruby methods take their return value from the last expression evaluated in their body, so the before_create method was returning false. It seems that there is a nice undocumented “feature” in ActiveRecord that allows application code to stop an object being saved to the database by returning false from before_create, and I imagine before_save.

A little note to that affect in the documentation would have saved me quite a bit of time today.

Ah well. Live and learn I guess 🙂

flvThing is released

I’ve released flvThing on the web site. It seems to play every flv file I’ve thrown at it quite nicely 🙂 
The flv files are played using the installed flash player which is hosted inside a WebView control. The application creates a tiny very stupid web server that serves up the flash files as well as the flv file for the flash player to load. It seems to work pretty well 🙂

OmniGraffle is SO cool!

I’ve been building a simple little app to play FLV files on the Mac and I should be releasing it some time over this weekend. I needed to make some icons and I threw them together in OmniGraffle Pro. Go check out for more details. 
I’ve used it a few times for this sort of thing. Here’s an example of what som
ebody who has no graphic design skills can accomplish very quickly 😉 
I’m pretty happy with it 🙂 It looks pretty good shrunk down to 128×128 and the alpha channel comes out when I export is as a PNG 🙂 

Blog spam and other stuff

I finally got around to cleaning up the spam on this blog. 
Unfortunately it looks like I zapped a couple of legitimate comments in the process however 😉 
I’ve been really busy of late working and looking after the monster baby (who just recently turned 1 year old). 
On the train to and from work I’ve been building a simple little database tool for myself. I’ll probably be releasing an alpha some time soon (although when soon is I could not say exactly 😉 ) 
It’s a Objective-C cocoa app that connects to pretty much any database that has a JDBC driver. 
It features syntax hilighting, simple code completion for SQL syntax (and I’m working on making it do code completion for database objects) and the big feature for me is tabbed based query results along with tabbed documents. It’s already pretty usable, although I still jump back to CocoaMysql on occasion for some things. If you’re feeling brave and want to give it a try feel free to email me at

Multiple ruby on rails applications under different folders served by Apache on Mac OS X

I’ve been doing quite a bit of development recently using Ruby on Rails under Mac OS X. Unfortunately it can be a little tricky to get rails apps deployed nicely under Apache. The machine I’m using is an aging G4 with very little RAM so running rails apps in CGI mode is very slow! Initially I tried FastCGI, but I found it to be unreliable 🙁 
After a bit of looking about on the net I came across SCGI ( ) and some code to use it to run rails. apps ( ). 
Installing these pieces is pretty straight forward 
1. download and install the SCGI apache module 
2. install the cmdparse gem (
sudo gem install cmdparse
3. install the highline gem (
sudo gem install highline
4. install the SCGI rails runner 
5. configure your rails apps for SCGI by executing
scgi_ctrl config in each rails app root folder 
Make sure that each of your rails apps has a different port selected in the config/scgi.yaml file 
Next we need to update
the Apache config file /etc/httpd/httpd.conf 
LoadModule scgi_module libexec/httpd/ 
AddModule mod_scgi.c 
<IfModule mod_scgi.c> 
  # matches locations with a dot following at least one more characters, that is, 
  # things like *,html, *.css, *.js, which should be delivered directly from 
  # the filesystem 
  <locationmatch \..+$> 
    # don’t handle those with SCGI 
    SCGIHandler Off 
Alias /app1 “/Library/WebServer/RailsApps/app1/public” 
SCGIMount /tbgmon 
<directory “/Library/WebServer/RailsApps/app1/public”> 
  Options +FollowSymLinks 
  Order allow,deny 
  allow from all 
Alias /app2 “/Library/WebServer/RailsApps/app2/public” 
SCGIMount /app2 
<Directory “/Library/WebServer/RailsApps/app2/public”> 
  Options +FollowSymLinks 
  Order allow,deny 
  Allow from all 
Now we start each of the SCGI server processes by running the
scgi_ctrl start command in each rails app root folder, bounce apache using sudo apachectrl graceful and the rails apps should be up and running from http://localhost/app1/ and http://localhost/app2/ 
That is only half of the story however. We need to have the SCGI server processes start when the machine boots. The way to do this under Mac OS X is to create a startup item. A startup item consists of a couple of files in a folder under /Library/StartupItems. One is a .plist file and the other is a shell script. 
Create a folder called SCGI under /Library/StartupItems and then create the file StartupParameters.plist with the following content 

  Description = “SCGI”; 
  Provides = (“SCGI”); 
  Uses = (“Web Server”); 
Next create a file called SCGI and paste in this text 

. /etc/rc.common 
StartService () 

    echo “Starting SCGI servers” 
    pushd /Library/WebServer/RailsApps/app1/ > /dev/null ; /usr/bin/scgi_ctrl start ; popd > /dev/null 
    pushd /Library/WebServer/RailsApps/app2/ > /dev/null ; /usr/bin/scgi_ctrl start ; popd > /dev/null 

StopService () 

    echo “Stopping SCGI servers” 
    ps ax | grep scgi | grep ruby | awk ‘{print $1}’ | xargs kill 

RestartService () 


RunService “$1”
According to the SCGI rails runner docs there is an option to choose the root folder of the rails app, but I couldn’t get it to work. I suppose I should contact the author about it one of these days 😉 
Now with any luck the next time your machine reboots the SCGI servers should be started and Apache should forward requests on to your rails apps.