Skip to content

Instantly share code, notes, and snippets.

View fogleman's full-sized avatar

Michael Fogleman fogleman

View GitHub Profile
@fogleman
fogleman / fib.py
Created October 20, 2012 15:49
Simpler Fibonacci Iterator
class FibonacciIterator(object):
def __init__(self):
self.data = [0, 1]
def next(self):
self.data.append(sum(self.data))
return self.data.pop(0)
class Fibonacci(object):
def __iter__(self):
return FibonacciIterator()
@fogleman
fogleman / git_cheat_sheet.md
Created November 28, 2012 21:36 — forked from ryansturmer/git_cheat_sheet.md
Git Cheat Sheet

Git Cheat Sheet

This attempts to be a useful "cheat sheet" for git. I'm just writing git recipes down here as I find and use them.

Getting Code

Clone a repository (GitHub)

git clone git@github.com:username/repository.git
@fogleman
fogleman / gist:4177546
Created November 30, 2012 18:23
2012 GitHub Game Off - Entries
@fogleman
fogleman / turing.c
Created May 15, 2013 01:54
2-D Turing Machine
#define NORTH 0
#define SOUTH 1
#define EAST 2
#define WEST 3
typedef struct {
int width; // width of the 2-D tape
int height; // height of the 2-D tape
int states; // number of states
int symbols; // number of symbols
@fogleman
fogleman / distinct.py
Last active December 1, 2020 05:07
Python Unique / Distinct Elements Iterator
def distinct(iterable, keyfunc=None):
seen = set()
for item in iterable:
key = item if keyfunc is None else keyfunc(item)
if key not in seen:
seen.add(key)
yield item
if __name__ == '__main__':
x = [0, 0, 1, 0, 1, 2, 2, 1, 0]
@fogleman
fogleman / allrgb.py
Last active August 29, 2015 13:57
AllRGB Generator
from itertools import izip, product
import wx
BITS = 6
SIZE = int(((2 ** BITS) ** 3) ** 0.5)
STEP = 2 ** (8 - BITS)
def color_func(color):
r, g, b = color
r, g, b = 0.30 * r, 0.59 * g, 0.11 * b
@fogleman
fogleman / main.py
Last active August 29, 2015 13:57
wxPython Bitmap Viewer
import wx
class View(wx.Panel):
def __init__(self, parent):
super(View, self).__init__(parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.EVT_PAINT, self.on_paint)
self.Bind(wx.EVT_CHAR_HOOK, self.on_char)
self.bitmap = None
@fogleman
fogleman / allrgb.py
Last active August 29, 2015 13:57
4096x4096 AllRGB using Octree
import random
import wx
SIZE = 4096
LOOKUP = [
[0, 1, 4, 5, 2, 3, 6, 7],
[1, 0, 5, 4, 3, 2, 7, 6],
[2, 3, 6, 7, 0, 1, 4, 5],
[3, 2, 7, 6, 1, 0, 5, 4],
@fogleman
fogleman / magick.md
Last active March 17, 2017 00:31
ImageMagick: Frequently Used

Create Animated GIF

convert -delay 20 -loop 0 *.png output.gif

Concatenate Images Vertically

montage *.png -mode concatenate -tile 1x output.png

Convert to RGB Bitmap

@fogleman
fogleman / lindenmayer.py
Last active August 29, 2015 14:02
L-system
from math import sin, cos, radians
import cairo
import random
import re
class System(object):
def __init__(self, rules):
self.rules = rules
self.pattern = re.compile('|'.join('(%s)' % x for x in rules))
def step(self, value):