Welcome to tobilehman.com!
%  

programming posts

Dapper Build tool: consistent builds with docker

This articles shows how to use the dapper build tool from Rancher Labs. The basic idea is to use Docker containers, copy* your source files into the container environment, then compile, then copy the build artefacts out. (* on Linux you can also use the mount mode to avoid copying the files.) How to use it: you start by installing Go so you can compile Dapper. I know, I know, but if you will humor me, I will convince you that Go is the last programming language compiler you will need to install on your host.

Latency Numbers Every Programmer Should Know

There’s an indispensible file called Latency Numbers Every Programmer Should Know, originally by Jeff Dean of Google. I use a Roam Research plugin to do spaced repetition and memorize these numbers. But memorizing them is not good enough, I should also measure these numbers and see how close the values are in practice. I created a Repl in Go to directly measure these numbers. I started with mutex lock/unlock. Locally, I get about 19ns, but the repl gives me between 12-14ns.

Literate Quicksort

This post is a literate program, it both explains and implements quicksort. Quicksort is a fast, recursive sorting algorithm. The big idea is to take an array of \( n \) unsorted integers, choose a pivot element, and then recursively sort the two arrays on either side of the pivot. Once a pivot is selected, every number to the left of the pivot is smaller, and every one to the right is bigger.

Generating random numbers in C

Assume your range is lower to upper, both of type int. Choose random number in range A random integer, uniformly distributed, over that interval is generated with: int random_number(int lower, int upper) { return (rand() % (upper - lower + 1)) + lower; } But in C, the rand() function is deterministic. That means that if you don’t “seed” the random number generator (RNG), then it will return the same sequence every time.

Book Review: Atomic Habits

Atomic Habits is written so clearly that I have a hard time believing ‘James Clear’ isn’t a clever pen name. That clarity comes from experience and practice. His story about recovering from a major head injury and returning to sports is inspiring. His recovery is a big source of practical knowledge about how to build good habits. Before I read this, I thought of habits using the goal/discipline model. You start by setting a goal, then you apply discipline in doing something repeatedly to reach that goal.

Book Review: Working in Public

The story of open source software most of us believe is wrong. The production of open source software isn’t like some egalitarian commune, it’s driven mostly by a few individuals. Through analyzing git commit frequency distributions and interviewing prominent open source contributors and maintainers, Nadia Eghbal captures the living history of open source software. In addition, she also analyses the main problems of maintenance that threaten the long term sustainability of open source software.

Compiling C to WebAssembly

Ten years ago, a coworker tried to teach me cribbage on my last day at work, but I didn’t get it. The following year, I met my future wife, and she was a cribbage fan. She taught me, and I’ve loved the game ever since. Six years ago, I wrote this cribbage score calculator in C. It takes a string like JH 2C 3C 3S JS, and returns the full accounting of the score in a game of cribbage.

Timelapse

I have a fascination with time. Two years ago, our family planted a tree in our back yard. A few months prior, my dad and I built an overhang that provides shade. I used a pillar supporting the overhang to point this timelapse camera at the tree. I bought that camera because of it’s low battery usage, and how it uses standard JPEGs on a standard SD card. That gives me raw material to compress a large amount of time into a nice video.

Conway's Game of Life

John H. Conway has passed away, his contributions to math are too numerous for me to list in this post. What I wanted to explore in this post is one of his “recreational math” contributions: The Game of Life. If you haven’t heard, It’s this zero player computer “game”: Not this multi-player board game: I scare-quoted game because there are no actual players. It is an example of a cellular automaton, which is a simple program that evolves over time according to a fixed, simple set of rules.

Piano ♪

To start the decade off right, I decided to learn the piano. I am paying for lessons from Ethan Maier, he’s excellent, I’ve been enjoying learning from him and practicing. Since I only have a piano at home, I wanted to make one that I could use on the go. Here is the simplest way I could think of to make a portable piano program: There is an standard for simple web graphics called SVG, which lets you define custom shapes that show up in any web browser.