Welcome to my blog where I write about things that interest me, stuff that was hard to figure out, and sometimes just to show off. I hope you find something interesting. Below you’ll find my most recent blog posts but you can also explore by tags. Or maybe you’re interested in stuff I’ve built?

Recent Blog Posts

Zig, Memory, and the mysterious 170

2 min read

I’m hacking on a small Zig application with a GTK frontend, and part of using GTK is passing around ?*anyopaque pointers and you never quite know if it’s working. In my app I’m passing around a struct that holds a string []const u8 to various GTK callbacks. However the string was empty. This led me down a rabbit hole of trying to figure out if my pointers were correctly passed, even going as far as stepping through it with a debugger. Turns out, the pointers are all correct. Even my string []const u8 was there with the correct length, except every single byte was set to 170 and I realized I was looking at undefined memory. Zig in debug mode sets undefined memory to 0xaa which is 170.

Hugo –cleanDestinationDir and Git Submodules

1 min read

Recently I’ve been working on updating my blog a bit (you might have noticed?). I keep the hugo sources in a git repository and the built site in a separate repository. That repository is added as a submodule to the sources repo and during the build, the generated HTML is written into the submodule. Except the submodule kept getting messed up; git would be unable to track the changes or they’d be added to the parent repository. It was truly maddening, but as it is so often, the problem was not git but me.

Zig Fetch

1 min read

Zig’s package manager is still a bit rough. It only supports fetching tarballs, but many github projects don’t have them unless they have a release. There’s a trick to fetch any commit as a tarball though:

https://api.github.com/repos/<repo-owner>/<repo>/tarball/<ref>

zig fetch can than download the code:

zig fetch --save https://api.github.com/repos/<repo-owner>/<repo>/tarball/<ref>

Once the code is downloaded, it still has to be added to your exe or libray in build.zig:

    const exe = b.addExecutable(.{
        .name = "zlox",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const my_dep = b.dependency(
      "<name of dependency>", 
      .{ .target = target, .optimize = optimize },
    );
    exe.root_module.addImport("regex", regex_dep.module("regex"));

One Billion Row Challenge in Zig

I finally got around to looking into The One Billion Row Challenge. If you’re unfamiliar, it’s a challenge to how fast a program can read and process one billion rows. It’s fascinating because it’s all about raw performance including algorithms, CPU instructions, and profiling and benchmarking. All things I enjoy dabbling with.

So one Saturday evening I started reading up on the challenge. The first thing that struck me was the top entries’ time: 1.535 seconds! For reference, the input is 13 GB. I can’t even dump the whole file to /dev/null in that short of a time. So clearly, lots to learn.