news
Programming Leftovers
-
Nicolas Fränkel ☛ Making illegal state unrepresentable
A couple of years ago, I wrote that The Builder pattern is a finite state machine!. A state machine consists of states and transitions between them. As a developer, I want to make illegal states unrepresentable, i.e., users of my API can’t create non-existent transitions. My hypothesis is that only a static typing system allows this at compile-time. Dynamic typing systems rely on runtime validation.
In this blog post, I will show that it holds true, with a caveat. If your model has many combinations, you also need generics and other niceties to avoid too much boilerplate code. My exploration will use Python, Java, Kotlin, Rust, and Gleam. With that background in mind, let’s move on to the model itself.
-
椒盐豆豉 ☛ Human powered enshitification long predates AI powered slop
You can imagine this tree grow much messier, bigger and deeper as more and more teams are added to the mix.
Now what has that to do with the shitty auto-play shorts feature I mentioned at the beginning? Imagine your team’s goal is to increase first time shorts adoption, aka make more people watch youtube shorts. Your org’s topline probably is total shorts view hours, percentage of youtube user that has watched shorts in past X days, average finish rate, etc.
-
Max Seelemann ☛ Fast Thumbnails with CGImageSource
When working with images, we rarely need to show them at full size — most often ist’s rather as a thumbnail or preview. Using fully loaded images for this is quite slow, so we implemented a thumbnail cache.
While modernizing this component, I remembered user reports about slow image loading. When they opened documents with photos, the app would stall for a moment, before becoming buttery-smooth again. The caching was clearly working, but the initial loading was problemat
-
Charlotte ☛ Fluent jj / aggressive aliasing
Anyway, if Git is a Swiss Army knife, jj is … uhh. A combat spork? I dunno. You don’t need thirty different commands, some of which operate in a confusing range of ways (reset), others oddly specific, and the occasional Mega Tool which throws your entire workflow out the window and replaces it with a DSL (rebase -i).
To do this, you need to learn about the subtle ways in which jj adjusts your view on a Git repository. Git probably took some learning; jj takes much less, but it is weird because it shifts your perspective on something existing, rather than being totally new. You have to unlearn some things! It will not take long, but you do have to do it. Try Steve’s Jujutsu Tutorial; worked for me ¯\_(ツ)_/¯
-
John D Cook ☛ 4-bit floating point FP4
Neural networks brought about something extraordinary: demand for floating point numbers with less precision. These networks have an enormous number of parameters, and its more important to fit more parameters into memory than it is to have higher precision parameters. Instead of double precision (64 bits) developers wanted half precision (16 bits), or even less, such as FP8 (8 bits) or FP4 (4 bits). This post will look at 4-bit floating point numbers.
Why even bother with floating point numbers when you don’t need much precision? Why not use integers? For example, with four bits you could represent the integers 0, 1, 2, …, 15. You could introduce a bias, subtracting say 7 from each value, so your four bits represent −7 through 8. Turns out it’s useful to have a more dynamic range.
-
Anže Pečar ☛ How to Safely Update Your Dependencies
The best way to reduce the risk of installing a compromised dependency is to avoid relying on it in the first place. Before adding a new dependency, I first make sure that implementing it ourselves would be too much work (or tokens!).
Besides that, I try to ensure the dependency is reliable and well maintained. There is no good way to determine this, but looking at the git history, issues, etc., can usually give you a rough idea.
-
Blake Watson ☛ Dice rolling and more on Minimal Character Sheet
You may not realize this, but it’s hard to get a computer—a machine built around math and logic—to generate a truly random number. Perhaps it’s impossible, but I’ll let the comp-sci majors argue about that. Fortunately, one of the oldest sites on the web—RANDOM.ORG—has an API that offers true random numbers based on atmospheric noise. When you roll a die with Minimal Character Sheet, that’s what you are getting. Sophisticated processes of the atmosphere—like lightning discharges—power your Divine Smite against a beholder. One might say atmospheric processes aren’t truly random, even that the universe is deterministic—but I’ll let physicists and philosophers argue about that.
-
Maury ☛ 5x5 Pixel font for tiny screens
5x5 is the smallest size that doesn't compromise legibility: [...]
-
Daniel Lemire ☛ The fastest way to match characters on ARM processors?
Consider the following problem. Given a string, you must match all of the ASCII white-space characters (\t, \n, \r, and the space) and some characters important in JSON (:, ,, [, ], {, }). JSON is a text-based data format used for web services. A toy JSON document looks as follows.
-
Rlang ☛ New York City Hexmaps
The five boroughs of New York City can be informally or formally carved up into many different pieces, depending on what it is that you’re doing.
-
Scheatkode ☛ Hot-wiring the lisp machine
The modern web is choking on its own exhaust. Somewhere along the line, we traded the elegance of plain text for gigabytes of node_modules/, I know you're thinking about it. heaviest-objects-in-the-universe.png labyrinthine JavaScript frameworks, and bloated Static Site Generators that insist you learn their esoteric templating languages just to write a blog post. Worse yet, some even force you to use the mouse. Gross.
I didn't want another framework. I refused to hoard dependencies like some doomsday prepper. I wanted the comfort of my text editor.
-
Python
-
Didier Stevens ☛ Update: cut-bytes.py Version 0.0.18
This is a fix for escape sequences that trigger warnings in the latest Python versions.
-
-
Java/Golang
-
Redowan Delowar ☛ Peeking into Go struct tags
Struct tags in Go are these little annotations that you stick beside struct fields. Libraries read them to decide what to do with each field, and the most familiar place you’ll see them is JSON marshalling and unmarshalling: [...]
-
Redowan Delowar ☛ Accepted proposal: UUID in the Go standard library
It’s good to see that Go is finally getting uuid in the standard library. The proposal was accepted on April 8. I hadn’t been following the conversation in the thread and only found out about it from Cup o’ Go episode 154 .
google/uuid is usually one of the first extra imports I add to a Go service that talks to a database, so this one has felt overdue for years.
-