Programming Leftovers
-
Round a direction vector to an 8-way compass
If you assume that the unit direction vector is in the first quadrant (both x and y are positive), then there is a direct way to compute the solution. Using 1/sqrt(2) or 0.7071 as the default solution, compare both x and y with cos(3*pi/8) and cos(pi/8), and only switch them to 1 or 0 if they are larger than cos(3*pi/8) or smaller than cos(pi/8). The full code looks as follows: [...]
-
Code review at the speed of email
I’m a big proponent of the email workflow for patch submission and code review. I have previously published some content (How to use git.sr.ht’s send-email feature, Forks & pull requests vs email, git-send-email.io) which demonstrates the contributor side of this workflow, but it’s nice to illustrate the advantages of the maintainer workflow as well. For this purpose, I’ve recorded a short video demonstrating how I manage code review as an email-oriented maintainer.
-
Defensible Machine Learning Model Naming
There's a curious case of a neural network for object recognition called YOLO – You Only Look Once. While many object detection models were two-pass (one for identifying bounding boxes, the other for classifying), YOLO was single-pass. This makes YOLO fast and small.
-
Leiningen Adds Support for nREPL's Unix Sockets
The next release of Leiningen (likely 2.9.9) will include support for starting an nREPL server listening to an Unix domain socket. As a reminder - Unix domain sockets were one of the highlights of nREPL 0.9, which was released at the end of 2021.
-
What's the Most Portable Way to Include Binary Blobs in an Executable?
I recently needed to include an arbitrary blob of data in an executable, in a manner that's easily ported across platforms. I soon discovered that there are various solutions to including blobs, but finding out what the trade-offs are has been a case of trial and error [1]. In this post I'm going to try and document the portability (or lack thereof...) of the solutions I've tried, give a rough idea of performance, and then explain why I'll probably use a combination of several solutions in the future.
-
When Should a Black Box Be Transparent?
We have been working with a third-party vendor that supplies a critical component of one of our systems. Because of supply-chain issues, they are trying to "upgrade" us to a newer version of this component, and they say it is a drop-in replacement for the old one. They keep saying this component should be seen as a black box, but in our testing, we found many differences between the original and the updated part. These are not just simple bugs but significant technology changes that underlie the system. It would be nice to treat this component as a drop-in replacement and not worry about this, but what I have seen thus far does not inspire confidence. I do see their point that the API is the same, but I somehow do not think this is sufficient. When is a component truly drop-in and when should I be more paranoid?
-
Git with Multiple E-Mail Addresses: And How I Make Sure to Commit with the Right One
Only using each Git server on a computer dedicated for some line of work (company, private, school) is impractical for different reasons. I keep personal notes on discoveries I make when working for my job or for school, which I store in a private repository. Changing laptops just to write down that command line I already googled seven times is not practical, and just would make me to google it for the eighth time.
Furthermore, I prefer to work on my stationary PC running Arch Linux (which I use as a daily driver, by the way) for school-related work, especially when it comes to making up programming examples; I'm just less efficient working on my Windows laptop.
-
Locking Engineering Principles
For various reasons I spent the last two years way too much looking at code with terrible locking design and trying to rectify it, instead of a lot more actual building cool things. Symptomatic that the last post here on my neglected blog is also a rant on lockdep abuse.
I tried to distill all the lessons learned into some training slides, and this two part is the writeup of the same. There are some GPU specific rules, but I think the key points should apply to at least apply to kernel drivers in general.
The first part here lays out some principles, the second part builds a locking engineering design pattern hierarchy from the most easiest to understand and maintain to the most nightmare inducing approaches.
Also with locking engineering I mean the general problem of protecting data structures against concurrent access by multiple threads and trying to ensure that each sufficiently consistent view of the data it reads and that the updates it commits won’t result in confusion. Of course it highly depends upon the precise requirements what exactly sufficiently consistent means, but figuring out these kind of questions is out of scope for this little series here.
-
Picroscopy Turns your Raspberry Pi into a Digital Microscopy
Picroscopy is a small Python web-application which is intended for usage with a Raspberry Pi as a microscopy solution.
With the Raspberry Pi Camera mounted on a microscope, the Raspberry Pi provides a live video feed to its monitor via HDMI, while another machine can be used to control the setup via a web-based interface.
-
YYYY-MM-DD format date in a Shell Script
The Linux date command is used to get the current date and time. You can easily customize the results by using the arguments. In this how-to tutorial, you will learn to format the date as YYYY-MM-DD in the bash shell.
-
Running command line tasks in Neovim
My daily workflow often involves repeatedly running tasks, whether that be build commands, unit tests, or some other scripts. My ideal workflow is to have a terminal split on the right hand side, and then be able to send tasks to it.
-
How to Manipulate Strings in Bash on Linux
The Linux ecosystem is packed with fantastic tools for working with text and strings. These include awk, grep, sed, and cut. For any heavyweight text wrangling, these should be your go-to choices.
Sometimes though, it’s convenient to use the shell’s built-in capabilities, especially when you’re writing a short and simple script. If your script is going to be shared with other people and it is going to run on their computers, using the standard Bash functionality means you don’t have to wonder about the presence or version of any of the other utilities.
If you need the power of the dedicated utilities, then by all means use them. That’s what they’re there for. But often your script and Bash can get the job done on their own.
Because they’re Bash built-ins, you can use them in scripts or on the command line. Using them in a terminal window is a fast and convenient way to prototype your commands and perfect the syntax. It avoids the edit, save, run, and debug cycle.
-
The (Mostly) Complete Unicode Spiral
I present to you, dear reader, a spiral containing every Unicode 14 character in the GNU Unifont. Starting at the centre with the control characters, spiralling clockwise through the remnants of ASCII, and out across the entirety of the Basic Multi Lingual Plane. Then beyond into the esoteric mysteries of the Higher Planes2.