Skip to content

Instantly share code, notes, and snippets.

View jeremyBanks's full-sized avatar

Jeremy Banks jeremyBanks

  • Canada
  • 02:20 (UTC -05:00)
View GitHub Profile
@jeremyBanks
jeremyBanks / brainfuck.py
Created July 24, 2008 21:24
[2008-07] Learning Brainfuck - First Program and Python Interpreter
#!/usr/bin/env python
# encoding: utf-8
#
# Rudementary Python Brainfuck Interpreter
# [email protected]
#
# Usage: brainfuck.py program.bf
#
# Input is from stdin, output to stdout, obviously.
# The grid is infinite in both directions.
@jeremyBanks
jeremyBanks / python.bash
Created July 26, 2008 10:51
[2010-01] downloading and verifying python, noobing bash and gpg
#!/bin/bash
# Fuck this, I don't know bash.
GENERAL=2.6
SPECIFIC=2.6b2
BZFILE="Python-$SPECIFIC.tar.bz2"
BZURL="http://www.python.org/ftp/python/$GENERAL/$BZFILE"
ASCFILE="Python-$SPECIFIC.tar.bz2.asc"
@jeremyBanks
jeremyBanks / pi.py
Created July 27, 2008 06:49
Simple π calculation [2010-01] (from Pythagorean theorem)
#!/usr/bin/env python
# encoding: utf-8
from __future__ import division, with_statement
import sys
from math import sqrt, pi
def calculatePi(samples):
samples = int(samples)
@jeremyBanks
jeremyBanks / nextFib.py
Created July 31, 2008 00:12
Fibbonachi generator for the Reddit thread.
#!/usr/bin/env python
import sys
import re
def prompt():
sys.stderr.write("Preceding term: (terminate with EOF)\n")
return sys.stdin.read()
def main():
predecessor = int(re.sub("[^\+\-eE0-9]", "", "".join(sys.argv[1:]) if len(sys.argv) > 1 else prompt()) or 0)
@jeremyBanks
jeremyBanks / fibchain.py
Created July 31, 2008 00:57
[2010-01] reddit fib thread cralwer, probably broken now
#!/usr/bin/env python
# Because I was unable to find the root of the Fibbonachi sequence post
# chain in the original story comments (it was nowhere to be found!) I made
# this little hacky script to go back, post by post, until it reache a post
# with no parent. For fun, it displays the users and values as it goes.
# The value isn't always accurate, but that doesn't really matter.
# The result of this (which didn't take very long) it stopped, not very
# far back, because someone deleted a post. Huh. Irritating.
# http://www.reddit.com/comments/2mg72/vote_up_if_you_love_pie/c02bfe6
@jeremyBanks
jeremyBanks / gist:3539
Created July 31, 2008 22:57
[2010-01] I guess I liked some tech talks with LOLCATs.
After seeing LOLCATs mentioned in two Google Tech Talks, I decided I should start
making note of each time it happens. Because, you know, it's going to happen _all
of the time_, no doubt.
video.google.com/videoplay?docid=2288395847791059857#18m30s
Here's an OMG
http://video.google.com/videoplay?docid=-3733345136856180693#23m
This guy calls people sluts and bastards.
@jeremyBanks
jeremyBanks / gist:3720
Created August 2, 2008 06:21
A simple example of how the Pickle module can be used.
#!/usr/bin/env python
class Character(object):
"""Crude example."""
me = Character()
me.name = "God"
me.stats = [1, 2, 3, 4, 5]
import pickle
@jeremyBanks
jeremyBanks / properties.py
Created August 4, 2008 18:00
[2010-01] some simple examples of using properties in python, probably not idiomatic
#!/usr/bin/env python
import sys
class Example(object):
@property
def readOnlyProperty(self):
print "Getting five"
return 5
__it = 6
@jeremyBanks
jeremyBanks / generators.py
Created August 4, 2008 18:25
After reading PEP 342 [2010-01] i goofed around with simple generators, I guess
#!/usr/bin/env python
import sys
def mahgen():
v = "START"
c = 0
while 1:
v = yield (v, c)
c += 1
@jeremyBanks
jeremyBanks / session.py
Created August 5, 2008 02:25
Generating a 128-bit uppercase hex number, for use as a WEP key.
~ $ python
Python 2.5.2 Stackless 3.1b3 060516 (python-2.52:61022, Feb 27 2008, 16:52:03)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> print("%032X" % (random.getrandbits(128)))
9BC16245BF668D1637236C6422B48A54
>>>