Or maybe even something like https://gist.github.com/23Skidoo/5553108