Skip to content

Instantly share code, notes, and snippets.


Stuart Langridge stuartlangridge

View GitHub Profile
#!/usr/bin/env python3
Find "tubewhacks"; words or phrases whose letters appear in all but a single tube station's name
Yeah, I'm just here to ruin the fun of thinking them up, by applying code to the problem. Sorry.
import os
import textwrap
stuartlangridge /
Created Aug 13, 2021
A small script for Ian Lloyd. Pass text to it on stdin and it outputs that same text with spelling errors highlighted. Change the highlight characters at the top if you need to.
#!/usr/bin/env python3
import sys, subprocess
HIGHLIGHT_AFTER = "👈" # if you just want a highlight before, make this ""
cmd = ["aspell", "pipe"]
# add any extra options given to our command to the aspell command
if len(sys.argv) > 2:
cmd += sys.argv[1:]
for line in sys.stdin.readlines():
# feed the line to aspell; will throw obvious error on failure
stuartlangridge /
Created Jul 27, 2021
Unsubscribe from all Github repos for a specific org
#!/usr/bin/env python3
Github won't let you say "don't subscribe me to new repos" for
one specific org only. You can either turn off autosubscribe
for everything, or for nothing.
This is extremely annoying if you're added to a very busy
new organisation, most of which you don't care about. This is
because you don't want to turn off all autosubscriptions -- if your
friend adds you to her new repo as a committer, you still want
stuartlangridge /
Created Jul 26, 2021
Parse FabioLolix/LinuxTimeline to get the chain of ancestry for Linux distros and find the longest
#!/usr/bin/env python3
import requests
from requests_cache import CachedSession as MySession
MySession = requests.Session
def unstring(s):
stuartlangridge /
Created Feb 20, 2021
Pub quiz question: which country has produced the most million selling popstars per square km?
#!/usr/bin/env python3
import requests
import requests_cache
import urllib.parse
import os.path
requests_cache.install_cache(os.path.join(os.path.dirname(__file__), 'million_sellers'))
stuartlangridge /
Created May 26, 2020
A deno script to make a single plain HTML file version of the deno manual

Note that this is a very quick thing. In particular, it only handles two levels of documentation in the manual, and it doesn't include images. Both would need to be fixed for this to actually be useful; however, this was entirely sufficient to drop a copy onto my phone where I could read it while my stupid mobile operator pretends to fix my network, sigh, etc.

stuartlangridge / example.js
Last active Nov 13, 2019
Exporting an SVG from Figma and identifying which SVG elements in the exported file correspond to which objects in Figma
View example.js
const getSvgNamesForNodes = () => {
// this is guesswork. When Figma has two nodes with the same name (say, "Union"),
// it serialises them into SVG with names "Union" and "Union_2", but it's not
// clear which one becomes "Union" and which "Union_2". It is theorised that this
// is done in the same order that .findAll returns, so we make use of that.
// Figma might decide to change this at any time, of course. It would be much
// nicer if there were an SVG export option which also serialised getPluginData()
// data as data-* attributes in the output SVG, but there isn't, yet.
let names = {};
let nameIndices = {};
import numpy as np
import glob
import markdown
import re
from bs4 import BeautifulSoup
def make_pairs(corpus):
for i in range(len(corpus)-1):
yield (corpus[i], corpus[i+1])
stuartlangridge /
Last active Nov 25, 2020
Gimp 2.8 Sprite Sheet from layer groups (python-fu)

A thing to convert a Gimp image of multiple layered sprites into a sprite sheet.

The way I make pixel art sprites is this: imagine you're drawing, say, a knight. I have all the frames for that knight in one great big Gimp XCF image, organised into groups.

So there's a layer group called "Running"; this defines a whole sprite, in multiple frames. In there, there's a set of layer groups, one per frame, called "Running 1" to "Running 9" (for example). In "Running 1", there's one or more layers which all go together to form that one single frame. This works out neatly because you can make an individual frame out of a few different parts, and edit those parts separately. This makes it easy to copy unchanging parts from one frame to the next, while just changing the bits that are different.