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 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 -
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 June 10, 2022 19:28
A very basic implementation of symbolic expressions. Operator overloading is fun!
import operator
from abc import ABC, abstractmethod
class Expression(ABC):
type = None
@staticmethod
def cast(value):
if isinstance(value, Expression):
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)
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) )})()
# 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
// 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 February 3, 2022 14:14
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
/* 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.
#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
@DavidBuchanan314
DavidBuchanan314 / transmission_skip_zeroes.patch
Created November 21, 2021 08:16
Quick and dirty patch for Transmission, to speed up verification of all-zeroes 32MB pieces (NOTE: torrents can have different piece sizes, this shouldn't really be hardcoded)
diff --git a/libtransmission/verify.cc b/libtransmission/verify.cc
index ad7a6a802..026087149 100644
--- a/libtransmission/verify.cc
+++ b/libtransmission/verify.cc
@@ -52,6 +52,7 @@ static bool verifyTorrent(tr_torrent* tor, bool* stopFlag)
while (!*stopFlag && pieceIndex < tor->info.pieceCount)
{
tr_file const* file = &tor->info.files[fileIndex];
+ bool skipping = memcmp(tor->pieceHash(pieceIndex).data(), "\x57\xb5\x87\xe1\xbf\x2d\x09\x33\x5b\xda\xc6\xdb\x18\x90\x2d\x43\xdf\xe7\x64\x49", 20) == 0;