Skip to content

Instantly share code, notes, and snippets.

@speezepearson
speezepearson / timetravel-rule30.py
Created July 16, 2021 06:33
Run Wolfram's Rule 30 on a not-quite-circular universe where one end is hooked up to the other end's past.
import argparse
from typing import Sequence, MutableSequence
_rule30 = {
(True, True, True): False,
(True, True, False): False,
(True, False, True): False,
(True, False, False): True,
(False, True, True): True,
(False, True, False): True,
@speezepearson
speezepearson / bip39.py
Last active June 24, 2021 06:09
Turn an arbitrary string into a BIP-39 twelve-word passphrase.
import getpass
import hashlib
bytes_to_bits = lambda bs: ''.join('1' if bs[i//8] & (128 >> (i % 8)) else '0' for i in range(len(bs)*8))
bip39_wordlist = 'abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve acid acoustic acquire across act action actor actress actual adapt add addict address adjust admit adult advance advice aerobic affair afford afraid again age agent agree ahead aim air airport aisle alarm album alcohol alert alien all alley allow almost alone alpha already also alter always amateur amazing among amount amused analyst anchor ancient anger angle angry animal ankle announce annual another answer antenna antique anxiety any apart apology appear apple approve april arch arctic area arena argue arm armed armor army around arrange arrest arrive arrow art artefact artist artwork ask aspect assault asset assist assume asthma athlete atom attack attend attitude attract auction audit august aunt author auto autumn average avocado avoid awake aw
from typing import Iterable, Sequence, Tuple
def to_int_with_replacement(base: int, digits: Sequence[int]) -> int:
if not digits:
return 0
return digits[0] + base * to_int_with_replacement(base, digits[1:])
def to_int_without_replacement(nsyms: int, digits: Sequence[int]) -> int:
if not digits:
return 0
@speezepearson
speezepearson / no-like-counts.js
Created January 22, 2021 05:56
Hide Substack comment-like-counts
// ==UserScript==
// @name Hide Substack comment-like-counts
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hide Substack comment-like-counts
// @author https://github.com/speezepearson
// @match https://*.substack.com/*
// @grant none
// ==/UserScript==
extern crate proc_macro;
use proc_macro::{TokenStream, TokenTree, Literal};
#[proc_macro_attribute]
pub fn superstitious(_attr: TokenStream, item: TokenStream) -> TokenStream {
panic_if_contains_13(item.clone());
item
}
fn panic_if_contains_13(ts: TokenStream) {
import argparse
import datetime
import os
from aiohttp import web
parser = argparse.ArgumentParser()
parser.add_argument('--host', default='localhost')
parser.add_argument('-p', '--port', default=8080)
parser.add_argument('--refresh-time', default=300)
@speezepearson
speezepearson / proxy-boilerplate.nginx.conf
Last active April 6, 2020 06:50
nginx proxy boilerplate
# Put this in /etc/nginx/conf.d/SOME_NAME.conf
# It should get included because of the
# http {
# include /etc/nginx/conf.d/*.conf;
# }
# in your /etc/nginx/nginx.conf
server {
listen 80;
listen [::]:80;
@speezepearson
speezepearson / aiohttp-boilerplate.py
Last active May 20, 2020 01:10
aiohttp boilerplate
"""Demo usage: python --open-browser $THIS_FILE
"""
import argparse
import typing as t
from aiohttp import web
class Server:
def __init__(self) -> None:
pass
@speezepearson
speezepearson / watchman_context.py
Created July 22, 2019 01:30
Python context manager to [de]register Watchman triggers.
import contextlib
import json
import subprocess
from pathlib import Path
from typing import Any, Collection, Iterator, Mapping
JsonTrigger = Mapping[str, Any]
@contextlib.contextmanager
def with_triggers(dir: Path, triggers: Collection[JsonTrigger]) -> Iterator[None]:
@speezepearson
speezepearson / chime-success.sh
Created April 2, 2017 02:20
Run a command, then chime success or failure.
#!/bin/bash
#
# Prefixed to a command, runs that command, and then makes a noise
# indicating whether the command passed or failed.
#
# Ubuntu only.
#
if eval "$@"; then
NAME='Mallet'