Skip to content

Instantly share code, notes, and snippets.

View justinabrahms's full-sized avatar

Justin Abrahms justinabrahms

View GitHub Profile
# Packages required to get emacs to compile will all optional stuff. (all yes's on ./configure)
sudo apt-get install libjpeg62-dev libtiff4-dev libgif-dev libgtk2.0-dev libxpm-dev libpng12-dev xaw3dg-dev librsvg2-dev libgconf2-dev libgpm-dev libdbus-1-dev libotf-dev libm17n-dev libncurses5-dev
class TestActiveField(object):
models_to_test = ['Model1', 'Model2', 'foo']
def test_valid_choice(self):
for model in self.models_to_test:
yield self.check_valid_choice_for_active_field, model
def check_valid_choice_for_active_field(self, model):
# implement test logic here
require.paths.unshift(__dirname + '/../lib');
var sys = require('sys');
var irc = require('irc');
var http = require('http');
var fs = require('fs');
var bot = new irc.Client('irc.freenode.net', 'iShouldChangeBotName', {
channels: ['#node.js']
});
from flask import Module, request, redirect, url_for, render_template, abort
from formalchemy import FieldSet
from example import db
from example import Service, User, Forum, Category, Topic, Post
mod = Module(__name__)
models = {
# from __future__ import with_statement # py2.5
from contextlib import contextmanager
import logging
@contextmanager
def log_execution_time(log_msg):
"""
Context manager which logs the time spent doing a
particular activity.
# START_TIME is an instance of datetime.time()
datetime.combine(datetime.today(), START_TIME)
now = datetime.today()
time_list = now.timetuple()[:3] # get year,month,day
time_list.extend([START_TIME.hour, START_TIME.minute])
start_datetime = datetime(*time_list)
from collections import defaultdict
import logging
class ErrorDict(defaultdict):
"""
Stores a list of errors per host, when initialized with a list.
>>> ed = ErrorDict()
>>> ed['google.com'].append('first')
>>> ed['google.com'].append('another error')
class TestRound(object):
def _check_rounding(self, test, expected):
assert round(test) == expected
def test_rounding(self):
for x, y in [(1, 1),
(1.9, 2)]:
yield self._check_rounding, x, y
# VERSUS
#!/usr/bin/env python2.6
#
# Simple class I used for a little while to play my D&D character when I didn't have dice. Worked okay, but I then found dice.
#
from collections import defaultdict
from random import randint
def roll(dice_type):
rolls = []
mod = 0