Skip to content

Instantly share code, notes, and snippets.

View notwa's full-sized avatar
🚲
bikeshedding

Connor notwa

🚲
bikeshedding
View GitHub Profile
@notwa
notwa / colors.txt
Last active November 1, 2022 08:34
trackmogrify
indianRed
lightCoral
salmon
darkSalmon
lightSalmon
crimson
red
fireBrick
darkRed
pink
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@notwa
notwa / ac_encode.py
Last active September 11, 2018 21:03
Arithmetic coding
# Arithmetic coding compressor and decompressor for binary strings.
# via: http://www.inference.org.uk/mackay/python/compress/ac/ac_encode.py
# main page: http://www.inference.org.uk/mackay/python/compress/
# this has been cleaned up (passes pycodestyle) and ported to python 3.
# default prior distribution
BETA0 = 1
BETA1 = 1
M = 30
@notwa
notwa / tennis.c
Last active June 4, 2018 18:14
Mario Tennis (N64) Ring Tournament code generator
// arbitrary terminology i made up on the spot:
// "entry" = code as exposed to user, in ASCII.
// "code" = code as indices into lut, used internally.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef uint32_t u32;
@notwa
notwa / _example.sh
Last active March 21, 2018 10:23
recompress.py: deconstruct and reconstruct Ocarina of Time ROMs
#!/usr/bin/env bash
set -e
# set this as needed!
rom="Legend of Zelda, The - Ocarina of Time (U) (V1.0) [!].z64"
output="reconstructed.z64"
gcc_flags="-std=gnu11 -Wall -O3 -s"
import autograd.numpy as np
import autograd.numpy.random as npr
from autograd.misc.flatten import flatten
from autograd.misc.optimizers import unflatten_optimizer
import itertools, types
def iterize(iterable):
if type(iterable) in (tuple, list):
iterator = iter(iterable)
elif np.isscalar(iterable):
@notwa
notwa / huffman.py
Last active October 21, 2020 18:46 — forked from mreid/huffman.py
Example implementation of Huffman coding in Python
# Example Huffman coding implementation
# Distributions are represented as dictionaries of { 'symbol': probability }
# Codes are dictionaries too: { 'symbol': 'codeword' }
def huffman(p):
'''Return a Huffman code for an ensemble with distribution p.'''
# Base case of only two symbols, assign 0 or 1 arbitrarily
if len(p) == 2:
return dict(zip(p.keys(), ['0', '1']))
@notwa
notwa / dwarf.lua
Last active April 21, 2018 02:15
dwarf fortress (VGA) font in love2d format
-- This is free and unencumbered software released into the public domain.
-- For more information, please refer to <http://unlicense.org/>
local charset = ("\
\x00☺☻♥♦♣♠•◘○◙♂♀♪♫☼\
►◄↕‼¶§▬↨↑↓→←∟↔▲▼\
!\"#$%&'()*+,-./\
0123456789:;<=>?\
@ABCDEFGHIJKLMNO\
PQRSTUVWXYZ[\\]^_\
@notwa
notwa / clock.h
Last active March 3, 2018 23:49
portable snippets clock.h without pulling in windows.h — https://github.com/nemequ/portable-snippets
/* Clocks (v1)
* Portable Snippets - https://github.com/nemequ/portable-snippets
* Created by Evan Nemerson <[email protected]>
*
* To the extent possible under law, the authors have waived all
* copyright and related or neighboring rights to this code. For
* details, see the Creative Commons Zero 1.0 Universal license at
* https://creativecommons.org/publicdomain/zero/1.0/
*
* Modified by Connor Olding, 2017
@notwa
notwa / sckey.c
Created August 21, 2017 11:22
Starcraft CD-Key Validator
int validate(const char *key) {
int magic = 3;
int count = 0;
for (char c; (c = *key); key++) {
if (c < '0' || c > '9') continue;
int v = c - '0';
if (++count == 13) {
// final character.
return magic % 10 == v;
} else {