Skip to content

Instantly share code, notes, and snippets.

Adam Forsyth agfor

Block or report user

Report or block agfor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View multilock.py
#!/usr/bin/env python3
import random
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
class FakeEtcd:
@agfor
agfor / gist:3b96a04fd76c117ab030270c6450d90b
Last active Jun 3, 2017
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
agfor / mssp.py
Created Dec 3, 2015
Brute force multiple subset sum solution
View mssp.py
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 / dice.py
Last active Aug 29, 2015
Calculate the frequencies of different total face values for rolling n six sided dice.
View dice.py
#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)))
#print(result)
def choose(n, k):
"""
@agfor
agfor / volume.py
Last active Aug 29, 2015
Applause volume based judging program for ChiPy Ultimate Language Shootout 2015
View volume.py
#based on http://ubuntuforums.org/showthread.php?t=500337
import alsaaudio, time, audioop
talks = """OCaml
R
Swift
PostScript
QML
Ruby
@agfor
agfor / gist:320caaaa234ce4ef632b
Created Mar 18, 2015
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
agfor / gist:a81e60d5ae4bd8db70ca
Last active Aug 29, 2015
Example of function returning a value or a generator, see stackoverflow.com/q/7113032/#comment42623885_7113061
View gist:a81e60d5ae4bd8db70ca
>>> def foo(bar):
... if bar:
... def baz():
... yield True
... return baz()
... else:
... return False
...
>>> foo(True)
<generator object baz at 0x100b82910>
View mastermind.py
#!/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:
View keybase.md

Keybase proof [11/299]

I hereby claim:

  • I am agfor on github.
  • I am agf (https://keybase.io/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:

View search_sorted_matrix.py
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]
You can’t perform that action at this time.