Original here: https://gist.github.com/esperlu/943776 . I am just modifying this for my personal use and I don't want to fork it on gist.