Building JetBrains IDEs with Nix

This one is mostly a note for myself, and is quite possibly not the cleanest solution ever (still not confident in my Nix skills). NixOS sometimes lags behind the latest versions of the JetBrains IDEs, so I managed to scrape together a file which can be used to build the latest versions of the IDEs. I found the base for this file in a GitHub discussion about building JetBrains Gateway, which incidentally also works, if you substitute in the right links. [Read More]

The purest of evils

So I was playing with custom import functionality, and… def slightly_wrong(module_wrapper: ModuleWrapper, name: str, item: _T) -> _T: if callable(item): fn = cast(Callable[_P, _R], item) @functools.wraps(fn) def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R: result = fn(*args, **kwargs) if isinstance(result, float): result += result * random.uniform(-0.01, 0.01) return result return wrapper if isinstance(item, float): return item + item * random.uniform(-0.01, 0.01) return item with import_hook(slightly_wrong): from math import pow, pi # . [Read More]

Neat mypy trick - avoid runtime exceptions with Protocol and ClassVar

I’m writing a little utility library that among other things deals with asynchronously managing subprocesses. One of the things I want it to do is to make it easier to process output for arbitrary command line utilities. It’s still early on in development, so I’m in the fun part of the process of playing with concepts, trying things out and deciding what the API should look like. That’s just before the terrifying part of having to pick a name. [Read More]

Sometimes you gotta fix it yourself

I’m a huge motorsports fan, and this weekend I had the privilege of attending the 2021 São Paulo Grand Prix. It was an amazing Formula 1 race in the highly regarded Interlagos circuit, and it’ll go down as one of the classic races of the sport, with a performance from Lewis Hamilton that was nothing short of breathtaking. COVID is still a concern in sports events such as this, and reasonably enough, F1 management elected to use a digital solution to verify vaccination status for anyone who attended. [Read More]

Live snippets for JetBrains IDEs

I love JetBrains IDEs. One thing they offer is customizable live snippets. These are dynamic code templates which allow you to input common patterns quickly. It’s not just copy-pasting a set of templates; they can do things like position the caret automatically at relevant points in the snippet and dynamically insert things like the current file name or line number, or the date and time. I’ll try to keep this blog post updated as I create more live templates. [Read More]

Recursively deleting all protected related objects in Django

When debugging Django applications, it’s often useful to delete objects so that you can try the thing you’re working on again and recreate them. This isn’t always trivial though, because related objects that have on_delete=PROTECT can prevent you from doing so. This is a great safeguard when the application is running in production, but not so much when you know what you’re doing and just want to test something in your own environment. [Read More]

Fast reshaping with iterators

Lately I’ve been reading up a bit more on functional programming. I feel that after years of knowing about the existence of the paradigm and even trying to dip my toes in a couple of times without success, now it finally “clicked”. I’m still playing around with concepts and languages, and trying to look at some programming exercises in a more functional light. It was surprising to me, though, how easily and efficiently I was able to solve today’s LeetCode challenge . [Read More]

Probabilistic data structures - bloom filters

Traditionally in programming we think about 0s and 1s as being infallible. They either are, or aren’t, and other than for cosmic rays flipping bits in RAM (it happens) there’s not much margin for uncertainty. It’s one of the nice things about computers: our memory is imperfect, but theirs isn’t. What if we could trade off a bit of this consistency for a lot of performance, though? Well, it turns out that we sometimes can, by using probabilistic data structures. [Read More]

I was playing around with my Canon T6 camera and gphoto2 for Python. The library worked great, but it was kind of finnicky to navegate the generated SWIG bindings and figure out what was there. Here’s a handy script that lists all the available configurations for a camera: import gphoto2 as gp camera = gp.Camera() camera.init() def get_configs_dict(widget): """Builds a dictionary with the current and possible configurations for a given camera. [Read More]