Added the code in the gist in 9a4e315.