Skip to content

Instantly share code, notes, and snippets.

View ekohl's full-sized avatar

Ewoud Kohl van Wijngaarden ekohl

View GitHub Profile
# http://www.matusiak.eu/numerodix/blog/index.php/2010/03/08/python-patterns-for-graph-traversal/
# Shows that python function parameter defaults can in fact change.
# A short example:
def a(x=[]):
x += 'b'
print x
print a.func_defaults
# ([],)
#!/bin/sh
BASE="$HOME/videos"
get_show() {
sed 's/\(.\+\)\.[Ss][0-9]\+[Ee][0-9]\+.\+/\1/' | tr [A-Z] [a-z]
}
get_season() {
sed 's/.\+\.[Ss]\([0-9]\+\)[Ee][0-9]\+.\+/\1/'
#!/usr/bin/python
from BeautifulSoup import BeautifulSoup
import portage
import urllib2
url = 'http://www.gentoo.org/proj/en/qa/treecleaners/maintainer-needed.xml'
# Build a to remove set
f = urllib2.urlopen(url)
soup = BeautifulSoup(f.read())
pullify() {
REMOTE=${1:-origin}
REMOTES=$(
echo "+refs/pull/*/head:refs/remotes/${REMOTE}/pr/*" ;
git config --get-all remote.${REMOTE}.fetch | grep -v "refs/remotes/${REMOTE}/pr/\*\$"
)
git config --unset-all remote.${REMOTE}.fetch
echo "$REMOTES" | while read LINE ; do
git config --add remote.${REMOTE}.fetch "$LINE"
done
@ekohl
ekohl / demo.py
Created September 18, 2010 09:14
#!/usr/bin/python
def even(list):
"""
Returns all even numbers in the given list
>>> even(range(10))
[0, 2, 4, 6, 8]
"""
return filter(lambda x: x%2==0, list)
class PowerShellVmsResource {
enum Method { GET, ADD };
enum Detail {
DISKS("$_.getmemorystatistics(); $_.getcpustatistics(); "),
STATISTICS("$_.getdiskimages(); ");
public final String powershell;
@ekohl
ekohl / libvirt2ganeti.py
Created February 22, 2011 11:17
Initial stab at libvirt to ganeti
import libvirt
from lxml import etree
sort_disks = lambda d: next(d.iter("target")).get("dev")
def main(host, opts):
#Connect to some hypervisor.
conn=libvirt.open("qemu:///system")
#Iterate through all available domains.
@ekohl
ekohl / sdN_hook.py
Created August 17, 2011 17:40
RHEV 3 block device passthrough
#!/usr/bin/python
import os
import hooking
domxml = hooking.read_domxml()
devs = domxml.getElementsByTagName('devices')[0]
for passthrough in os.environ.get('passthrough', '').split(';'):
@ekohl
ekohl / domainsort.py
Created September 2, 2011 10:47
Sort domain names by their extension
#!/usr/bin/env python
import sys
domains = sys.stdin.read().split()
domains = sorted(list(reversed(domain.split("."))) for domain in domains)
domains = [ ".".join(reversed(domain)) for domain in domains ]
print "\n".join(domains)
@ekohl
ekohl / phonelog.py
Created September 29, 2011 11:12
Phone logging daemon
#!/usr/bin/env python
from optparse import OptionParser
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import sessionmaker
from textwrap import dedent
from threading import Thread
import socket
import datetime
import logging