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
#!/bin/sh
#
# indico-scheduler init file for starting up the indico scheduler
#
# chkconfig: - 20 80
# description: Starts and stops the zodb daemon.
### BEGIN INIT INFO
# Provides: indico-scheduler
# Required-Start: $local_fs $network
#!/bin/bash
# tmux-smartsplit
# open a new tmux (split-)window which will automatically
# continue the existing ssh session if one exists
SIP=$(tmux display-message -p "#S:#I:#P")
PTY=$(tmux server-info |
egrep flags=\|bytes |
awk '/windows/ { s = $2 }
/references/ { i = $1 }
{%- macro form_field_label(field, label_for=true) -%}
<label{% if label_for %} for="{{ field.id }}"{% endif %}>{{ field.label.text }}
{%- if field.flags.required -%}
<span class="ym-required" title="Dieses Feld muss ausgefüllt werden.">*</span>
{%- endif %}</label>
{% endmacro %}
{%- macro form_field_errors(field) -%}
{% if field.errors %}
<strong class="ym-message">
class EnsureUnicodeExtension(Extension):
"""Ensures all strings in Jinja are unicode"""
@staticmethod
def ensure_unicode(s):
"""Converts a bytestring to unicode. Must be registered as a filter!"""
if isinstance(s, str):
return s.decode('utf-8')
return s
class UsedIf(object):
"""
Make a WTF field "used" if a given condition evaluates to True.
If the field is not used, validation stops.
"""
def __init__(self, condition):
self.condition = condition
def __call__(self, form, field):
if self.condition in (True, False):

Keybase proof

I hereby claim:

  • I am thiefmaster on github.
  • I am thiefmaster (https://keybase.io/thiefmaster) on keybase.
  • I have a public key whose fingerprint is 6ED8 EE76 5B86 4EB7 5068 25F8 B071 CD13 184D 719C

To claim this, I am signing this object:

@ThiefMaster
ThiefMaster / wtforms-locale-fields.py
Last active August 29, 2015 14:00
Utility to use MongoKit i18n fields with WTForms
class _UnboundLocalizedField(UnboundField):
def __init__(self, field, locale):
super(_UnboundLocalizedField, self).__init__(field.field_class, *deepcopy(field.args), **deepcopy(field.kwargs))
self.locale = locale
# Make the field optional if it's not the default locale
if locale != current_app.config['BABEL_DEFAULT_LOCALE']:
# Validators can be set via positional or keyword argument
if len(self.args) > 1:
self.args[1][:] = [x for x in self.args[1] if not isinstance(x, DataRequired)]
elif 'validators' in self.kwargs:
@ThiefMaster
ThiefMaster / evalex.py
Created May 8, 2014 16:40
You can pass an instance of this class to the `evalex` argument of `DebuggedApplication` to conditionally enable it. Feel free to use it under the WTFPL.
class RestrictedEvalex(object):
def __init__(self, whitelist=None):
self.whitelist = whitelist
def __nonzero__(self):
if not self.whitelist:
return False
elif self.whitelist is True:
return True
>>> class Foo(object):
... def bar(self, blah):
... print self, blah
...
>>> Foo.bar
<unbound method Foo.bar>
>>> Foo.bar(None, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method bar() must be called with Foo instance as first argument (got NoneType instance instead)
def _index(self, name, tablename, columns, schema=None, **kw):
t = sa_schema.Table(tablename or 'no_table', sa_schema.MetaData(),
*[sa_schema.Column(n, NULLTYPE) for n in columns],
schema=schema
)
return sa_schema.Index(name, *[t.c[n] for n in columns], **kw)