Skip to content

Instantly share code, notes, and snippets.

@BenWiederhake
BenWiederhake / check-spellcheck.py
Created April 30, 2024 16:34
Find unnecessary spellcheck exclusions in uutils; run this from the top-level directory
#!/usr/bin/env python3
import re
import subprocess
RE_SPELLCHECK_DISABLE = re.compile("spell-checker:disable-\w+")
CACHED_FILES_STRING = None
def check_right_directory():
@BenWiederhake
BenWiederhake / randombeeps.py
Created October 8, 2023 12:23
Random beeps, perhaps it does nothing against tinnitus
#!/usr/bin/env python3
# Usage: python3 randombeeps.py | aplay -f cd
import math
import random
import struct
import sys
MIN_FREQ_HERTZ = 100
@BenWiederhake
BenWiederhake / words_allow_extra.lst
Created May 6, 2023 15:33
(Hopefully) Valid words in Serenity that don't appear in a dictionary
aaabf # Part of a commit
aarch
Aarch
ABCD
abefrnt # list of shortargs
abench
ABI
abrt
Absolutize
AcceptSocketConnections
// g++ -O2 -std=c++20 -o foo repro.cpp && ./foo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Vector {
~Vector() {}
char* data() {
if (m_outline)
return m_outline;
return reinterpret_cast<char*>(m_inline);
@BenWiederhake
BenWiederhake / pulser.py
Created January 30, 2022 20:10
Annoying pulser that pulses annoyingly
#!/usr/bin/env python3
from PIL import Image
import math
import time
SIZE = (400, 300)
TOTAL_TIME = 40
@BenWiederhake
BenWiederhake / lint-classes.py
Created September 12, 2021 16:53
Script that tries to identify and remove unused and unjustified headers in Serenity
#!/usr/bin/env python3
# Put this file in Meta/
from collections import defaultdict, Counter
import os
import random
import re
import subprocess
import sys
@BenWiederhake
BenWiederhake / █████.txt
Created March 9, 2021 13:10
Project "████████" (20██-██-██)
Example "FULL BLOCK": ██████.de = xn--4zhaaaaa.de
Example "SEVEN EIGHTS BLOCK": ▇▇▇▇▇▇.de = xn--3zhaaaaa.de
https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
Registrars tat don't work:
- DENIC (and thus *.de): Allows only hand-selected Unicode characters.
- Verisign (*.net, *.com): Doesn't let me paste it, even though Wikipedia claims it's supported
- .org: Says "Invalid entry", refuses to elaborate, even though Wikipedia claims it's supported
- OVH: kann's nicht.
#!/usr/bin/python3
# Example usage:
# $ ./video_cut.py lectXX-raw.mp4 lectXX-cut.mp4 00:07:59 00:56:48 01:06:26 01:56:59
# $ ffmpeg -i lectXX-cut.mp4 -c:v libx264 -preset slow -crf 23 lectXX.mkv # Re-encode (to save some space; make "23" higher for higher compression and lower quality)
# $ chmod -w lectXX.mkv
# $ rsync -Pv lectXX.mkv ${USER}@contact.mpi-inf.mpg.de:/www/inf-resources-0/download.mpi-inf.mpg.de/d1/tkids/
# And maybe remove write permissions, to prevent future mistakes.
import re
@BenWiederhake
BenWiederhake / feel_random.py
Created May 22, 2019 11:11
Generate "diverse" randomness that feels more natural than memory-less uniform distribution
#!/usr/bin/env python3
# Want:
# * Initially, uniform random distribution
# * If new elements appear, they are likely to be picked
# * If an element is picked, it is unlikely to be picked again soon
# * Long-ago-elements are roughly of the same probability (prevent permutation-lock)
# So:
# - Among new elements, pick uniform.
@BenWiederhake
BenWiederhake / sha1.py
Created July 22, 2018 17:47 — forked from bonsaiviking/sha1.py
SHA1 implementation in pure Python
#!/usr/bin/env python3
# Based on https://gist.github.com/bonsaiviking/5639034
# Converted to Python3 by hand.
import struct
def leftrotate(i, n):
return ((i << n) & 0xffffffff) | (i >> (32 - n))