Skip to content

Instantly share code, notes, and snippets.

@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
@1328
1328 / p.py
Created February 20, 2015 16:35
parser
import time
import datetime
import os
import csv
import re
import logging
from pprint import pprint
from collections import namedtuple, defaultdict
@1328
1328 / f.py
Created February 17, 2015 20:09
fifties
import unittest
import json
import time
from pprint import pprint
from collections import defaultdict, namedtuple
from itertools import product
import numpy as np
@1328
1328 / a.py
Created February 17, 2015 18:06
adv
# comments added, but not tested, so there are probably typos and other things
# that need to be worked out
import sqlite3
# consider using json for this sort of thing. sqlite3 is terrific for random
# selects, but if you are going to be loading it all up anyway, no reason not to
# have the easier editing of json
quit_game = False
@1328
1328 / x.py
Created February 6, 2015 14:48
cards.py
from random import shuffle
from collections import namedtuple
Card = namedtuple('Card',['value','suit'])
test = Card(5,'spades')
print('look how namedtuples make things easier: {}'.format(test))
print('now that test is a card we can access its attributes cleanly: {} of {}'.
format(test.value, test.suit))
@1328
1328 / tic_toe_tac.py
Created January 5, 2015 23:14
tic_tac_toe
import random
import collections
import logging
from pprint import pprint
SAVEFILE = 't1'
class Board(object):
template = '''
@1328
1328 / x.py
Created November 16, 2014 17:36
days
class Date:
def __init__(self, new_month, new_day, new_year):
"""The constructor for objects of type Date."""
self.month = new_month
self.day = new_day
self.year = new_year
def __str__(self):
@1328
1328 / x.py
Created November 16, 2014 01:38
comments
from jira.client import JIRA
from datetime import datetime, date, timedelta
from BusinessHours import BusinessHours
import sys
global jira
global jiraURL
global jiraUser
global jiraPass
@1328
1328 / kmer.py
Created November 16, 2014 01:11
kmer 11-15
from __future__ import print_function
from collections import defaultdict
#from statistics import median
import time
def median(iterable):
return sorted(iterable)[len(iterable)//2]
@1328
1328 / kmer.py
Created November 11, 2014 04:37
11-10
from __future__ import print_function
from collections import defaultdict, deque
from pprint import pprint
class Edge(object):
'''
Edge class, used to keep track of links between nodes.
two adjacent noes chare a single Edge instance, that describes their
relationship