https://gist.github.com/3348000 

Like I say, hopefully it might provide a starting point...

Brian