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
"Memcached cache backend with key prefixing"
from django.core.cache.backends.base import InvalidCacheBackendError
from django.core.cache.backends.memcached import CacheClass as MemcachedCacheClass
from django.utils.encoding import smart_unicode, smart_str
class CacheClass(MemcachedCacheClass):
def __init__(self, server, params):
try:
self._key_prefix = smart_str(params['key_prefix'])
@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])
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
#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).
*
def http_head(url):
import httplib
import urlparse
redirects = 0
while redirects < 10:
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
if scheme == 'https':
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
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'
property FLUSH_TEXT : "Quit and flush"
property SET_TEXT : "Set speed"
-- be damn carefull what you input here, it will run as root
on ipfwLimit(bandwidth)
my ipfwFlush()
do shell script "ipfw pipe 1 config bw " & bandwidth & "KB" with administrator privileges
do shell script "ipfw add 10 pipe 1 tcp from any 80 to me" with administrator privileges
do shell script "ipfw add 11 pipe 1 tcp from me to any 80" with administrator privileges
@madssj
madssj / gist:5849359
Created June 24, 2013 11:21
getsentry.com sending includeSubdomains header.
$ curl -si https://getsentry.com/welcome/ |grep includeSubdomains
Strict-Transport-Security: max-age=2592000; includeSubdomains
@madssj
madssj / dltr.py
Created July 1, 2013 12:48
Fast deletion of S3 bucket contents.
import sys
import boto
buckets = sys.argv[1:]
if "," in buckets:
buckets = buckets.split(",")
buckets = [bucket.strip() for bucket in buckets]
if not buckets:
sys.stderr.write("Usage: {0} <bucket> [[bucket] ...]\n".format(sys.argv[0]))