``` doesn’t work on HN, prepend two spaces to each line to get a code block.
Regardless, it’s a lot of code, so maybe better move it out to a pastebin/gist?