Skip to content

Instantly share code, notes, and snippets.

View agfor's full-sized avatar

Adam Forsyth agfor

  • Braintree
  • Chicago, IL
View GitHub Profile

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:

@agfor
agfor / mastermind.py
Created July 16, 2014 14:29
Mastermind
#!/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:
@agfor
agfor / gist:a81e60d5ae4bd8db70ca
Last active August 29, 2015 14:10
Example of function returning a value or a generator, see stackoverflow.com/q/7113032/#comment42623885_7113061
>>> def foo(bar):
... if bar:
... def baz():
... yield True
... return baz()
... else:
... return False
...
>>> foo(True)
<generator object baz at 0x100b82910>
@agfor
agfor / gist:320caaaa234ce4ef632b
Created March 18, 2015 04:06
Notes from Richard Stallman's Talk at Loyola, March 17 2015
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 / volume.py
Last active August 29, 2015 14:21
Applause volume based judging program for ChiPy Ultimate Language Shootout 2015
#based on http://ubuntuforums.org/showthread.php?t=500337
import alsaaudio, time, audioop
talks = """OCaml
R
Swift
PostScript
QML
Ruby
@agfor
agfor / dice.py
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)))
#print(result)
def choose(n, k):
"""
@agfor
agfor / TemporalNoise.java
Created April 23, 2012 22:51
A brief snippet to help a non-programmer engineer friend using ImageJ to do some basic time domain statistics on a series of raw image files
import java.io.*;
import java.lang.Math;
public class Temporal_Noise {
public static void main(String[] args) {
Temporal_Noise tn = new Temporal_Noise();
tn.run(null);
}
public void run(String dir_name) {
if (dir_name == null)
@agfor
agfor / extraitertools.py
Created April 23, 2012 22:55
A few extra itertools-esque snippets
import collections
import itertools
def last(iterable, deque=collections.deque):
return deque(iterable, maxlen = 1)[0]
def iterlen(iterable):
return sum(1 for _ in iterable)
def droptake(iterable, takecondition, dropcondition = None,
@agfor
agfor / huffman.py
Created April 23, 2012 23:04
A Huffman Coder / decoder written as a sandbox to experiment with hybrid OO and functional code
from __future__ import with_statement
from heapq import heapify, heappop, heappushpop
from itertools import count
from mmap import mmap
try:
from collections import Counter
except:
def Counter(iterable):
frequencies = __import__('collections').defaultdict(int)
for item in iterable:
@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)