i wrote something for this quite a while ago (likely could be improved...), http://gist.github.com/614392