Skip to content

Instantly share code, notes, and snippets.

View storborg's full-sized avatar

Scott Torborg storborg

View GitHub Profile
from sqlalchemy import MetaData, Column, ForeignKey, types, create_engine, orm
from sqlalchemy.ext.declarative import declarative_base, declared_attr
engine = create_engine('sqlite://')
sm = orm.sessionmaker(bind=engine)
metadata = MetaData()
metadata.bind = engine
Base = declarative_base(metadata=metadata)
$ python polymorphic_trick.py
2011-01-26 17:28:06,918 INFO sqlalchemy.engine.base.Engine.0x...5a90 PRAGMA table_info("employees")
2011-01-26 17:28:06,918 INFO sqlalchemy.engine.base.Engine.0x...5a90 ()
2011-01-26 17:28:06,919 INFO sqlalchemy.engine.base.Engine.0x...5a90 PRAGMA table_info("developers")
2011-01-26 17:28:06,919 INFO sqlalchemy.engine.base.Engine.0x...5a90 ()
2011-01-26 17:28:06,919 INFO sqlalchemy.engine.base.Engine.0x...5a90
CREATE TABLE employees (
id INTEGER NOT NULL,
name VARCHAR(50),
discriminator VARCHAR(50),
"""
Baidu is the shit. They made a super-awesome SimCity style map. To see it, go
to http://maps.baidu.com and zoom in on Beijing, then click the alternate modal
button in the top center of the maps area.
Once you're down marveling in the awesomeness you will surely be inspired to
make a giant wall-sized mural with the tiles.
Use this.
"""
from sqlalchemy import MetaData, Column
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import create_session, composite
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.mutable import MutableComposite
metadata = MetaData('sqlite://')
Base = declarative_base(metadata=metadata)
"""
Poor man's firehose: use your friends to grab twitter data, bypassing the IP
rate limit by using a bunch of different clients. This works by serving up
javascript which will make the client grab a JSONP feed from twitter and then
re-submit it to your server.
Obviously, modify this to be more useful, e.g. by setting the page to
auto-refresh itself or use long polling to get more URLs to fetch.
Call this like:
@storborg
storborg / datepicker-configuration.js
Created February 9, 2012 19:18
Reconfigure the bootstrap datepicker to use a different date format globally.
(function() {
/* Update date_input plugin so that MM/DD/YYYY format is used. */
$.extend($.fn.datepicker.defaults, {
parse: function (string) {
var matches;
if ((matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/))) {
return new Date(matches[3], matches[1] - 1, matches[2]);
} else {
return null;
}
@storborg
storborg / sharecounts.py
Created February 27, 2012 18:08
getting social media counts for urls
import simplejson as json
from urllib import urlencode
import requests
import re
def facebook_likes_for_url(url):
r = requests.get('http://graph.facebook.com/%s' % url)
obj = json.loads(r.content)
return obj['likes']
#include <pthread.h>
#include <stdio.h>
#define NUM_WAITING_THREADS 20
#define NUM_WORKING_THREADS 20
pthread_mutex_t quux;
void waste_some_time(int cycles) {
" Python indent file
" Language: Python
" Maintainer: Eric Mc Sween <em@tomcom.de>
" Original Author: David Bustos <bustos@caltech.edu>
" Last Change: 2012 Aug 15
"
" Updated 2012 Aug 15 by Scott Torborg <storborg@gmail.com>
" - Adds support for more esoteric PEP8 indentation conditions, particularly
" E125 and E127.
>>> from mako.template import Template
>>>
>>> templ = Template('''
... % for el in els:
... <p>${el}</p>
... % else:
... <p>No elements.</p>
... % endfor
... ''')
>>>