Skip to content

Instantly share code, notes, and snippets.

What's happening

Armin Ronacher mitsuhiko

What's happening
View GitHub Profile
mitsuhiko /
Created Mar 19, 2012
flask-script with wtforms
import sys
from werkzeug.datastructures import ImmutableDict, MultiDict
from flask import request
from flaskext.script import Manager
from postfixmgmt import app, db, __version__
from postfixmgmt.forms import DomainAddForm
manager = Manager(app)
mitsuhiko / gist:2594843
Created May 4, 2012
In-Band Signalling WTF
View gist:2594843
# This does nothing
collection.find_and_modify({'_id': 'deadbeef'}, {$set: {}})
# This clears a document
collection.find_and_modify({'_id': 'deadbeef'}, {})
mitsuhiko / gist:2594874
Created May 4, 2012
This destroys data :-(
View gist:2594874
class Model(object):
def save(self, ops=None):
ops = dict(ops or ())
for column in self.modified_columns:
ops.setdefault('$set', {})[column] =[column]
rv = self.collection.find_and_modify({'_id':}, ops)
View gist:2628247
from flask import _request_ctx_stack
app.jinja_env.globals['get_subdomain'] = lambda:
View gist:2643644
import threading
import greenlet
while 1:
t = threading.Thread(target=greenlet.getcurrent)
View gist:2693484
def proxy_fix(application):
def new_application(environ, start_response):
environ['wsgi.url_scheme'] = 'https'
return application(environ, start_response)
return new_application
app.wsgi_app = proxy_fix(app.wsgi_app)
View gist:2762307
upstream fireteam-frontend-upstream {
server 1;
server 9;
server 2;
server .;
server 1;
server 6;
server 8;
server .;
server 3;
import zmq
import time
ctx = zmq.Context()
socket = ctx.socket(zmq.REQ)
print 'Sending auth information'
print 'Response:', socket.recv()
$ python
>>> group_list(www2)
>>> jot_list(www2, aha, None)
>>> jot_list(www2, aha, blah)
View _error_
Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
File "/home/max/.virtualenvs/flask/lib/python2.7/site-packages/werkzeug/", line 513, in next
return self._next()
File "/home/max/.virtualenvs/flask/lib/python2.7/site-packages/werkzeug/", line 829, in iter_encoded
for item in self.response:
File "/home/max/.virtualenvs/flask/lib/python2.7/site-packages/jinja2/", line 918, in generate
yield self.environment.handle_exception(exc_info, True)
File "/home/max/Projekte/flask-testing-stuff/templates/index.html", line 1, in top-level template code
{% extends "layout.html" %}