This file contains hidden or 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 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) |
This file contains hidden or 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
| $ 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), |
This file contains hidden or 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
| """ | |
| 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. | |
| """ |
This file contains hidden or 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 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) | |
This file contains hidden or 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
| """ | |
| 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: |
This file contains hidden or 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
| (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; | |
| } |
This file contains hidden or 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
| #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) { |
This file contains hidden or 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
| " 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. |
This file contains hidden or 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 mako.template import Template | |
| >>> | |
| >>> templ = Template(''' | |
| ... % for el in els: | |
| ... <p>${el}</p> | |
| ... % else: | |
| ... <p>No elements.</p> | |
| ... % endfor | |
| ... ''') | |
| >>> |