Skip to content

Instantly share code, notes, and snippets.

View agfor's full-sized avatar

Adam Forsyth agfor

  • Braintree
  • Chicago, IL
View GitHub Profile

Python Number Conversion Chart

From To Expression
@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)
@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))
@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 / 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 / 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)