Programming Leftovers
-
Altering Python attribute handling for modules
A recent discussion on the Python forum looked at a way to protect module objects (and users) from mistaken attribute assignment and deletion. There are ways to get the same effect today, but the mechanism that would be used causes a performance penalty for an unrelated, and heavily used, action: attribute lookup on modules. Back in 2017, PEP 562 ("Module __getattr__ and __dir__") set the stage for adding magic methods to module objects; now a new proposal would extend that idea to add __setattr__() and __delattr__() to them.
-
on building jpeg-xl for wasm
I was planning on working on a redesign of a photo site, and wanted to use JPEG-XL as the preferred image format for storage. The only implementation I know of is the libjxl reference implementation written in C++. Alas, it hasn’t been a good week for JPEG successors, and I would much prefer not to run this code on my server.
While looking at libjxl a short while ago, I did notice that the build system supports compiling to WASM. Seems like this could be the needed solution to my safety concerns. Hook this into my go server with something like wazero, and I’d feel a lot more comfortable connecting this to the internet. I didn’t investigate too thoroughly at the time, but it seemed quite straightforward.
-
In a git repository, where do your files live?
Hello! I was talking to a friend about how git works today, and we got onto the topic – where does git store your files? We know that it’s in your .git directory, but where exactly in there are all the versions of your old files?
For example, this blog is in a git repository, and it contains a file called content/post/2019-06-28-brag-doc.markdown. Where is that in my .git folder? And where are the old versions of that file? Let’s investigate by writing some very short Python programs.
-
On Waiting
A key component is, before you dive into waiting mode, you should have a plan for monitoring the situation. In the preview feature example, the monitoring plan could be as simple as a calendar reminder to check back in, or you could wait until you feel the pain more acutely. If your “waiting” strategy is causing a lot of pain, that’s a great indicator that you can’t wait any longer.
-
How to Create a Histogram with Different Colors in R
Histograms are a fantastic way to visualize the distribution of data. They provide insights into the underlying patterns and help us understand our data better. But what if you want to add some color to your histograms to make them more visually appealing or to highlight specific data points? In this blog post, we’ll explore how to create histograms with different colors in R, and we’ll provide several examples to guide you through the process.
-
Are You a Terminal Emulator Hipster?
Is it worth getting used to another terminal? Which one? Why?
-
Race-free process creation in the GNU C Library
The pidfd API has been added to the kernel over the last several years to provide a race-free way for processes to refer to each other. While the GNU C Library (glibc) gained basic pidfd support with the 2.36 release in 2022, it still lacks a complete solution for race-free process creation. This patch set from Adhemerval Zanella seems likely to fill that gap in the near future, though, with an extension to the posix_spawn() API.
Unix systems refer to processes via an integer ID (the "process ID" or PID) that is assigned at creation time. The problem with PIDs is that they are reused over time; once a process with a given PID has exited and been reaped, that PID can be assigned to a new and unrelated process with the result that any given PID might not, in fact, refer to the process that the user thinks it does. To address this problem, the pidfd concept was introduced; a pidfd is a file descriptor that acts as a handle for a process. The process associated with a pidfd can never change, so many of the race conditions associated with PIDs do not exist with pidfds.