Changing the Distance Metric

Posted on May 19, 2020 by Jack Kelly
Tags: coronavirus, maths

Mathematics has this idea of a metric, which generalises the idea of distances that we normally think about. If we take a set X, we can talk about a metric or distance function, which is a function d : X × X → X, that means “the distance between x and y”, and it has to have the following properties for any x, y, z ∈ X:

  1. The distance between x and y is 0 if and only if they are the same thing:
    d(x, y) = 0 ⇔ x = y

  2. Symmetry: The distance between x and y equals the distance between y and x:
    d(x, y) = d(y, x)

  3. Triangle Inequality: If you’re going between x and y, detouring via z cannot be shorter:
    d(x, y) ≤ d(x, z) + d(z, y)


What I Remember

Posted on April 26, 2020 by Jack Kelly
Tags: coronavirus

(Note: all Twitter links have screenshots next to them, as it’s notoriously difficult to predict what Twitter shows on the other end of a link.)

Update History:

What do I remember about the coronavirus pandemic?

I remember watching case numbers double and redouble throughout late February and early March, thinking “oh god, we’re only a few doublings behind Italy, and our leaders are going to drop the ball”.


The Power of Tiny DSLs

Posted on April 3, 2020 by Jack Kelly
Tags: haskell, coding

I was playing around with codeworld-api recently, and found myself with a pair of interesting problems:

Placing the picture is easy — codeworld-api provides two functions that do exactly what I want:

Going the other way is more difficult. After noodling around on paper trying to compute the inverse transform, I remembered that these transformations could be represented as 3x3 matrices (Wikipedia has some examples), and that inverting a 3x3 matrix is easy (provided that the affine transformation it represents hasn’t collapsed the space).

This means I have to compute the transformation twice: once as codeworld-api calls, and once as matrices. Or do I?



Posted on January 25, 2020 by Jack Kelly
Tags: nix, haskell, coding

I really like using Nix to build and manage my computers. Declarative machine definitions are incredibly powerful, and NixOS actually achieves what tools like Ansible and Chef have tried to reach for.

This web site is served from a NixOS machine, and is a collection of static files which get copied across by nix copy when it sends the built NixOS expression to the server. Until recently, my built website lived in a single derivation, which meant that any time I changed anything, a full rebuild of the site would get sent up my terrible internet connection.

I have written a tool to split up the big derivation called nix-freeze-tree (Hackage). It lets me split the website derivation down to individual files, and symlink them together back into the tree I want. The individual derivations are fixed-output derivations, which means that Nix knows the hash of the files before it builds the derivation, and can check the hash of the files to copy and skip files that haven’t changed.

If you’re reading this, then I’ve successfully wired nix-freeze-tree into my site build pipeline and deployed it.

Ergodox Firmware with Nix

Posted on January 8, 2020 by Jack Kelly
Tags: keyboards, nix

A few years back, I bought an Infinity Ergodox. I’ve been very happy with it, especially once I customised the firmware to add keybindings for my Haskell work.

Unfortunately, the kiibohd repos have broken Infinity Ergodox support for some time, and nobody seems to care. Getting a working build involves jumping through some hoops, and even then modern GCC has slightly different semantics for inline functions, so it needs another patch on top of that.

Pulling all this together is the sort of thing that Nix excels at, so I threw together some Nix expressions to build the firmware, and to give me a shell with dfu-util for flashing. I’ve uploaded them to SourceHut for reference.

All Posts | RSS | Atom
Copyright © 2020 Jack Kelly
Site generated by Hakyll (source)