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
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)
>>> 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)

Nov 2018

Type Item CHF chEUR
Case [be quiet! Dark Base 700][1] 165
PSU [be quiet! Straight Power 11 650W][2] 110
Board [Asus ROG STRIX X470-F Gaming][3] 235
CPU [AMD Ryzen 7 2700X][4] 360
Cooler [Noctua NH-D15 SE-AM4][5] 100
GPU [MSI RTX 2070 Gaming Z][6] 700
>>> from indico.modules.rb.models import Photo
>>> Photo.room
AttributeError: type object 'Photo' has no attribute 'room'
>>> db.session.query(Photo)
<sqlalchemy.orm.query.Query at 0x8211490>
>>> Photo.room
<sqlalchemy.orm.attributes.InstrumentedAttribute at 0x81c8090>
@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
@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 / fuse-series.py
Last active September 29, 2015 13:49
Small FUSE filesystem that maps TV series into subfolders so e.g. XBMC picks them up properly. Any file matching _EPISODE_RE will show up as a symlink in a folder named after the series. If there's a .srt file with the same name, another symlink is "created".
import logging
import os
import re
import sys
from errno import ENOENT, EINVAL
from stat import S_IFDIR, S_IFLNK
from fuse import FUSE, Operations, LoggingMixIn, FuseOSError

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:

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):
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