Skip to content

Instantly share code, notes, and snippets.

View storborg's full-sized avatar

Scott Torborg storborg

View GitHub Profile
"""
what's the fastest way to test for order-insensitive equality of two lists of
integers?
running timing tests for compare_sets:
comparing equal shuffled lists takes 1.289612
comparing equal unshuffled lists takes 1.226031
comparing unequal lists takes 0.660738
running timing tests for compare_sort:
comparing equal shuffled lists takes 2.248559
"""
query for a database obect which relates to a specific set of other objects.
"""
__author__ = 'scott torborg (scotttorborg.com)'
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
"""
a polymorphic many-to-many association with referential integrity and clean
collection access! (at least in one direction) sqlalchemy is the shit.
"""
__author__ = 'scott torborg (scotttorborg.com)'
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
"""
generalizing the polymorphic many-to-many relation example.
"""
__author__ = 'scott torborg (scotttorborg.com)'
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import _AssociationList
"""
example of (bug?) in adding deferred columns to a declarative class
after the
class's creation.
Foo is a normal declarative class with a deferred column. Bar is the
same class,
but with the deferred column added afterwards.
"""
Price comparison of favorably reviewed SSDs as of 5/31/2009
$/GB Size Cost Vendor
OCZ Summit
4.23 60GB $253.99 eCOST
4.87 60GB $292.00 Amazon
3.79 120GB $455.00 Amazon
3.48 250GB $871.00 Amazon
"""
sqlalchemy composite column example.
"""
from sqlalchemy import *
from sqlalchemy.orm import *
metadata = MetaData('sqlite://')
vertices = Table('vertices', metadata,
"""
Cute twitter bot to twitter pretty flickr photos and unicode characters.
"""
import flickr, random, urllib
from twitter import Twitter
flickr.API_KEY = 'FILL ME IN'
username = 'prettier'
"""
walk through related tags on twitter.
start it with something like python twitterwalk.py sxsw
"""
import sys, re
from twitter import Twitter
if len(sys.argv) > 1:
"""
Quick hack to return a likely User Agent based on a weighted list of strings.
Use like:
>>> import useragent
>>> useragent.pick()
"""
import random