Categories
Posts

Changing a Django model’s primary key with migrations

Recently, I took on the task of internationalizing a Django app. The app included the following two simple models for tagging user Profiles with a set of pre-defined Tags: “Wait a minute…”, I thought to myself while scrolling through the models.py module for the first time. “How am I supposed to add a translation for […]

Categories
Posts

He or She? Or: The basics of (binary) classifier evaluation

Of all the amazing scientific discoveries of the 20th century, the most astonishing has to be that “men are from Mars, [and] women are from Venus”. (Not that the differences weren’t obvious pre-20th century, but it’s always good to have something in writing.) If indeed the genders do originate from different planets, then surely the […]

Categories
Posts

Where to define and instantiate associated models in Django

For the sake of example, let’s consider the following UML diagram describing two model classes and how they are interrelated: We can see that there are two classes, User and UserProfile, with a one-to-one association between them. That is, each instance of class User is associated with one and only one instance of UserProfile and […]

Categories
Posts

Guessing multiple extensions from dotted filenames in Python

How to extract suffixes from filenames with Python Defining a guess_extensions(filename) utility function that extracts extensions from a filename Recently I was dealing with filenames of the following form: 3a1d3614.2020-09-27.json.gz. That is, the filenames consisted of four parts: an alphanumeric ID, a date, and two extensions separated by dots. Python offers at least two built-in […]

Categories
Posts

How to fix committing to a wrong branch in Git

Make sure you are on the affected branch: git checkout wrong-branch Soft-reset the HEAD to the previous commit. In the words of git status, this will leave all your changed files as “changes to be committed”: git reset –soft HEAD^ Stash away the uncommited changes resulting from the previous step: git stash Apply the stashed […]

Categories
Posts

Disabling the Yoast sitemap’s stylesheet

If, for whatever reason, you’d like to disable the stylesheet that comes with Yoast’s sitemap, add the following piece of code to your theme’s functions.php: In case you are wondering, this is made possible by how Yoast implements the get_output(…) function in class-sitemaps-renderer.php: As you can see, the function calls the wpseo_stylesheet_url filter in line […]

Categories
Posts

Diagrammatic Icons and their Motivations: Central Concepts and Examples

Note: What follows is a linguistic essay I wrote during my time as a student pursuing a master’s degree in computational linguistics. I stumbled over it a few days ago while going through some old data. Given the general scarcity of information about the topic of iconicity, I’ve decided to publish it here. Despite its […]