Skip to content

Instantly share code, notes, and snippets.

View stuartlangridge's full-sized avatar

Stuart Langridge stuartlangridge

View GitHub Profile
@stuartlangridge
stuartlangridge / firehose.py
Created July 6, 2023 19:16
Python file to read the Bluesky ("atproto") firehose and show the json of each message. (Doesn't contain the author, because who knows how the hell to do that.)
from atproto.firehose import FirehoseSubscribeReposClient, parse_subscribe_repos_message
import sys
from atproto import CAR, models
from atproto.cbor import decode_dag, decode_dag_multi
from atproto.xrpc_client.models.utils import get_or_create
import json
class JSONExtra(json.JSONEncoder):
"""raw objects sometimes contain CID() objects, which
seem to be references to something elsewhere in bluesky.
@stuartlangridge
stuartlangridge / get_mastodon_servers.py
Created February 15, 2023 23:42
A little Python script to fetch all of a person's Mastodon followers and followings and see which servers they're on
#!/usr/bin/env python3
import requests
import requests_cache
import json
requests_cache.install_cache('masto_cache')
MASTODON_USERNAME = "sil@mastodon.social"
def fetch(endpoint):
url = f"https://{server}/api/v1/accounts/{account_id}/{endpoint}"
@stuartlangridge
stuartlangridge / transcript
Created July 19, 2022 19:48
PHP version of imul
# this file is $a, $b, expected answer for imul($a, $b)
$ cat tests/imul.txt
2,4,8
1,1,1
10,10,100
-1, -2, 2
1, 2, 2
-1, 2, -2
1, -2, -2
-0, 0, 0
#!/usr/bin/env python3
"""
Find "tubewhacks"; words or phrases whose letters appear in all but a single tube station's name
https://www.reload.me.uk/tubewhack/
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
stuartlangridge / sil-aspell-highlighter.py
Created August 13, 2021 15:04
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_BEFORE = "👉"
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
stuartlangridge / github-org-unsubscribe.py
Created July 27, 2021 18:02
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
stuartlangridge / linuxtree.py
Created July 26, 2021 19:47
Parse FabioLolix/LinuxTimeline to get the chain of ancestry for Linux distros and find the longest
#!/usr/bin/env python3
import requests
try:
from requests_cache import CachedSession as MySession
except:
MySession = requests.Session
def unstring(s):
@stuartlangridge
stuartlangridge / million_sellers_by_country.py
Created February 20, 2021 19:29
Pub quiz question: which country has produced the most million selling popstars per square km? https://twitter.com/dsquareddigest/status/1363092145301827586
#!/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'))
#https://www.officialcharts.com/chart-news/the-best-selling-singles-of-all-time-on-the-official-uk-chart__21298/
@stuartlangridge
stuartlangridge / README.md
Created May 26, 2020 23:33
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
stuartlangridge / README.md
Created November 28, 2019 12:19
SCRIPT-8