Manipulating Raw HTML in Node with the Visitor Pattern

TL;DR Check out the Adding ids to Header Nodes section to see how to use the Visitor Pattern.

I recently wanted to add an id to every header tag in an HTML string. This sounds like an easy task right? A little jQuery and the problem is solved: $(":header").attr("id", "1") is a rough solution.

The catch is that this was in Node, not the browser. In most situations I would reach for Cheerio, which replicates the jQuery API inside node, but I needed something lighter weight.

This is a story of parsing, recursing, and modifying raw HTML without comfortable, declarative APIs. It's surprisingly approachable with the help of the Visitor pattern.

Build Your Own Nested Query String Encoder/Decoder

The other day at work, one of my colleagues was frated that he was unable to encode nested objects in a query string and still maintain a readable URL. I went home that night and coded up a simple solution to this problem, and I thought I'd share it here today. This Github repo contains specs and the solution code.

Regex And Automated Test Fuzzing

I posted my article Build Your Own Regex Engine on Reddit the other day, and one of the commenters claimed that the implementation should be trivial to break. Since I had already tested my program against a customized suite of tests, the remark got me thinking about how I could further increase my confidence in the correctness of my program. One extremely low cost however effective strategy for identifying faults in software is known as fuzzing.