Python `decimal.getcontext` does not work with bpython

I have been working on a side project for which I’m using bpython, a “fancy interface to the Python interpreter.” If you use the Python REPL often, you should check it out. It offers unique features like in-line syntax highlighting, readline-like autocomplete, a “rewind” function to pop the last line of code from memory, auto-indentation and more. Anyway, today I found a bug in bpython, and that’s that Python’s decimal.getcontext() does not work with it. ...

June 6, 2023

macOS networkQuality tool

Today I learned about a precious little macOS command line tool, networkQuality. The networkQuality tool is a built-in tool released in macOS Monterey that can help diagnose network issues and measure network performance. Usage: networkQuality -v Example output: ==== SUMMARY ==== Uplink capacity: 44.448 Mbps (Accuracy: High) Downlink capacity: 162.135 Mbps (Accuracy: High) Responsiveness: Low (73 RPM) (Accuracy: High) Idle Latency: 50.125 milliseconds (Accuracy: High) Interface: en0 Uplink bytes transferred: 69.921 MB Downlink bytes transferred: 278.340 MB Uplink Flow count: 16 Downlink Flow count: 12 Start: 13/05/2023, 15:04:13 End: 13/05/2023, 15:04:27 OS Version: Version 13.3.1 (a) (Build 22E772610a) It supports Apple’s Private Relay, offers some configuration options and allows setting up your own server. More info here. ...

May 15, 2023

The real cost of interruption

I’m just back from reading Programmer Interrupted: The Real Cost of Interruption and Context Switching, an interesting short piece in which I learned about at least two new things. First, The Parable of the Two Watchmakers, introduced by Nobel Prize winner Herbert Simon, describes the complex relationship between sub-systems and their larger wholes. In the context of the article, it helps explain, even for non-programmers, the cost of an interruption. It also hints at a possible mitigation technique: ...

April 7, 2023

Hand dryers

via

February 28, 2023

Awesome psql tips

Today I learned about psql-tips.org by Lætitia Avrot, an excellent repository of psql (the CLI tool, not the database itself) tips. I like how one randomized tip is playfully served on the home page while the complete list is always at hand.

February 23, 2023

Making the latest C# language features available in older .NET versions

In a C# library I’ve been working on, I wanted to use C# 9.0’s init keyword. Quoting the documentation: The init keyword defines an accessor method in a property or indexer. An init-only setter assigns a value to the property or the indexer element only during object construction. This enforces immutability so that once the object is initialized, it can’t be changed again. Consider the following class: public class Person { public string FirstName { get; init; } } You can initialize it like this: ...

February 4, 2023

On implementing the ASP.NET Core 7 rate-limiting middleware

Today, my last self-assigned duty before the Christmas break was to migrate our in-house rate-limiting implementation (based on the AspNetCoreRateLimiting third-party package) to the new, shiny rate-limiting middleware introduced by ASP.NET Core 7. While the process was relatively straightforward, I stumbled upon a few quirks I want to annotate here. Our use case is simple. We use what the ASP.NET Core 7 documentation defines as a “fixed window limiter.” It uses a specified time window to limit requests. When the time window expires, a new time window starts, and the request limit is reset. Consider the following code (for convenience, I’m using an extension method): ...

December 23, 2022

Brazilian Ju-Jitsu and me

I attended my first BJJ class a little more than a month ago. Going into it, I was hesitant. After many years doing what most people today call calisthenics, I wanted to try something new and challenging. But would it be appropriate for me to get into martial arts at the age of fifty-two? When I discovered that we have a branch of the renowned Roger Gracie Academy here in my hometown, I thought it was time to find out. ...

October 27, 2022

How to avoid unwanted calls on iPhone

Oh, joy. After many years with an iPhone, today I learned how to stop spam calls with a single, not-really-super-secret move. Settings > Phone > Silence Unknown Callers That’s it. Unknown callers now go straight to my recent calls list for me to (eventually) review. Most importantly, the phone doesn’t ring. I initially had True Caller installed and enabled, which worked for a while. Spammers use throw-away numbers anyway, so it’s super-hard for tools like that to keep track. In Italy, we can enlist in a nationwide “oppositions register”. Once a phone number is registered there, national call services can’t call it. I signed up on the register’s opening day, which also worked for a few days. There are ways for spammers to go around the register, such as calling from abroad. I fell back to simply not answering unknown calls. That worked, but unsolicited calls still caught my attention and muting the phone helped only a little. ...

October 20, 2022

The Docker Event Monitor

I added a new tool to my amateurish DevOps toolbox. Developed in the open by Tom Williams, the Docker Event Monitor is a “tiny container that monitors the local Docker event system in real-time and sends notifications to various integrations for event types that match the configuration. For example, you can trigger an alert when a container is stopped, killed, runs out of memory or health status change.” At its core sits a simple python script that monitors the docker.sock file for noticeable changes. The code is straightforward and looks safe to me. It only took a few minutes to set DEM up so that our alerts channel on Slack gets notified of any health status changes. Some handy options are included; my favorite is silence to set a time window during which alerts are not fired. It avoids unnecessary spam when routine maintenance goes off on your stack. ...

September 8, 2022