Skip to content

Instantly share code, notes, and snippets.

@jeamland
jeamland / gist:1231216
Created September 21, 2011 03:59
Example toxconfig.py
from tox import TestEnvironment, py27
envlist = [py27]
testenv = TestEnvironment(
commands=[
'nosetests',
],
deps=[
'SQLAlchemy',
'bottle',
@jeamland
jeamland / gist:1294394
Created October 18, 2011 01:27
SQLAlchemy declarative problem
import sqlalchemy as sa
from sqlalchemy import orm, sql
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Customer(Base):
__tablename__ = 'customer'
class LineFilter(object):
def __init__(self, lines):
self.lines = lines
def eval(self, tags, names, ranges):
for r in ranges:
for line in self.lines:
if r[0] <= line <= r[1]:
return True
return False
@jeamland
jeamland / execfiletest.py
Created November 17, 2011 23:01
Execfile failure mode
import tempfile
test_script = """
import os
def foo():
print repr(os.environ)
"""
with tempfile.NamedTemporaryFile() as tmp:
@jeamland
jeamland / mouse_event.py
Created November 30, 2011 01:45
Javascript mouse events for Selenium
def mouse_event(browser, event, element_id, x, y):
script = """
var element = document.getElementById("%(element_id)s");
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
event.initMouseEvent("%(event)s", true, true, window, 1, 0, 0, %(x)d, %(y)d, false, false, false, false, 0, null);
element.dispatchEvent(event);
} else {
var event = document.createEventObject();
No.
@jeamland
jeamland / gist:2214560
Created March 27, 2012 10:05
System of a Doom
Motherboard: Gigabyte GA-Z77MX-D3H
$145 (PCCaseGear, MSY no-show)
CPU: Intel Core i5-2500K
$212 (MSY, PCCaseGear $215)
RAM: G.Skill Ripjaws-X 8 GB (2 x 4 GB) 240-Pin DDR3-1600 Kit
$54 (MSY, PCCaseGear $55)
GPU: Sapphire Radeon HD 7870
$369 (MSY, PCCaseGear $395)
SSD: Intel 520 60GB
$113 (MSY, PCCaseGear $119)
@jeamland
jeamland / gist:2715212
Created May 17, 2012 00:38
On Learning to Code

I finished high school in the first year of a new assessment system in South Australia. This of course resulted in curriculum changes and all that kind of fun that happens around these kind of things. One of the objections parents raised was that the maths curriculum was too hard. As a child of two mathematicians I got to hear more about this as one of my parents was in the process of actually becoming involved in various aspects of the high school maths curriculum and how it was examined. One of the areas singled out as being too difficult was probability, you know calculating the chance of something happening. So the Authorities decided to remove it. What was funny to those of us who knew what was going on was that they didn't remove counting.

Counting is the process by which we work out how much of something there is. There are ways to do this mathematically, combinations and permutations and all that jazz. The joke here is that probability, at least in the way the course was structured, involved counting

line = "2012/05/18 00:01:57.350 [0.1107 0.0673] [-40434.7711 4055.2146 -48.3776] [[0.0000 -0.0000 0.0000]] [12.4549 25.2789 -4.0204] [33.9825 34.1984 23.4829] [-30128.3000 96816.4946 96816.4946] [0.0682 -84.2729] [83.4846 3.3248]"
date, time, line = line.split(' ', 2)
print date, time
bits = line.split('] [')
last_bits = bits[-1].split('] [')
bits[-1:] = last_bits
@jeamland
jeamland / gist:3311828
Created August 10, 2012 06:34
try/except/finally
>>> def foo():
... try:
... print 'one'
... raise Exception('wombats')
... print 'two'
... except:
... print 'three'
... raise
... finally:
... print 'four'