Skip to content

Instantly share code, notes, and snippets.

View DavidBuchanan314's full-sized avatar
🌍
Hack the planet!

David Buchanan DavidBuchanan314

🌍
Hack the planet!
View GitHub Profile
import os
import sys
"""
This (pure!) python script streams a gzip-compressed YUV4MPEG video to stdout.
It easily runs at 1080p60fps on my machine.
Pipe it into a media player like this:
python3 gzip_swar_life.py | mbuffer | gunzip - | mpv -
@DavidBuchanan314
DavidBuchanan314 / Makefile
Last active January 9, 2024 22:19
A second attempt at simdutf incremental utf8 validation (proof-of-concept, not rigorously tested, see https://github.com/simdutf/simdutf/issues/361 )
CFLAGS := -Wall -Wextra -Wpedantic -O3
CXXFLAGS := ${CFLAGS}
LDFLAGS := -lsimdutf
main: main.o utf8_incremental.o
@DavidBuchanan314
DavidBuchanan314 / hash_json.py
Last active December 27, 2023 18:09
I wrote about this code in more detail here: https://www.da.vidbuchanan.co.uk/blog/signing-json.html
"""
DISCLAIMER: This is a quick prototype, it's not at all tested, and may be deeply cryptographically flawed.
Normally, JSON canonicalization is at least O(nlogn), because you need to sort the map keys.
This approach avoids the need to do that, and in theory it's O(n), but in practice it's probably slower for most inputs... I have not benchmarked.
If you limit recursion depth, you could implement it as an Online Algorithm https://en.wikipedia.org/wiki/Online_algorithm
NB: Python's JSON parser allows duplicate map keys, which this impl will be oblivious to.
/*
gcc main.c -o main -O3 -lSDL2
This hits 240fps at 4K resolution, on my M1 Pro
*/
#include <SDL2/SDL.h>
#include <stdio.h>
@DavidBuchanan314
DavidBuchanan314 / root_my_vm.py
Last active November 17, 2023 07:34
Get root any running *nix VM by patching it's memory from the host.
#!/usr/bin/python3
import sys
import os
import signal
PATTERN = b"root:x:0:0:root"
REPLACE = b"root::00:0:root"
import zlib
from io import BytesIO
# TODO: make this shorter
RLEFLATE_MAGIC = b'\xed\xe3\t\x90$I\x92$I\xcc\xff\xff\xff\xff\xff\xff\xff\xff'\
b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'\
b'\xff\xff\xff\xff?3333\xe1\x0e\x00\x0e``\xa0\xaa*"\xc2\xdc]U\x04\x00\x80'
RLEFLATE_EOF = b'\x77'
RLEFLATE_REPEAT = [
None, b'W', b'7', b'G', b'g', b'#', b'3', b'+', b';', b'\x11', b'Q',
@DavidBuchanan314
DavidBuchanan314 / bsky_firehose_standalone.py
Last active October 25, 2023 01:50
This is not production quality code, several corners have been cut, etc. etc.
import io
import base64
import struct
import hashlib
import asyncio
import websockets
from enum import Enum
# ground control to major type
// ==UserScript==
// @name Fake Widevine
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Fake the presence of a functional Widevine CDM - enough to get the spotify UI to launch, so you can pick another playback device.
// @author David Buchanan
// @match https://open.spotify.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant none
// ==/UserScript==
@DavidBuchanan314
DavidBuchanan314 / NWSL.TXT
Last active September 1, 2023 14:11
I think this is functionally MIT-equivalent but I am not a lawyer!
NUCLEAR WASTE SOFTWARE LICENSE V1.0
Copyright <YEAR> <OWNER>
This software license is a message... and part of a system of messages...
pay attention to it! Writing this software and associated documentation
files (the "Software") was important to us. We considered ourselves to be a
powerful culture. This Software is not a place of honor... no highly
esteemed deed is commemorated here... nothing valued is here. What is here was
dangerous and repulsive to us. This message is a warning about danger. The
#!/usr/bin/env python3
import os
"""
Cursed Code.
This code literally patches your kernel memory, proceed at your own risk.
Tested on Ubuntu 17.10 and Arch, x86_64. Should work on other distros, maybe even other architectures!