Update: this guy put a more elaborate version on the reddits:
https://gist.github.com/zwparchman/7f0a00a7dc69f2506db840d4a99a35e2