This file contains hidden or 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
def get_random_name(): | |
""" | |
Return a random proper name in a somewhat efficient way. | |
""" | |
fp = open("/usr/share/dict/propernames") | |
fp.seek(0, 2) | |
size = fp.tell() | |
fp.seek(0) | |
fp.seek(int(random.random() * size * 0.95)) |
This file contains hidden or 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 sys | |
import re | |
create_table_re = re.compile("db.create_table('([^']+)',") | |
field_name_re = re.compile("^(s*)('([^']+)', self.gf") | |
cur_model = None | |
input = open(sys.argv[1]) |
This file contains hidden or 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 asyncore | |
import asynchat | |
import socket | |
class Lobby(object): | |
def __init__(self): | |
self.clients = set() | |
def leave(self, client): | |
self.clients.remove(client) |
This file contains hidden or 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
#include <math.h> | |
#include <stdlib.h> | |
#define NV_MAGICCONST 1.7155277699214135 /* (4 * exp(-0.5) / sqrt(2.0)); */ | |
#define MAX_RANDOM 2147483647 /* (2 ** 31) - 1; */ | |
/* | |
* normalvariate ported from python's stdlib (random.normalvariate). | |
* released under the same licence as that (python license). | |
* |
This file contains hidden or 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
def http_head(url): | |
import httplib | |
import urlparse | |
redirects = 0 | |
while redirects < 10: | |
scheme, netloc, path, query, fragment = urlparse.urlsplit(url) | |
if scheme == 'https': |
This file contains hidden or 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
def send_plain_mail(subject, body, from_mail, to): | |
import smtplib | |
from email.MIMEText import MIMEText | |
from email.Encoders import encode_quopri | |
msg = MIMEText(body, 'plain', 'iso-8859-1') | |
msg['Subject'] = subject | |
msg['From'] = from_mail | |
msg['To'] = to |
This file contains hidden or 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 os | |
import subprocess | |
import threading | |
from Queue import Queue | |
ITUNES_DIR = os.path.expanduser("~/Music/iTunes/iTunes Music/") | |
KNOWN_EXTENSIONS = ('.mp3', '.aac') | |
AACGAIN_PARAMS = ['-a', '-k', '-d', '3'] | |
AACGAIN_LOCATION = 'aacgain' |
This file contains hidden or 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
var a:XML = <request command="run-command" />; | |
var r:URLRequest = new URLRequest("http://localhost/service.php"); | |
r.data = a; | |
r.method = URLRequestMethod.POST; | |
r.contentType = "text/xml"; | |
var l:URLLoader = new URLLoader(); | |
l.addEventListener(Event.COMPLETE, function(e:Event) { | |
trace("success", l.data); |
This file contains hidden or 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 | |
if [ $# -ne 2 ] | |
then | |
echo "Usage: $0 <postgresql sql dump> <db_name>" >&2 | |
exit 1 | |
fi | |
db_file=$1 | |
db_name=$2 |
This file contains hidden or 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 os, sys, re | |
from os.path import join, getsize, exists | |
def median(numbers): | |
s = sorted(numbers) | |
l = len(numbers) | |
if l % 2 == 0: | |
a, b = s[l / 2 - 1 : l / 2 + 1] | |
if a != b: | |
return a + b / 2.0 |
OlderNewer