Plurrrr

week 30, 2022

Design Patterns with Rust Types

This post introduces some patterns and tricks to better utilise Rust's type system for clean and safe code.

This post is on the advanced side and in general there are no absolutes - these patterns usually need to be evaluated on a case-by-case basis to see if the cost / benefit trade-off is worth it.

Source: Design Patterns with Rust Types.

asdf: Manage multiple runtime versions with a single CLI tool

asdf is a tool version manager. All tool version definitions are contained within one file (.tool-versions) which you can check in to your project's Git repository to share with your team, ensuring everyone is using the exact same versions of tools.

The old way of working required multiple CLI version managers, each with their distinct API, configurations files and implementation (e.g. $PATH manipulation, shims, environment variables, etc...). asdf provides a single interface and configuration file to simplify development workflows, and can be extended to all tools and runtimes via a simple plugin interface.

Source: the Introduction of asdf.

Lisp in Vim

Fifteen years ago, writing Lisp code in Vim was an odd adventure. There were no good plugins for Vim that assisted in structured editing of Lisp s-expressions or allowed interactive programming by embedding a Lisp Read-Eval-Print-Loop (REPL) or a debugger within the editor. The situation is much better now. In the last ten years, we have seen active development of two Vim plugins named Slimv and Vlime. Slimv is over 10 years old now. Vlime is more recent and less than 3 years old right now. Both support interactive programming in Lisp.

I am going to discuss and compare both Slimv and Vlime in this article. I will show how to get started with both plugins and introduce some of their basic features.

Source: Lisp in Vim, an article by Susam Pal.

The many flavors of hashing

In practical computer science hashing is a very important concept. It is used from simple data structures (like hash maps), highly complex data structures (like bloom filters or hyperloglog counters), database indices and sharding, storage and communication integrity, distributed storage, most password authentication and storage mechanisms, digital signatures, other cryptographic constructs based on Merkle trees (including Git or digital ledgers), and possibly many other use-cases I'm not even aware of right now.

However, not every hash algorithm is appropriate in all of these scenarios, and in fact, very few algorithms are usable in more than a couple of situations. Even worse, using the wrong algorithm will lead in the best case scenario to performance problems, but in the worst case scenario to security issues and even financial loss. Thus, knowing which algorithm to pick for which application is crucial.

Therefore I'll try to summarize how I approach the topic of hashing, including use-cases, recommended algorithms, and links to other articles.

Source: The many flavors of hashing, an article by Ciprian Dorin Craciun.

Uncompressing Folders in Swift

So imagine you need to get multiple files and folders from an API. One option for doing so is to get all the file names and request them from what ever file server you are using. This is terrible don't do this. The optimal way is to bundle the entire directory into a compressed format and distribute that one file. Okay great, say you needed these files in an iOS/iPadOS or MacOS application. That means you will need to decompress the files that you received in swift.

Source: Uncompressing Folders in Swift, an article by Quindarius Lyles-Woods.

Debugging Postgres autovacuum problems: 13 tips

If you’ve been running PostgreSQL for a while, you’ve heard about autovacuum. Yes, autovacuum, the thing which everybody asks you not to turn off, which is supposed to keep your database clean and reduce bloat automatically.

And yet—imagine this: one fine day, you see that your database size is larger than you expect, the I/O load on your database has increased, and things have slowed down without much change in workload. You begin looking into what might have happened. You run the excellent Postgres bloat query and you notice you have a lot of bloat. So you run the VACUUM command manually to clear the bloat in your Postgres database. Good!

But then you have to address the elephant in the room: why didn’t Postgres autovacuum clean up the bloat in the first place…? Does the above story sound familiar? Well, you are not alone. 😊

Source: Debugging Postgres autovacuum problems: 13 tips, an article by Samay Sharma.

Oldest and Fatherless: The Terrible Secret of Tom Bombadil

Old Tom Bombadil. Possibly the least liked character in The Lord of the Rings. A childish figure so disliked by fans of the book that few object to his absence from all adaptations of the story. And yet, there is another way of looking at Bombadil, based only on what appears in the book itself, that paints a very different picture of this figure of fun.

What do we know about Tom Bombadil? He is fat and jolly and smiles all the time. He is friendly and gregarious and always ready to help travellers in distress.

Except that none of that can possibly be true.

Source: Oldest and Fatherless: The Terrible Secret of Tom Bombadil.

You might also be interested in the comments on Hacker News.

Responsive and accessible typography and why you should care

How many times have you been aware of text's different shapes and sizes while browsing the web lately? Probably not many, unless you found an extremely uncomfortable typography that pushed you to quickly flee the website.

