This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# START_TIME is an instance of datetime.time() | |
datetime.combine(datetime.today(), START_TIME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import nose | |
from nose.plugins.base import Plugin | |
class NoseTimer(Plugin): | |
""" | |
Times each individual test and outputs them in reverse order of | |
speed (highest first) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pycon talk selection irc bot. | |
var irc = require('../../node-irc/lib/irc.js'); | |
var sys = require('sys'); | |
var imb0t = function () { | |
return { | |
pattern_list: [], | |
client: undefined, | |
position: -1, // starts at -1 so we can increment it on the first ,next to make it 0, which properly indexes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"tour/tree" | |
"fmt" | |
) | |
func Walk(tree *tree.Tree, ch chan int) { | |
if tree != nil { | |
Walk(tree.Left, ch) |