App-wide CLI Configuration in Python

Tuesday, September 5th 2023

Recently I had the situation where I had a Python-based program to be used in a command line interface (CLI). But the program had many configuration options and I wanted a flexible way to deal with defaults and overriding them, while changing as little code as possible. I didn’t find great results on Google’s first page, so I thought I write it up here.

The problem with a reasonably large Python program, where code is distributed into several modules, is that we cannot really just pass a config dictionary around. There are too many functions, and it’s really annoying. So the first improvement is to export the configuration from variables in a config module. That’s better, but now we have to change the source code every time we want to change the program’s configuration. Not ideal. But there’s a somewhat neat solution with Python built-ins.

Read more

My first mechanical keyboard, and how you can get one too

Tuesday, April 2nd 2019

People in my Twitter stream would post pictures of their workplace every once in a while. More often than not, the picture would feature a fancy keyboard. I would then search the internet about it, get intringued, and leave it at that. But recently I went for it.

I’ll first list some advantages of custom mechanical keyboards, and then do my best to walk you through the process of getting your own. For rookies this is harder than you think.

So why would you want one?

First, because you can control every piece of hardware inside it. There’s a multitude of of switches to choose from, they differ in how hard you need to press them, in their haptic feedback, in their noisiness, and other things. There’s an endless supply of keycaps available. You can choose the PCB based on which layout, connector or LEDs you like. You can change any part of the whole to make it your keyboard.

Read more

Inspecting React Children

Saturday, September 1st 2018

Suppose you write a frontend framework in React, like Bootstrap. (If it’s for the web or react-native doesn’t matter for the argument.) There are components for different text styles (MediumText, SmallText…), for popular control elements (Dropdown, Button…) and so on. You want this to be modular and composable, so you pass a different text component to the Button instead of setting a size property on it. After all, the button size depends only on the content, why would you have a large button with small text inside?

<Button>
<SmallText>I am a small button</SmallText>
</Button>

But now there’s a problem. A button with small text should have less padding than with larger text. How does it know without a property?

Read more

Building a Relay-compatible GraphQL Server

Friday, February 3rd 2017

Read it over at the Zalando Tech Blog.

Read more

Footnotes in pure CSS

Thursday, March 19th 2015

Being a web developer is as much a blessing as it is a curse. One moment you’re reading an article about the most untradable players in the NBA by your favorite basketball author, the next you’re creeping around the footnote implementation of their site and wondering if Javascript is really necessary there.1

Of course it isn’t. There are games written completely in CSS. And they are also the solution to our problem. Both examples rely on differently styled or hidden, but still accessible input controls.

One way to achieve the latter is to surround the input with a label, then hide the input. Clicking the content will trigger a click on the invisible checkbox as well:

Read more