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
from ldap import initialize, SCOPE_SUBTREE | |
from operator import add | |
config = {'host': 'ldap://HOST', 'base': 'dc=example,dc=com', 'attr': 'l'} | |
result = initialize(config['host']).search_s(config['base'], SCOPE_SUBTREE, '(%s=*)' % config['attr'], [ config['attr'] ] ) | |
data = reduce(add, [ entry[config['attr']] for (dn, entry) in result ]) | |
print "\n".join(sorted(set(map(str.lower, data)))) |
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 operator import add | |
lijst = range(50) | |
print "lijst:", lijst | |
f = lambda x: x * 2 | |
print "map:", map(f, lijst) | |
g = lambda x: x % 2 == 0 |
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 | |
""" | |
The sum of the squares of the first ten natural numbers is, | |
1^2 + 2^2 + ... + 10^2 = 385 | |
The square of the sum of the first ten natural numbers is, | |
(1 + 2 + ... + 10)^2 = 55^2 = 3025 | |
Hence the difference between the sum of the squares of the first ten natural | |
numbers and the square of the sum is 3025 - 385 = 2640. |
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 | |
if len(sys.argv) != 2: | |
print "Usage: %s fqdn" % sys.argv[0] | |
sys.exit(1) | |
fqdn = sys.argv[1] | |
split = fqdn.split(".") | |
domain = ".".join(split[-2:]) |
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 urllib2 | |
import sys | |
for site in sys.argv[1:]: | |
try: | |
s = urllib2.urlopen(site) | |
print s.url, s.code, s.msg, s.headers.get('X-Server', None) | |
except urllib2.HTTPError, e: | |
print >> sys.stderr, e.url |
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 | |
# dynzoom.py - dynamic zooming for uzbl, based on dynzoom.js | |
# Usage: | |
# @on_event GEOMETRY_CHANGED spawn /path/to/dynzoom.py \@geometry 1024 768 | |
# Where 1024x768 is the resolution where we start to zoom out | |
import sys, re | |
" Parses WxH+X+Y into a 4-tuple of ints " |
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 csv | |
import sys | |
import random | |
# For each argument to the program | |
for arg in sys.argv[1:]: | |
# Store all the data | |
rows = list(csv.DictReader(open(arg))) | |
trackers = list(set(row['Tracker'] for row in rows)) |
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()) |
OlderNewer