-
I’ve been researching how best to generate unique, human-friendly codes for a new project.
Scott recommended we take a look at Douglas Crockford’s “Base 32” system:
The encoding scheme is required to
- Be human readable and machine readable.
- Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
- Be error resistant. Entering the symbols must not require keyboarding gymnastics.
- Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.
Crockford excludes the letters I, L and O to avoid ambiguity with the numbers 1 and 0. Less intuitively, he also excludes the letter U as this helps avoid accidentally generating codes that contain English obscenities: a problem I would have missed entirely.
We looked into the implementation of Rails’
SecureRandom.base58
:def self.base58(n = 16) SecureRandom.random_bytes(n).unpack("C*").map do |byte| idx = byte % 64 idx = SecureRandom.random_number(58) if idx >= 58 BASE58_ALPHABET[idx] end.join end
I wondered why they didn’t simply modulo
byte
with 58 like so:def self.base58(n = 16) SecureRandom.random_bytes(n).unpack("C*").map do |byte| idx = byte % 58 BASE58_ALPHABET[idx] end.join end
Scott found the explanation in a four-year old pull request to simplify the implementation: modulo bias. Naïvely simplifying the implementation would mean that the “random” choice would actually be biased towards picking some characters more than others.
Coincidentally, someone else suggested the same change again 12 days ago.
-
After last week’s big migration to Fargate, I wanted to double check the new Docker version of our application wasn’t writing to disk (in order to remain stateless).
The docker diff command handily told me exactly what a container was changing on its file system when running and revealed that Phusion Passenger was logging to a file when I didn’t expect it to.
$ docker diff 1fdfd1f54c1b A /var/log/nginx/error.log
-
E has been binging the French spy drama “The Bureau” but I can’t help but think of The Day Today’s BBC drama of the same name every time I see her watching it:
This is supposed to be a high class bureau de change, not some two-bit Punch and Judy show down on the seafront at Margate!
-
Jeff Geerling’s “The best way to keep your cool running a Raspberry Pi 4” convinced me to buy the FLIRC case from The Pi Hut and he’s right: my Pi runs much cooler than my previous setup with a large heatsink inside the official case:
mudge@raspberrypi:~ $ cat /sys/class/thermal/thermal_zone0/temp 36998
-
In a move that threatens my marriage, I have spent far too much time this weekend trying to generate a custom Raspbian image that already has my Time Machine backups, Unbound DNS sinkhole and AirPlay receiver set up on it.
Thankfully, the tool used to create the raspberrypi.org images is open-source and you can find the results of my indulgent noodling in my fork of pi-gen.
-
Last week’s investment paid off.
Weeknotes 33
By Paul Mucur,
on