Skip to content

Instantly share code, notes, and snippets.

@iffy
iffy / doc.py
Created September 23, 2011 16:58
minmal doctest example
import doctest
import work
suite = DocTestSuite(work)
# What goes here?
@iffy
iffy / bar.py
Created October 4, 2011 15:25
import error
from datetime import datetime, timedelta
from foo.datetime import something
@iffy
iffy / output
Created October 14, 2011 16:19
sql patcher
$ python patcher.py
-- UPDATE customer to version 1
create table customer (
id integer primary key,
);
update _schema_version set version='1' where what='customer';
-- UPDATE customer to version 2
alter table customer add column (email text);
create unique index foo on customer(email);
update _schema_version set version='2' where what='customer';
@iffy
iffy / output
Created November 1, 2011 22:31
coverage bug?
$ coverage run --branch ./thefile.py ; coverage report
Name Stmts Miss Branch BrPart Cover
-------------------------------------------
thefile 8 0 4 1 92%
@iffy
iffy / console
Created November 16, 2011 20:11
broken pipe
[matt] /tmp $ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>>
>>> f = open('dafile', 'w')
>>> f.write('import sys\n'
... 'raise Exception("hey")')
>>> f.close()
@iffy
iffy / client
Created November 30, 2011 16:14
sftp
[matt] ~ $ sftp -oPort=8022 foo@10.1.15.5:/somefile /tmp/somefile
Connecting to 10.1.15.5...
foo@10.1.15.5's password:
Fetching /somefile to /tmp/somefile
Cannot download non-regular file: /somefile
@iffy
iffy / gentoo py2.6 pg8.4.4 (production server)
Created December 21, 2011 22:50
psycopg unicodedecodeerror
Python 2.6.2 (r262:71600, Sep 14 2009, 13:43:10)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psycopg2 import connect
>>> from psycopg2.extras import DictCursor
>>> from psycopg2 import extensions
>>>
>>> # do what you need to get these:
... from sm.db import connstr
>>>
@iffy
iffy / sqlite
Created February 22, 2012 21:41
storm/sqlite3 diff
>>> import sqlite3
>>> from decimal import Decimal as D
>>>
>>>
>>> db = sqlite3.connect(':memory:')
>>>
>>> cur = db.cursor()
>>> _ = cur.execute('''create table foo (
... id integer primary key,
... val decimal(12,2) default 0.0
@iffy
iffy / index.html
Created May 7, 2012 05:49
line transition problem
<html>
<head>
<title>Chart</title>
<style>
path {
stroke: #f00;
}
.line {
stroke: #0f0;
fill: none;
@iffy
iffy / index.html
Created June 1, 2012 13:42
Introduction and the Reactor
<html>
<head>
<title>Bite-sized Twisted: Introduction and the Reactor</title>
<style>
body {
font: normal normal 16px Crimson Text;
color: #666666;
background: #ffffff none repeat scroll top left;
padding: 0 0 0 0;
}