This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# ([],) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PowerShellVmsResource { | |
enum Method { GET, ADD }; | |
enum Detail { | |
DISKS("$_.getmemorystatistics(); $_.getcpustatistics(); "), | |
STATISTICS("$_.getdiskimages(); "); | |
public final String powershell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import hooking | |
domxml = hooking.read_domxml() | |
devs = domxml.getElementsByTagName('devices')[0] | |
for passthrough in os.environ.get('passthrough', '').split(';'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |