Nat Knight

Reflections, diversions, and opinions from a progressive ex-physicist programmer dad with a sore back.

#python #data

Greg Wilson was soliciting strategies for lazy-loading datasets in Python modules. There are, of course, many ways to do this, but I didn't see this one being discussed.

Since Python 3.7 (released in 2017) you can define a module-level __getattr__ function that gets used for name resolution (see PEP 562). You can use this to call a data-loading function the first time each module-level property is accessed. This implementation uses only functions, dicts, and the one magic “dunder” function, which might be more approachable than programming with classes (depending on your audience).

Read more...

#webtool #hypertext #web

After yet another fight with the syntax for text fragments in URLs (which I've written about before) I had Claude whip up a little app for constructing and testing them.

It's published here.

#aprilcools #ttrpgs #community

It’s April Cools! It’s like April Fools, except instead of cringe comedy you make genuine content that’s different from what you usually do. This is my very first April Cools post. 🥶

I attend (and marginally help organize) a local in-person monthly tabletop role-play game meetup. It's consistently the extracurricular highlight of my month. Whether you've been playing for years, are just getting into the hobby, or (like me) have had to dramatically cut back the time you spend at the table because you're a parent, it's a great way to scratch the TTRPG itch without the considerable labour and time commitment of a long-term campaign.

Running games at a public meet up on a monthly basis is very different from running a home game. This article talks about some of the challenges you might have and gives some advice on how you might successfully run a meetup of your very own.

Read more...

#link #ai

Laurie Voss hypothesizes that rather than driving all software developers out of a job, the rise of generative LLMs and “vibe coding” will result in more overall software development jobs, but that they will look different than the ones that currently exist.

The argument goes roughly:

  • LLMs are a new layer of abstraction for writing programs
  • New layers of abstraction create new kinds of programmers who don't think as much about layers lower on the stack
  • There's lots of unmet demand for software development
  • Developers who can “vibe code” to meet this need will be numerous, productive, and decently paid (though perhaps not well compensated as developers in 2025).

He also argues that overall demand for software development will go up as it gets cheaper, so salaries for current developers won't really be impacted.

While I have a couple of quibbles, I like this a lot! I think “AI is a new level of abstraction” is a much more useful take than “all code will be written by AI” or “AI is useless and will go away”. The idea of a software engineer who doesn't really know how to code is very strange, but I can sort of see how it would work with the right tools. You would need a bunch of knowledge about protocols, databases, architecture, etc. that previously would have been inaccessible to someone who doesn't code, but that's changed now.

I'm not sure I buy the “salaries won't go down” component. We've witnessed fifty years of capital rapaciously sucking up every grain of surplus profit it can, so if there's a way that LLMs could be used to undermine software developers' bargaining power re: the cost of their labour I bet someone will find it, or at least try hard enough that it will be a bad time, at least in the short term.

With all the AI hype flying around leaders who (for example)

  • replace their staff with AI agents
  • create a class of “vibe coders” whose salaries are anchored lower
  • buy AI licenses for their favourite half of the engineering team and lay off the other half

will be lionized as bold and forward thinking, at least until the negative consequences of these actions start to crop up. I think they will crop up, because more code means more tech debt, and with fewer people building theories you're going to hit that wall sooner or later, but the owning class and their lackeys can remain irrational way longer than it takes to erode your salary.

#til #webdev #javascript #clipboard

I remember a time when there were whole libraries dedicated to clipboard management.

Turns out in browsers released after ~2020 you can do it with one line:

navigator.clipboard.writeText(text).then(console.log).catch(console.error);
Read more...

#til #javascript #webdev #customelements

I was working on a custom element today that replaces a textarea with CodeMirror in the UI while still updating the textarea in the background so that it can be submitted in a form. I ran across a wild footgun in custom elements.

StackOverflow eventually provided the solution. There's a solution on stack overflow, but Danny Engleman wrote up a more thorough explanation.

Read more...

#uv #python #til #scripting

I've known for a while that uv can run Python scripts that declare inline dependencies.

I learned today that you can also use uv to manage those dependencies.

Read more...

#release #sqlite3

I wrote a spec for a SQLite-based todo database and just release version 0.1.

Read more...

#llm #mlx #huggingface

TL;DR: Create a directory to hold Hugging Face data and set the environment variable HF_HOME to that directory's path.

For example:

mkdir /Volumes/externaldrive/huggingface
export HF_HOME='/Volumes/externaldrive/huggingface' 

You'll also want to set it in your .profile or .bashrc or wherever you set these things.

Read more...

#web #hypertext

Or “how you can link to arbitrary text on a webpage”.

The syntax is a little weird, but you can add a specially formatted anchor to a URL to link to a snippet of text.

The syntax is:

https://example.com#:~:text=[prefix-,]textStart[,textEnd][,-suffix]

I find it particularly useful for linking to a quote in a longer article.

See MDN for the full documentation.