Skip to content

Instantly share code, notes, and snippets.

View mitsuhiko's full-sized avatar
🖥️
What's happening

Armin Ronacher mitsuhiko

🖥️
What's happening
View GitHub Profile
@mitsuhiko
mitsuhiko / flask-script-wtforms.py
Created March 19, 2012 14:54
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
mitsuhiko / gist:2594843
Created May 4, 2012 13:36
In-Band Signalling WTF
# This does nothing
collection.find_and_modify({'_id': 'deadbeef'}, {$set: {}})
# This clears a document
collection.find_and_modify({'_id': 'deadbeef'}, {})
@mitsuhiko
mitsuhiko / gist:2594874
Created May 4, 2012 13:43
This destroys data :-(
class Model(object):
...
def save(self, ops=None):
ops = dict(ops or ())
for column in self.modified_columns:
ops.setdefault('$set', {})[column] = self.data[column]
rv = self.collection.find_and_modify({'_id': self.id}, ops)
self.data.update(rv)
from flask import _request_ctx_stack
app.jinja_env.globals['get_subdomain'] = lambda: _request_ctx_stack.top.url_adapter.subdomain
import threading
import greenlet
while 1:
t = threading.Thread(target=greenlet.getcurrent)
t.start()
t.join()
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)
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)
socket.connect('tcp://127.0.0.1:5000')
print 'Sending auth information'
socket.send('auth')
print 'Response:', socket.recv()
$ python routetest.py
/
>>> group_list(www2)
/aha
>>> jot_list(www2, aha, None)
/aha:blah
>>> jot_list(www2, aha, blah)
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/wsgi.py", line 513, in next
return self._next()
File "/home/max/.virtualenvs/flask/lib/python2.7/site-packages/werkzeug/wrappers.py", line 829, in iter_encoded
for item in self.response:
File "/home/max/.virtualenvs/flask/lib/python2.7/site-packages/jinja2/environment.py", 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" %}