Simon Jefford

Rack and Firebug

Last week, I submitted an entry into the CodeRack contest. CodeRack, if you haven’t come across it yet, is a competition designed to encourage Rubyists to build and share Rack middleware.

My entry allows Rack-based applications (in other words, pretty much any web app built in Ruby on recentish frameworks) to output log information to the Firebug console. It turns out that the same Javascript API is supported by WebKit so it works in Safari, and probably Chrome as well.

It works by taking advantage of the fact that Rack apps (and middleware) take as their sole parameter a hash containing the environment - all the CGIish stuff like user agent, HTTP method and the path information. Apps and middleware can add information to this hash so it can be shared.

FirebugLogger expects logs to be stored in this environment hash with a key of “firebug.logs”. Each log entry is a list with two members: a level and a message. Rack based apps can append to this list and the middleware then appends a script block which makes the appropriate Javascript calls to the logging API.

I also have the middleware in a Github repo, along with unit tests and a Rails plugin which adds the middleware to the Rails middleware stack and provides a nice API for adding log entries.


Since I wrote this, it turns out my little middleware was a finalist! I didn’t place, but I’m still pretty pleased that people liked it. Thanks to everyone who voted!

23 Oct 2009

Some site changes

I’ve decided to share more items in Google Reader. I’ve added a link to the resulting “link blog” to the sidebar, along with a link to my twitter account.

15 Sep 2009

Select a random movie from Delicious Library

Wandering what to watch? Give this a go.

    tell first document of application "Delicious Library 2"
	set movieCount to the count of every movie
	set chosenMovie to random number from 1 to movieCount
	set selected media to movie chosenMovie
    end tell

10 Sep 2009