PSA: Internet Explorer requires all four arguments to document.createTreeWalker

If you, like me, typically use the Mozilla Developer Network documentation as the source of truth for the browser JavaScript interface, you may be forgiven for assuming that only the first argument to document.createTreeWalker is required. As it turns out, Internet Explorer requires all four arguments to be passed explicitly. For a cross-browser-friendly tree walker with the defaults, create it like this:

document.createTreeWalker(someElement, NodeFilter.SHOW_ALL, null, false);

IE's implementation is consistent with DOM Level 2, which specifies four arguments, all of them required. Mozilla's is consistent with the DOM Living Standard, which specifies three arguments, only the first of which is required (Mozilla still allows the fourth argument, but it's marked obsolete).

Posted on April 6, 2015 .

Installing CharlockHolmes on Heroku cedar-14

CharlockHolmes is a useful library for detecting the character encoding of strings of unknown provenance. It's both accurate and fast, thanks to its use of icu4c, a popular C library for unicode operations. Unfortunately, the native dependency makes installation on Heroku less than elementary.

The good news is that there's a nicely written blog post that takes you through exactly how to get CharlockHolmes to build. The bad news is that a few things have changed since the post was written, so it doesn't work out of the box; worse, it wasn't terribly obvious (at least to me) how to fix the problems.

But, having spent the afternoon on the problem, I finally got ol' Charlock to build on our cedar-14 app. Since most of the post is still entirely relevant, rather than rehashing it here, I've annotated the original post with updates. Enjoy!

Posted on March 25, 2015 .