Skip to content

Instantly share code, notes, and snippets.

@insom
insom / powermate-to-midi.c
Created December 24, 2010 23:17
Create an ALSA midi output which changes pitch according to the position of a Griffin Powermate.
/*
* Create an ALSA midi output which changes pitch according to the position
* of a Griffin Powermate.
*
* Copyright 2007 - Aaron Brady <bradya@gmail.com>
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
@insom
insom / check_horsebolted
Created January 19, 2011 14:33
Check if any process is running that we're not expecting.
#!/usr/bin/python
from glob import glob
import re, sys
okay_re = [re.compile(x) for x in [ r'proftpd', r'apache2', r'upload.py', r'getty', r'munin-node', r'inetd', r'init', r'check_horsebolted', r'upstart.udev', r'portmap', r'irqbalance', r'puppet', r'nrpe', r'udevd', r'sshd', r'atd', r'mdadm', r'rsync', r'fail2ban', r'exim4', r'rsyslogd', r'cron', r'ntpd', r'mcollective', r'mysqld', r'bash', r'sleep', r'sync.php', r'queue.php', r'CRON', ]]
res = ([z for z in [open(x,'r').read() for x in glob('/proc/*/cmdline')] if not [y for y in okay_re if y.search(z)] and z])
print res
@insom
insom / mc-find-hosts.py
Created January 28, 2011 23:48
A Python language clone of MCollective's ext/perl/mc-find-hosts.pl
#!/usr/bin/python
import sys
import syck as yaml
import time
from hashlib import sha1
from M2Crypto.RSA import load_pub_key, load_key
from stompy.simple import Client
# Change these.
PREFIX = 'mcollective'
@insom
insom / icinga.h
Created June 13, 2011 16:27
Icinga CGI Defines
#define HOST_SCHEDULED_DOWNTIME 1
#define HOST_NO_SCHEDULED_DOWNTIME 2
#define HOST_STATE_ACKNOWLEDGED 4
#define HOST_STATE_UNACKNOWLEDGED 8
#define HOST_CHECKS_DISABLED 16
#define HOST_CHECKS_ENABLED 32
#define HOST_EVENT_HANDLER_DISABLED 64
#define HOST_EVENT_HANDLER_ENABLED 128
#define HOST_FLAP_DETECTION_DISABLED 256
#define HOST_FLAP_DETECTION_ENABLED 512
@insom
insom / pwapp2.py
Created July 7, 2011 12:22
Consistent Password Hashing, for Developers
#!/usr/bin/python
import hashlib
import sys
def main(key, username, hostname):
m = hashlib.md5('%s%s%s' % (key, username, hostname))
h = m.hexdigest()
f8 = h[:8]
print f8
@insom
insom / cyclestatus.py
Created July 14, 2011 21:53
Cycle through a series of stdin lines, updating iChat status.
#!/usr/bin/python
# For best results: pip install appscript
__author__ = "Aaron Brady <bradya@gmail.com>"
__copyright__ = "Copyright 2011, Aaron Brady, Interactive Web Solutions Ltd."
__license__ = "MIT"
from appscript import app
from time import sleep
from sys import stdin, argv
ic = app("iChat")
lines = stdin.readlines()
@insom
insom / volume.py
Created August 18, 2011 15:38
Turn down MPD when the Avaya phone system detects a call
#!/usr/bin/python
import re
import os
import time
import mpdclient
SERVER = '192.168.1.7'
re_ = re.compile(r'''CALL: [^ ]+ State=. Cut=. Music=... Aend="([^"]+)" [^ ]+ Bend="([^"]+)" (.*) CalledNum=([^ ]+) [^ ]+ CallingNum= ?([^ ]+)''')
@insom
insom / daz.sh
Created September 12, 2011 14:12
Darren's Bash RC
# Color codes
RED='\[\033[01;31m\]'
GREEN='\[\033[01;32m\]'
YELLOW='\[\033[01;33m\]'
BLUE='\[\033[01;34m\]'
PURPLE='\[\033[01;35m\]'
CYAN='\[\033[01;36m\]'
WHITE='\[\033[01;37m\]'
NIL='\[\033[00m\]'
@insom
insom / attended-pyconuk.py
Created September 25, 2011 14:56
Tag yourself as having gone to PyConUK 2011
#!/usr/bin/python
import fluidinfo, sys
u, p = sys.argv[1:]
f = fluidinfo.login(u, p)
fluidinfo.call('POST', '/tags/' + u, dict(name='attended',
description='Things that I have been to', indexed=False))
fluidinfo.call('PUT', '/about/pyconuk 2011/' + u + '/attended', '2011-09-24')
print fluidinfo.call('GET', '/about/pyconuk 2011')
# might print something like - ({'status': '200', 'content-length': '116',
# 'content-location': 'https://fluiddb.fluidinfo.com/about/pyconuk%202011',
@insom
insom / cctable.py
Created October 23, 2011 21:44
Export Current Cost power meter readings to a file readable by collectd
#!/usr/bin/python
import os
import serial
import re
s = serial.Serial('/dev/ttyUSB0', 57600)
FILENAME = '/tmp/cctable'
TMPNAME = FILENAME + '.new'
while True:
data = s.readline().strip()
rx = re.compile(r'<tmpr>([0-9\.]+)</tmpr>.*<watts>([0-9]+)</watts>')