Skip to content

Instantly share code, notes, and snippets.

View mreid's full-sized avatar

Mark Reid mreid

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mreid on github.
  • I am mreid (https://keybase.io/mreid) on keybase.
  • I have a public key whose fingerprint is 0290 8892 E023 A876 460B D320 2B84 F83F 283D 58D8

To claim this, I am signing this object:

@mreid
mreid / huffman.py
Last active September 25, 2021 12:22
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.'''
assert(sum(p.values()) == 1.0) # Ensure probabilities sum to 1
# Base case of only two symbols, assign 0 or 1 arbitrarily
if(len(p) == 2):
@mreid
mreid / arithmetic.py
Last active August 29, 2015 14:07
Toy implementation of arithmetic coding as described in Cover & Thomas §13.3
# Example implementation of simple arithmetic coding in Python (2.7+).
#
# USAGE
#
# python -i arithmetic.py
# >>> m = {'a': 1, 'b': 1, 'c': 1}
# >>> model = dirichlet(m)
# >>> encode(model, "aabbaacc")
# '00011110011110010'
#
@mreid
mreid / gist:fec7eb92b1670684e6e51d56dd3fd391
Created March 4, 2025 04:41
Crow script for Phantasms performance
---strum sequencer for just friends, w/syn, mangrove and crow
--- Adapted from script by WilliamHazard: https://llllllll.co/t/jf-strum/59169
--- Used in https://youtu.be/-j5uSu7hiCo?si=krmbytEQypPDsq5D
s = sequins
a = s{0,3,8,5,10,15,s{19,24,31}}
b = s{1,2,3,-1}
c = s{0,3,8,s{3,5,0,5}}
d = s{0,3,5,15,s{12,17,8,10}}