I’ve been researching how best to generate unique, human-friendly codes for a new project.
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’
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
bytewith 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.
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
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.
Last week’s investment paid off.