Skip to content

Instantly share code, notes, and snippets.

Avatar
🖥️
What's happening

Armin Ronacher mitsuhiko

🖥️
What's happening
View GitHub Profile
@mitsuhiko
mitsuhiko / flask-script-wtforms.py
Created Mar 19, 2012
flask-script with wtforms
View flask-script-wtforms.py
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
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
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] = self.data[column]
rv = self.collection.find_and_modify({'_id': self.id}, ops)
self.data.update(rv)
View gist:2628247
from flask import _request_ctx_stack
app.jinja_env.globals['get_subdomain'] = lambda: _request_ctx_stack.top.url_adapter.subdomain
View gist:2643644
import threading
import greenlet
while 1:
t = threading.Thread(target=greenlet.getcurrent)
t.start()
t.join()
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;
View client.py
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()
View routetest.py
$ python routetest.py
/
>>> group_list(www2)
/aha
>>> jot_list(www2, aha, None)
/aha:blah
>>> 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/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" %}