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
{
"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 / 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 / auth.py
Created August 21, 2012 22:10
Flask-IRC example
from flask.ext.irc import BotModule, CommandAborted
from exodus import login_required, db
auth = BotModule('Auth', __name__)
@auth.command('addhost')
def addhost(source, channel):
"""Show the URL to connect your host with your account.
This command shows you the URL to associate your hostname with an account.
@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.
@ThiefMaster
ThiefMaster / se-scroller.js
Created September 5, 2012 00:26
sticky scroller from stackexchange websites
function moveScroller() {
var width = $('#scroller').width();
var move = function () {
var st = $(window).scrollTop();
var ot = $('#scroller-anchor').offset().top;
var s = $('#scroller');
if (st > ot) {
if (s.height() > $(window).height()) {
s.css({ 'position': 'fixed', 'top': '', 'bottom': '0px', 'width': width });
@ThiefMaster
ThiefMaster / copy.c
Created September 6, 2012 11:51
copy
/* Copy a regular file from SRC_NAME to DST_NAME.
If the source file contains holes, copies holes and blocks of zeros
in the source file as holes in the destination file.
(Holes are read as zeroes by the `read' system call.)
When creating the destination, use DST_MODE & ~OMITTED_PERMISSIONS
as the third argument in the call to open, adding
OMITTED_PERMISSIONS after copying as needed.
X provides many option settings.
Return true if successful.
*NEW_DST is as in copy_internal.
@ThiefMaster
ThiefMaster / sslfix.py
Created September 7, 2012 23:29
SSL fix for flask dev server
from SocketServer import TCPServer
from OpenSSL import SSL
def patch_shutdown_request():
# Fix SocketServer's shutdown not working with pyopenssl
def my_shutdown_request(self, request):
"""Called to shutdown and close an individual request."""
try:
#explicitly shutdown. socket.close() merely releases
#the socket and waits for GC to perform the actual close.
@ThiefMaster
ThiefMaster / crap.php
Created October 17, 2012 07:28
php is even more crappy than i thought
<?php
error_reporting(E_ALL|E_STRICT);
function crap(&$var) {
echo '$var='.$var."\n";
$var = 'x';
}
crap($x = 123);
# Strict Standards: Only variables should be passed by reference in php shell code on line 1