Skip to content

Instantly share code, notes, and snippets.

View agfor's full-sized avatar

Adam Forsyth agfor

  • Braintree
  • Chicago, IL
View GitHub Profile
#!/usr/bin/env python3
import random
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
class FakeEtcd:
agfor / gist:3b96a04fd76c117ab030270c6450d90b
Last active June 3, 2017 16:53
Adam Forsyth Home Purchase / Mortgage
View gist:3b96a04fd76c117ab030270c6450d90b
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.
agfor /
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 /
Last active August 29, 2015 14:26
Calculate the frequencies of different total face values for rolling n six sided dice.
#Naive version. Takes a couple of minutes for 11 dice on my laptop
#from itertools import product
#from collections import Counter
#dice = int(input('How many dice? '))
#result = Counter(map(sum, product(range(1, 7), repeat=dice)))
def choose(n, k):
agfor /
Last active August 29, 2015 14:21
Applause volume based judging program for ChiPy Ultimate Language Shootout 2015
#based on
import alsaaudio, time, audioop
talks = """OCaml
agfor / gist:320caaaa234ce4ef632b
Created March 18, 2015 04:06
Notes from Richard Stallman's Talk at Loyola, March 17 2015
View gist:320caaaa234ce4ef632b
These notes are just what struck me as worth writing down. It was a pretty standard speech of his, so some of this is the color you wouldn't necessarily get by watching a video online.
He ran down the aisle shouting "dammit dammit dammit" when he arrived, which made a toddler in the back of the room yell the same.
He picked his feet.
My tea's not hot enough. It needs to be run through the machine again. The water should fall right on the tea bag if possible.
agfor / gist:a81e60d5ae4bd8db70ca
Last active August 29, 2015 14:10
Example of function returning a value or a generator, see
View gist:a81e60d5ae4bd8db70ca
>>> def foo(bar):
... if bar:
... def baz():
... yield True
... return baz()
... else:
... return False
>>> foo(True)
<generator object baz at 0x100b82910>
agfor /
Created July 16, 2014 14:29
#!/usr/bin/env python3
import sys
assert sys.version[0] == '3'
from random import choice
from itertools import product
from collections import Counter, defaultdict
class Settings:

Keybase proof [11/299]

I hereby claim:

  • I am agfor on github.
  • I am agf ( on keybase.
  • I have a public key whose fingerprint is 0648 5B84 A556 77B0 4442 6A36 74F0 4AF9 EEF6 7BB2

To claim this, I am signing this object:

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]