Skip to content

Instantly share code, notes, and snippets.

@1328
1328 / index.py
Created April 19, 2015 02:38
test
import shelve
import time
from collections import defaultdict, deque
from functools import lru_cache
from pprint import pprint
class FastaIndex(object):
'''
@1328
1328 / x.py
Created April 15, 2015 00:01
multiprocessing shenanigans
import os
from random import random, choice
from multiprocessing import Pool
from time import sleep
from pprint import pprint
def call_api(who, other_subscribers):
@1328
1328 / b.py
Created April 12, 2015 03:28
battle
from __future__ import print_function
# that -- and it has to be at the top -- makes py2 use print like py3
import random
from random import randint
import time
from collections import namedtuple
Spell = namedtuple('Spell', ['name', 'damage_min', 'damage_max'])
@1328
1328 / x.py
Created April 12, 2015 02:37
minmax
class MinHeap():
def __init__(self, sourceCollection = None):
self._heap = list()
self._size = 0
for item in sourceCollection:
self.add(item)
def peek(self):
if self.isEmpty():
@1328
1328 / x.py
Created April 3, 2015 15:51
ex.py
import json
import logging
from collections import namedtuple
from pprint import pprint
Record = namedtuple('CustomerRecord', ['first', 'last', 'id', 'phone', 'color'])
logging.basicConfig()
@1328
1328 / x.py
Created April 3, 2015 15:43
comments
import json
import sys
def main(argv):
# show off some use of the context manager using `with`
in_file = open("data.in", 'r') #opening our input file
#in_file = open(argv[0], 'r') #input file on command line
result_file = open("result", 'w') #Opening our output file
@1328
1328 / h2,py
Created March 18, 2015 21:32
hangman
import random
from string import ascii_lowercase
# a bit of a hacky solution to change the board names to be a bit better
from boards import easy as easy_board
from boards import hard as hard_board
WORD_FILENAME = 'wordlist.txt'
@1328
1328 / evil.py
Created March 11, 2015 22:38
decorator example
import threading
import time
from collections import defaultdict
class Effect(object):
'''
class styled decorator because you need to have some way for the
effects.starter to find the effects.stopper
@1328
1328 / gol.py
Created March 5, 2015 16:15
game_of_life.py
import random
import os
import time
from pprint import pprint
BH = 40
BW = 40
ALIVE = 'X'
DEAD = '.'
@1328
1328 / x.py
Created March 4, 2015 16:46
x.py
import cmd
from pprint import pprint
class Calculator(cmd.Cmd):
def get_floats(self, line, number = None):
''' get number of floats from line
if number is None, don't worry about the number returned
if cannot float anything in the line it prints help and raises