Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / app.py
Created January 30, 2012 15:49
Serve a Flask app on a sub-url during localhost development.
"Serve a Flask app on a sub-url during localhost development."
from flask import Flask
APPLICATION_ROOT = '/spam'
app = Flask(__name__)
app.config.from_object(__name__)
@rduplain
rduplain / client.py
Created February 24, 2012 19:41
A very simple Python HTTP client based on standard library, for testing against development servers.
import cookielib
import urllib
import urllib2
class Client(object):
def __init__(self):
self.cookie_jar = cookielib.CookieJar()
self.opener = urllib2.build_opener(
urllib2.HTTPCookieProcessor(self.cookie_jar))
@rduplain
rduplain / gist:2017517
Created March 11, 2012 18:19 — forked from ask/gist:2014539
celery consumer service using boot-steps.
from celery import abstract
from celery import current_app
from kombu import Exchange, Queue
from kombu.mixins import ConsumerMixin
# need to subclass the result backend so that it uses a topic exchange
# instead of direct, and send the results for tasks using a routing_key
# of the format:
@rduplain
rduplain / app.py
Created March 12, 2012 23:31
Use pure SQLAlchemy APIs with Flask. Integrate with Flask-SQLAlchemy.
# Using SQLAlchemy 0.7.5 and Flask-SQLAlchemy 0.15.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy, BaseQuery, _QueryProperty
from models import Base
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db'
@rduplain
rduplain / manage.py
Created March 21, 2012 14:13
Current Flask-Celery + Flask-Script integration.
from flask import Flask
from flask.ext.celery import install_commands
from flask.ext.script import Manager
app = Flask(__name__)
manager = Manager(app)
install_commands(manager)
@rduplain
rduplain / gist:2149194
Created March 21, 2012 16:19
PyCon 2012 Digest for WillowTree Apps

PyCon 2012 Digest

from DevOps team {rduplain,mattd,teebes}, to mobile developers at WillowTree Apps

Pronunciation

@rduplain
rduplain / app.py
Created March 23, 2012 19:09
Simple Flask example with sessions and redirects.
from flask import Flask, make_response, redirect, session, url_for
SECRET_KEY = 'develop'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def index():
return '<a href="%s">Go here.</a>' % url_for('do_redirect')
@rduplain
rduplain / args.py
Created March 27, 2012 14:00
Calling positional arguments by name in Python.
def spam(a, b, c=None):
return a, b, c
if __name__ == '__main__':
print "spam(b='b', a='a', c='c') =>", spam(b='b', a='a', c='c')
print "spam(b='b', a='a') =>", spam(b='b', a='a')
try:
spam(a='a', c='c')
except TypeError, e:
@rduplain
rduplain / gist:2269917
Created April 1, 2012 00:11
Simple http proxy config for nginx.
server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://127.0.0.1:8000/;
@rduplain
rduplain / app.py
Created April 10, 2012 15:58
Flask: serving static file from a separate domain
# http://flask.pocoo.org/mailinglist/archive/2012/4/10/serving-static-file-from-a-separate-domain-in-production/
from flask import Flask, url_for
# Uncomment to set server name.
# SERVER_NAME = 'mianos.com'
app = Flask(__name__, static_folder=None)
app.config.from_object(__name__)
app.add_url_rule('/<path:filename>', endpoint='static',