inital import from original GIST page

https://gist.github.com/matbor/5931466