Skip to main content

Category: Hacks

Some useful types for database-using Rust web apps

I’ve been writing a little web app in rust lately, and in it I decided to try to do it without an ORM. Instead, I modeled data access in a way that resembles the Data Access Layer pattern: You make a set of abstractions that maps the “business logic” to how the data is stored in the data store. Here are some types that I found useful in this journey so far.

Saved by NixOS Integration Tests, Surprisingly

Recently, tsnsrv has been getting a lot of high-quality contributions that add better support for Headscale and custom certificates, among other things. As they always do when things change, bugs crept in, and frustratingly, not in a way that existing tests could have caught: Instead of the go code (which has mildly decent test coverage), it was bugs in the nixos module!

This was a great opportunity to investigate if we can test the tsnsrv NixOS module, and maybe improve the baseline quality of the codebase as a whole.

A recent blog post series on the NixOS test driver (part1, part2) made the rounds showing off what it can do, so this felt like a tractable project to take on. Here’s my experience with it.

Neat GitHub Actions patterns for GitHub Merge Queues

GitHub have enabled their “merge queue” function, which is really exciting! The “it’s not rocket science rule” of software development is a pretty good guiding principle for developing stuff in a team (if CI is fast, more on that later!) - so I’m very glad it gets easier to achieve.

Unfortunately, it’s only “easier” but not “easy”. I was able to use the feature for about a half year while it was in private beta, and while using it my team and I learned a few lessons that make certain things possible (and some others easier).

tsnsrv, or easily accessing services on your tailscale network

Like many people on the internet, I recently saw this great talk by Xe Iaso about things you can do on your Tailscale network with the tsnet package. It got me wondering what more I could do with tailscale myself. Then, three days later, I noticed that my Kobo e-reader had stopped syncing with calibre-web and I knew something about how I accessed my homelab-hosted services would have to change.

Building a golang program with cgo

Recently, I needed to debug a particularly nasty interaction between two programs, one of which was a go tool. To get further in understanding the issue, I had to compile a little test program with cgo, the dreaded (by go programmers) compilation mode that allows go programs to call C code. Unfortunately, it’s a bit difficult to find out what to concretely do in order to build a program with cgo.

basename and dirname in Rust

I recently did some minor file name munging in Rust, and was reminded that one of the hard parts about learning a new language is the differences in vocabulary. In UNIX, there are two command line tools, basename and dirname. They take a pathname as an argument and print a modified pathname to stdout, which is really handy for shell scripts. Several other languages copied that naming convention, and so I was really surprised to find that googling for rust dirname didn’t return anything useful1.

Editing rustdoc comments in emacs

I’ve been writing a bunch of rust code lately, and it’s been a pretty great experience! The thing I enjoy most about it is that the documentation looks just so extremely good. Which brings me to my major point of frustration with my rust-writing setup: Writing doc comments in emacs’s otherwise excellent rust-mode is a pain. You always have to insert the doc comment character sequence de la ligne, and writing doctest examples was even worse: You write rust code, inside markdown, in rust comments.

Better filters for gmail with google apps scripts

At my workplace, we use github pretty extensively, and with github, we use organization teams. They allow assigning permissions on different repos to groups of people, but, are a really great way of @-mentioning people. This is wonderful, but sadly, github doesn’t make it easy for gmail filters to tell the difference between an email notification that you got because it was interesting to you, or because somebody sent a heads-up @-mention to a team you’re on.

I thought that was impossible to solve, but I was so wrong!