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
@ThiefMaster
ThiefMaster / python.post-checkout.sh
Last active August 29, 2015 14:06
post-checkout githook which cleans up all pyc/pyc/__pycache__ files/folders. to enable, save as post-checkout in .git/hooks and chmod +x
#!/bin/bash
prev_head=$1
new_head=$2
checkout_type=$3
[[ $checkout_type == '1' ]] || exit 0
[[ $prev_head == $new_head ]] && exit 0
cd "./$(git rev-parse --show-cdup)"
from indico.util.console import cformat
colors = {
'fk': 'yellow!',
'pk': 'red!',
'ix': 'green!',
'ck': 'cyan!',
'uq': 'blue!'
}
def print_stuff(table):
t = db.Model.metadata.tables[table]
@ThiefMaster
ThiefMaster / bash-to-zsh.py
Created March 19, 2015 21:50
simple script that converts a non-timestamped bash history to an extended zsh history
from __future__ import print_function
import sys
from time import time
def main():
ts = int(time())
for line in sys.stdin:
print(': {0}:0;{1}'.format(ts, line.rstrip()))
CREATE TEMP TABLE orphaned_note_ids ON COMMIT DROP AS
(SELECT id FROM events.notes x WHERE x.event_id IS NOT NULL and NOT EXISTS
(SELECT 1 FROM events.events WHERE id = x.event_id));
UPDATE events.notes SET current_revision_id = NULL WHERE id IN (SELECT id FROM orphaned_note_ids);
DELETE FROM events.note_revisions WHERE note_id IN (SELECT id FROM orphaned_note_ids);
DELETE FROM events.notes WHERE id IN (SELECT id FROM orphaned_note_ids);
{
"suc": true,
"data": {
"cityView": {
"name": "Metropolis",
"money": 673511,
"stone": 750,
"stone_capacity_percent": 75,
"food": 735,
"food_capacity_percent": 73,
@ThiefMaster
ThiefMaster / vrecur-fix.py
Created May 18, 2011 14:50
monkey patch to make vRecur generate an apple iCal comaptible rrule string
class vRecur(icalendar.vRecur):
"""Fix vRecur so the frequency comes first"""
def ical(self):
# SequenceTypes
result = ['FREQ=%s' % self.types['FREQ'](self['FREQ']).ical()]
for key, vals in self.items():
if key == 'FREQ':
continue
typ = self.types[key]
if not type(vals) in icalendar.prop.SequenceTypes:
@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
@ThiefMaster
ThiefMaster / autoreviewcomments.user.js
Created March 26, 2012 08:30 — forked from Benjol/autoreviewcomments.user.js
Add pro-forma comments dialog for reviewing (pre-flag)
// ==UserScript==
// @name AutoReviewComments
// @namespace benjol
// @version 1.2.0
// @description Add pro-forma comments dialog for reviewing (pre-flag)
// @include http://*stackoverflow.com/questions*
// @include http://*stackoverflow.com/review*
// @include http://*stackoverflow.com/admin/dashboard*
// @include http://*serverfault.com/questions*
// @include http://*serverfault.com/review*
@ThiefMaster
ThiefMaster / structs.py
Created July 25, 2012 19:42
CommandStorage object
class CommandStorage(object):
"""Stores multi-part commands.
Performs fast lookups returning the command and any arguments which were
not part of the command.
>>> cs = CommandStorage()
>>> cs
<CommandStorage([])>
>>> cs['playlist off'] = 'func_playlist_off'
@ThiefMaster
ThiefMaster / privileges.py
Created August 30, 2012 23:06
Privilege system with nested privilege groups and inheritance
# vim: fileencoding=utf8
"""Privilege system.
Stores boolean privileges which can be put in nested groups.
By default all privileges "bubble", i.e. they enable all (bubbling) parent
groups. When a group is set in a privilege set all children are set to the
same state. Basically a group is considered active when it has at least one
bubbling privilege/group that is active.