Skip to content

Instantly share code, notes, and snippets.

View kcsaff's full-sized avatar

Kacey Saff kcsaff

  • Boulder, CO, USA
View GitHub Profile
@kcsaff
kcsaff / threadpool.py
Last active August 29, 2015 14:13
Noisy threadpool implementation that automatically handles multiple attempts & such.
from __future__ import print_function
import queue
import threading
from contextlib import contextmanager
from collections import Counter
import time
import traceback
class Warn(object):
"""
@kcsaff
kcsaff / cache.py
Last active August 29, 2015 14:13
A simple python cache class that allows you to take care & only cache valid data.
"""
Simple caching.
This module contains a `Cache` class that allows for simple caching that is invalidated by a timeout or an
exception while the user attempts to apply the value.
"""
import sqlite3
import time
import threading
@kcsaff
kcsaff / vector.py
Created January 14, 2015 00:12
Simple Python Vector class
import operator
class Vector(object):
def __init__(self, data, typ=None, copy=True):
self._type = typ
if isinstance(data, int):
self.data = [self._type() for _ in range(data)]
elif copy:
self.data = list(data) # copy the data
else: # This is (probably) a slice or copy is unnecessary for some other reason
@kcsaff
kcsaff / dbutil.py
Last active August 29, 2015 14:13
Simple one-file solution to ease using MySQL databases from the command line.
"""
This is a short library to help connecting to a MySQL database from the command line.
You'll need MySQLdb (or its fork, mysql-client) to use this.
"""
from getpass import getpass
try:
import MySQLdb
except ImportError as e:
print(e)