Read more in the original post and the code on GitHub.