Skip to content

Instantly share code, notes, and snippets.

View agfor's full-sized avatar

Adam Forsyth agfor

  • Braintree
  • Chicago, IL
View GitHub Profile
@agfor
agfor / skein.py
Last active February 22, 2021 23:50
A pure-Python implementation of a subset of the Skein hash function. Written to see if I understood the spec.
from __future__ import print_function, division
from math import ceil
from operator import xor, getitem
from functools import reduce
from struct import unpack, pack
two64 = 0x10000000000000000
def hexToBytes(hexes):
hexes = hexes.replace(' ', '')
return bytes(int(hexes[i:i+2], 16) for i in range(0, len(hexes), 2))

Python Number Conversion Chart

From To Expression
#!/usr/bin/env python3
import random
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
class FakeEtcd:
@agfor
agfor / gist:3b96a04fd76c117ab030270c6450d90b
Last active June 3, 2017 16:53
Adam Forsyth Home Purchase / Mortgage
8 Spruce Street, Lake Placid, NY 12946
$247,500 purchase price
20% down
$198,000 mortgage
30 year fixed
Primary Residence
First home purchase
Single family home
Do not need to escrow taxes and insurance,
but will if it is lowers interest rate.
class TransposedMatrix(object):
def __init__(self, matrix, index = None):
self.matrix = matrix
self.index = index
def __getitem__(self, index):
if self.index is None:
return TransposedMatrix(self.matrix, index)
return self.matrix[index][self.index]
@agfor
agfor / mssp.py
Created December 3, 2015 02:54
Brute force multiple subset sum solution
from collections import OrderedDict
from pprint import pprint
def greedy_reduction(weights, capacities):
weights = [{'weight': weight, 'used': False} for weight in sorted(weights, reverse = True)]
knapsacks = [{'capacity': capacity, 'load': 0, 'weights': []} for capacity in sorted(capacities, reverse = True)]
for knapsack in knapsacks:
for weight in weights:
if weight['used']:
@agfor
agfor / Install_tmux
Created July 6, 2012 20:28 — forked from simme/Install_tmux
Install and configure tmux on Mac OS X
# First install tmux
brew install tmux
# For mouse support (for switching panes and windows)
# Only needed if you are using Terminal.app (iTerm has mouse support)
Install http://www.culater.net/software/SIMBL/SIMBL.php
Then install https://bitheap.org/mouseterm/
# More on mouse support http://floriancrouzat.net/2010/07/run-tmux-with-mouse-support-in-mac-os-x-terminal-app/
@agfor
agfor / imagestats.py
Created April 23, 2012 23:21
A Python module to help a non-programmer engineer fried do some statistical analysis on raw images
#!/usr/bin/env python3
#from tkFileDialog import askopenfilenames
from tkinter.filedialog import askopenfilename
import os, os.path
from itertools import chain, repeat
from operator import itemgetter, sub, pow, truediv
from array import array
from math import sqrt
from sys import argv
@agfor
agfor / fixed_point_combinators.py
Created April 23, 2012 23:19
Some experiments with implementations of fixed point combinators in Python
from __future__ import print_function
from collections import defaultdict
import functools
def Y(f):
@functools.wraps(f)
def Yf(*args):
return inner(*args)
inner = f(Yf)
@agfor
agfor / orderedsets.py
Created April 23, 2012 23:18
Several Ordered Set implementations I wrote after seeing a question about them on Stack Overflow
from collections import OrderedDict
class OrderedSet(object):
def __init__(self, iterable = None):
self.storage = OrderedDict()
if iterable:
self.storage.update((elem, True) for elem in iterable)
def __contains__(self, elem):
return elem in self.storage
def __iter__(self):
return iter(self.storage)