Skip to content

Instantly share code, notes, and snippets.

View ThiefMaster's full-sized avatar
🐈
Scratching your code.

Adrian ThiefMaster

🐈
Scratching your code.
  • CERN / @indico
  • Geneva, Switzerland
View GitHub Profile
class DebugLevelFilter(Filter):
max_debug_level = None
def __init__(self, required_level):
super(DebugLevelFilter, self).__init__()
self.required_level = required_level
def input(self, in_, out, source_path, **kw):
if self.required_level == self.env.debug:
out.write(in_.read())
class DebugLevelFilter(Filter):
max_debug_level = None
def __init__(self, required_level):
super(DebugLevelFilter, self).__init__()
self.required_level = required_level
def input(self, in_, out, **kw):
if self.required_level == self.env.debug:
out.write(in_.read())
// Templating
(function($, global) {
'use strict';
var templates = null;
function loadTemplates() {
if(!$.isReady) {
console.error('Tried loading templates before DOMReady');
console.trace();
return false;
@ThiefMaster
ThiefMaster / api-additions.py
Created May 29, 2013 09:33
Add this to indico/web/http_api/api.py - e.g. at the very end
from indico.util.fossilize import IFossil
from MaKaC.common.Announcement import getAnnoucementMgrInstance
@HTTPAPIHook.register
class RangeHook(HTTPAPIHook):
TYPES = ('num', 'char')
RE = r'(?P<start>[0-9]+|[a-z])-(?P<end>[0-9]+|[a-z])'
DEFAULT_DETAIL = 'simple'
MAX_RECORDS = {
class XAccelMiddleware(object):
"""A WSGI Middleware that converts X-Sendfile headers to X-Accel-Redirect
headers if possible.
If the path is not mapped to a URI usable for X-Sendfile we abort with an
error since it likely means there is a misconfiguration.
"""
def __init__(self, app, mapping):
self.app = app
from flask import Flask
app = Flask(__name__)
@app.route('/foo/<path:bla>/')
def foo_path(bla):
print 'foo_path', bla
@ThiefMaster
ThiefMaster / pre-commit
Last active December 18, 2015 22:58 — forked from pferreir/pre-commit
pre-commit hook to PEP8-check the code
#!/bin/sh
# vim: et ts=4 sw=4 ft=sh
# Interesting post on max line length:
# http://stackoverflow.com/questions/88942/why-should-python-pep-8-specify-a-maximum-line-length-of-79-characters
PEP8_OPTIONS='--max-line-length=120'
RED=`echo -e "\033[1;31m"`
--- /home/adrian/dev/indico/env/lib/python2.7/site-packages/pep8.py 2013-06-09 15:46:35.000000000 +0200
+++ ./lib/python2.7/site-packages/pep8.py 2013-06-25 14:57:01.522980981 +0200
@@ -1100,21 +1100,24 @@
# For each file of the diff, the entry key is the filename,
# and the value is a set of row numbers to consider.
rv = {}
- path = nrows = None
+ path = nrows = row = None
for line in diff.splitlines():
if nrows:
def undo_changes(after):
root = dbi.getInstance().getDBConnection().root()
db = root._p_jar.db()
undo_data = [obj for obj in db.undoInfo(last=-1000) if obj['time'] >= after]
for entry in undo_data:
db.undo(entry['id'])
dbi.commit()
#encoding: UTF-8
import re
from flask import Flask, jsonify, render_template, request, redirect
from flask.ext.mail import Mail, Message
app = Flask(__name__)
mail=Mail(app)
app.config.update(