Skip to content

Instantly share code, notes, and snippets.

Avatar
🌍
Hack the planet!

David Buchanan DavidBuchanan314

🌍
Hack the planet!
View GitHub Profile
View gzip_swar_life.py
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 -
View swar_life.py
import os
import sys
"""
This (pure!) python script streams a YUV4MPEG format video to stdout. It easily
runs at 1080p60fps on my machine.
Pipe it into a media player like this:
python3 swar_life.py | mpv -
View periodict_table_golf.py
import inspect
# helper function to visualise the results
def print_table(width, height, function):
grid = [[" "]*(width + 1) for _ in range(10)]
for n in range(1, 118+1):
y, x = function(n)
grid[y][x] = str(n).ljust(3)
for x in range(1, width+1):
@DavidBuchanan314
DavidBuchanan314 / symbolics.py
Last active Jun 10, 2022
A very basic implementation of symbolic expressions. Operator overloading is fun!
View symbolics.py
import operator
from abc import ABC, abstractmethod
class Expression(ABC):
type = None
@staticmethod
def cast(value):
if isinstance(value, Expression):
View stegflate_decode.py
import zlib
import io
import sys
PNG_MAGIC = b"\x89PNG\r\n\x1a\n"
def parse_png_chunk(stream):
size = int.from_bytes(stream.read(4), "big")
ctype = stream.read(4)
body = stream.read(size)
View match_lambda_hack.py
from dataclasses import dataclass
def lambda_match_wrapper(instance, _locals):
return type("MatchWrapper", (), {
"__getattribute__": (lambda self, name:
type("EqWrapper", (), {
"__eq__": (lambda self, o:
eval(o, None, dict(_locals, self=instance)) )})()
if name == "_lambda" else
instance.__getattribute__(name) )})()
View pi_pico_easteregg.py
# based on https://github.com/unicorn-engine/unicorn/blob/master/bindings/python/sample_arm.py
from __future__ import print_function
from unicorn import *
from unicorn.arm_const import *
# https://github.com/raspberrypi/pico-bootrom/blob/ef22cd8ede5bc007f81d7f2416b48db90f313434/bootrom/bootrom_rt0.S#L441-L445
CODE = bytes.fromhex("""
.byte 0x11, 0x38, 0xc0, 0x7a, 0x00, 0xbd, 0x00, 0xb5
.byte 0x42, 0x40, 0x00, 0x2a, 0x00, 0xf0, 0x02, 0xf8
View scratch-desktop-live-reload.js
// edit this path according to your needs!
var projFile = "/Users/david/Sync/programming/python/boiga/test.sb3";
var fs = require("fs");
var vm = document.querySelector("#app")._reactRootContainer.current.child.child.child.stateNode.store.getState().scratchGui.vm;
var loading = false;
var watcher = fs.watch(projFile, async (event, filename) => {
if (!filename || loading) return;
var fileContents = await fs.promises.readFile(projFile);
if (!fileContents.length) return;
@DavidBuchanan314
DavidBuchanan314 / aes_fi.ino
Created Feb 3, 2022
Arduino AES-128 Fault Injection test program. Main loop is at the end of the file. AES impl from https://github.com/kokke/tiny-AES-c
View aes_fi.ino
/* https://github.com/kokke/tiny-AES-c */
#ifndef _AES_H_
#define _AES_H_
#include <stdint.h>
#include <stddef.h>
// #define the macros below to 1/0 to enable/disable the mode of operation.
//
// CBC enables AES encryption in CBC-mode of operation.
View bootselfie_solve.c
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
// charset is [a-z0-9\n\-]
// scancodes from https://stackoverflow.com/a/61192565
static const uint8_t CHARSET[] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 12};
// extracted from the floppy image