Skip to content

Instantly share code, notes, and snippets.

@avian2
avian2 / gist:1860669
Created February 18, 2012 19:02
HTTPS Everywhere for Net::Zemanta::Suggest
package Net::Zemanta::Suggest::HTTPS;
use strict;
use base qw( Net::Zemanta::Suggest );
sub suggest {
my $self = shift;
my $suggestions = $self->SUPER::suggest(@_);
cmdline = ['rsync', '--delete', '-az', src_path, dst_path]
self.log.debug("rsync from %r to %r: %r" % (src_path, dst_path, cmdline))
self.subprocess.check_call(cmdline)
@avian2
avian2 / gist:666a01cc92a8f5512001
Last active August 29, 2015 14:00
Nicer limit display for Munin graphs
Index: munin-2.0.6/master/lib/Munin/Master/GraphOld.pm
===================================================================
--- munin-2.0.6.orig/master/lib/Munin/Master/GraphOld.pm 2014-05-04 00:39:12.000000000 +0200
+++ munin-2.0.6/master/lib/Munin/Master/GraphOld.pm 2014-05-04 00:42:49.620605473 +0200
@@ -1161,7 +1161,8 @@
. "#" . (
$single_value
? "ff0000"
- : $COLOUR[($field_count - 1) % @COLOUR]));
+ : $COLOUR[($field_count - 1) % @COLOUR])
# vim:ts=4 sw=4 expandtab softtabstop=4
import json
import jsonschema
def main():
record = json.load(open("blank-ocds.json"))
schema = json.load(open("../standard/standard/schema/record-schema.json"))
jsonschema.validate(record, schema)
main()
py32-latest create: /home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest
py32-latest installdeps: jsonschema
ERROR: invocation failed, logfile: /home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/log/py32-latest-1.log
ERROR: actionid=py32-latest
msg=getenv
cmdargs=[local('/home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/bin/pip'), 'install', 'jsonschema']
env={'PYTHONIOENCODING': 'utf_8', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'WINDOWPATH': '7', 'LOGNAME': 'avian', 'USER': 'avian', 'GNOME_KEYRING_CONTROL': '/home/avian/.cache/keyring-im0pyK', 'LC_PAPER': 'sl_SI.UTF-8', 'PATH': '/home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/bin:/home/avian/src/depot_tools:/home/avian/local/eagle-5.11.0/bin:/home/avian/local/bin:/home/avian/syn/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin', 'DISPLAY': ':0', 'SSH_AGENT_PID': '12184', 'LANG': 'en_US.utf8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': '4aaab8b188ece36029e4747a00000014-1407223324.605827-1316331910',
@avian2
avian2 / gist:0635215fb6a664690444
Created February 20, 2015 08:48
Spectrum Wars proposed interface
class Player:
"""Base class for the algorithm controlling a receiver and/or transmitter.
Users should derive their own classes from this one and override
methods as necessary.
class MyPlayer(Player):
...
The system creates two instances: one controlling the receiver and one
# pizza.py
class DoughFactory(object):
def get_dough(self):
return 'insecticide treated wheat dough'
class Pizza(DoughFactory):
def order_pizza(self, *toppings):
### Hettinger's way
# robot.py
class Robot(object):
def move(self):
print('Movement')
class CleaningRobot(Robot):
def clean(self):
import traceback
import re
def debug_var(a):
s = traceback.extract_stack(limit=2)[0][3]
g = re.match("\w+\((\w+)\)", s)
print("%s = %r" % (g.group(1), a))
def main():
foo=1
@avian2
avian2 / ocsp_age_
Created December 15, 2016 12:49
Munin plugin for monitoring age of stapled OCSP responses.
#!/usr/bin/python
import re
import subprocess
import sys
import time
import datetime
def parse_date(date):
dt = datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y GMT")