Skip to content

Instantly share code, notes, and snippets.

@insom
insom / powermate-to-midi.c
Created Dec 24, 2010
Create an ALSA midi output which changes pitch according to the position of a Griffin Powermate.
View powermate-to-midi.c
/*
* 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 Jan 19, 2011
Check if any process is running that we're not expecting.
View check_horsebolted
#!/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 Jan 28, 2011
A Python language clone of MCollective's ext/perl/mc-find-hosts.pl
View mc-find-hosts.py
#!/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 Jun 13, 2011
Icinga CGI Defines
View icinga.h
#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 Jul 7, 2011
Consistent Password Hashing, for Developers
View pwapp2.py
#!/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 Jul 14, 2011
Cycle through a series of stdin lines, updating iChat status.
View cyclestatus.py
#!/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 Aug 18, 2011
Turn down MPD when the Avaya phone system detects a call
View volume.py
#!/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 Sep 12, 2011
Darren's Bash RC
View daz.sh
# 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 Sep 25, 2011
Tag yourself as having gone to PyConUK 2011
View attended-pyconuk.py
#!/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 Oct 23, 2011
Export Current Cost power meter readings to a file readable by collectd
View cctable.py
#!/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>')