Skip to content

Instantly share code, notes, and snippets.

View madssj's full-sized avatar

Mads Sülau Valstorp Jørgensen madssj

  • San Jose, United States
View GitHub Profile
def http_head(url):
import httplib
import urlparse
redirects = 0
while redirects < 10:
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
if scheme == 'https':
#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).
*
@madssj
madssj / echoserver.py
Created June 4, 2013 08:38
A simple python echo server.
import asyncore
import asynchat
import socket
class Lobby(object):
def __init__(self):
self.clients = set()
def leave(self, client):
self.clients.remove(client)
@madssj
madssj / south_07to06.py
Last active December 18, 2015 01:29
South migration convert from 2 to 1.
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])
@madssj
madssj / gist:1319151
Created October 27, 2011 09:25
Get a random name from /usr/share/dict/propernames
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))