Typography is a silent tool that UX designers and developers can sometimes take for granted. There is much noise around this topic. Pixels? Are breakpoints enough to switch sizes across devices? Do we even need breakpoints at all?

Let’s find out about a few key concepts to succeed at a responsive and accessible typography as a front-end developer or as a UX designer.

Source: Responsive and accessible typography and why you should care, am article by Maria Eugenia Trapani.

Swift Proposal: Move Function

In this document, we propose adding a new function called move to the swift standard library, which ends the lifetime of a specific local let, local var, or consuming function parameter, and which enforces this by causing the compiler to emit a diagnostic upon any uses that are after the move function. This allows for code that relies on forwarding ownership of values for performance or correctness to communicate that requirement to the compiler and to human readers.

Source: Move Function + "Use After Move" Diagnostic, an article by Michael Gottesman, Andrew Trick, and Joe Groff.

SQLite Internals: Pages & B-trees

This constrained size means that SQLite doesn't include every bell and whistle. It's careful to include the 95% of what you need in a database—strong SQL support, transactions, windowing functions, CTEs, etc—without cluttering the source with more esoteric features. This limited feature set also means the structure of the database can stay simple and makes it easy for anyone to understand.

Source: SQLite Internals: Pages & B-trees, an article by Ben Johnson.

Using GNU Stow to manage your dotfiles

I accidentally stumbled upon something yesterday that I felt like sharing, which fell squarely into the "why the hell didn’t I know about this before?" category. In this post, I’ll describe how to manage the various configuration files in your GNU/Linux home directory (aka "dotfiles" like .bashrc) using GNU Stow.

Source: Using GNU Stow to manage your dotfiles, an article by Brandon Invergo.

The limits of Python vectorization as a performance technique

Vectorization in Python, as implemented by NumPy, can give you faster operations by using fast, low-level code to operate on bulk data. And Pandas builds on NumPy to provide similarly fast functionality. But vectorization isn’t a magic bullet that will solve all your problems: sometimes it will come at the cost of higher memory usage, sometimes the operation you need isn’t supported, and sometimes it’s just not relevant.

Source: The limits of Python vectorization as a performance technique, an article by Itamar Turner-Trauring.

Solving “The Dangler” Conundrum with Container Queries and :has()

Y’know that situation where you tell the client, “Here’s your website and you can edit those four (4) little homepage features in the CMS” and the client says “Okay okay okay” and you check the site a week later and it looks bad because the client —despite your incredible documentation— put an odd number of items in the feature grid? It’s a major minor problem that’s tough to explain to the client, but it all comes down to…

The dangler.

Source: Solving “The Dangler” Conundrum with Container Queries and :has(), an article by Dave Rupert.

When Not to Use Docker: Cases Where Containers Don’t Help

Many organizations that adopt Docker or an adjacent containerization technology find it increases efficiency and accelerates the development process. Docker’s not something that magically improves every system though. In this article, we’ll look at some scenarios where moving to containers might be more of a hindrance than a help.

Source: When Not to Use Docker: Cases Where Containers Don’t Help, an article by James Walker.

What they don't teach you about sockets

In order to effectively write applications that communicate via sockets, there were some realizations I needed to make that weren't explicitly told to me by any of the documentation I read.

If you have experience writing applications using sockets, all of this information should be obvious to you. It wasn't obvious to me as an absolute beginner, so I'm trying to make it more explicit in the hopes of shortening another beginner's time getting their feet wet with sockets.

Source: What they don't teach you about sockets, an article by Macoy Madson.

Useless Math That Turned Out to Be Extremely Important

Mathematicians are a peculiar people. We live in our own little world, studying esoteric ideas that may or may not have much connection to the real world. One might wonder whether the bulk of what we study is actually useful. It’s true, after all, that we often pursue ideas not because there’s an immediate application, but simply because they’re interesting. By and large, it seems we aren’t overly concerned about immediate real-world application of our results.

Don’t start campaigning to cut math funding just yet, though. Math that doesn’t have applications today may very quickly become extremely important, even becoming integral to our way of life!

Source: Useless Math That Turned Out to Be Extremely Important, an article by Alex Shumway.

A Guide to Naming Variables

Software is written for people to understand; variable names should be chosen accordingly. People need to comb through your code and understand its intent in order to extend or fix it. Too often, variable names waste space and hinder comprehension. Even well-intentioned engineers often choose names that are, at best, only superficially useful. This document is meant to help engineers choose good variable names. It artificially focuses on code reviews because they expose most of the issues with bad variable names. There are, of course, other reasons to choose good variable names (such as improving code maintenance).

Source: A Guide to Naming Variables, an article by Jacob Gabrielson.