Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from PIL import Image
import collections
colors = [
(238,203,173),
(49,79,79),
(100,149,237),
(127,255,0),
(255,255,0),
import csv
from pprint import pprint
FN = 'tmpdata.txt'
def write_csv(fn, lines = 4):
'''writes a csv with a header, total and lines lines inbetween'''
with open(fn, mode='w') as fh:
@1328
1328 / gist:9263ae8cfb4cdd342461
Created May 16, 2014 14:12
Poor mans csv readers
import re
from pprint import pprint
def option1(fn):
'''the screwy quoting break the csv module, so we just have to do it ourselves'''
data = []
with open(fn, mode='r') as fh:
for r in fh:
from pprint import pprint
def check_int(x):
'''probably want to work out how to deal with floats as well'''
'''but this is just proof of concept'''
try:
int(x)
return True, x
@1328
1328 / some file
Created June 5, 2014 16:53
Comments 6-5
import os.path
from hashlib import md5
from pprint import pprint
# spacing is a bit wacked, should be 4 spaces per tab
def get_files():
# let's make these generators
for f in os.listdir('.'):
@1328
1328 / histo match
Last active August 29, 2015 14:02
tmp
import random
import time
import collections
import itertools
import numpy as np
from pprint import pprint
from PIL import Image
@1328
1328 / dsklfj
Created June 11, 2014 21:38
turn 2
import random
import time
import collections
import itertools
import numpy as np
from pprint import pprint
from PIL import Image
@1328
1328 / comments
Created July 11, 2014 20:37
comments 7-11
import sqlite3
from collections import namedtuple
EMP = namedtuple('EMP', ['first_name','last_name','badge','hours'])
def yes_no(query):
'''
this is a simple func to as a y/n question and get back a valid y/n
response
@1328
1328 / troll comments
Created July 29, 2014 21:11
comments
"""
Trollcheckbot 1.1a is a reddit bot written by (utter novice) /u/tingmakpuk.
In theory, this bot will be summoned by a user responding to an exising comment using
a trigger phrase. The bot will report on the user who posted the parent comment:
Version 1.0: Replies with target username and comment karma.
Version 1.1: Replies with target username and comment karma. Makes a judgement.
Version 1.1a: Fixed signature and related bug
WIP -- Version 2.0 will log the work and not duplicate the effort.
@1328
1328 / comments
Created August 5, 2014 20:44
some gist
from random import randrange
class Player(object):
def __init__(self, who = 'you'):
self.score = 0
self.who = who
def choose(self):
'''let's not make choice an instance variable, since it varies on each