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'])
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]))
@madssj
madssj / gist:6103494
Created July 29, 2013 10:39
Fetches the ip address of a vagrant box's eth1.
vagrant ssh -c 'ip a s eth1 | grep "inet " | cut -d " " -f 6 | cut -d/ -f 1'
@madssj
madssj / debian_upgrade_postgresql.sh
Last active December 25, 2015 04:49
A shell script to upgrade between versions of PostgreSQL on Debian. Use at your own risk.
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: $0 <from> <to>"
exit 1
fi
from=$1
to=$2
@madssj
madssj / s3_restore.py
Last active December 26, 2015 08:08
Restores keys from Amazon Glaicer based on a given bucket and prefix. Uses multiprocessing to speed up marking keys as restored.
import sys
import boto
import multiprocessing
NUM_PROCS = 16
bucket_name = sys.argv[1]
prefix = sys.argv[2]
try:
@madssj
madssj / compressors.py
Last active August 29, 2015 13:56
Ngmin compressor mixin for django-pipeline
# edit: i put this in a project called django-pipeline-ngmin-mixin-compressor
# which you should use
from pipeline.conf import settings
from pipeline.compressors.yuglify import YuglifyCompressor
from pipeline.compressors.uglifyjs import UglifyJSCompressor
class NgminMixIn(object):
"""
# Because the package manager really should *not* be the
# judge over if you should install a package or not - I actually
# need to use sshpass because of things outside of my control.
#
# Of course I'll use a long and secure encrypted ssh key when
# possible.
#
# Sometimes this is not possible. Deal with it.
#
# Note: If you in any way can, use public/private key authentication.
@madssj
madssj / gist:142e5bcb714f9e162ae0
Created February 27, 2015 13:57
A fix for running a wordpress with a new url, setting WP_HOME and WP_SITEURL to whatever is in $_SERVER['HTTP_HOST']
/** Automaticly set the correct WP_HOME and WP_SITEURL based on HTTP_HOST */
$absolute_url = "http" . ($_SERVER['HTTPS'] ? 's' : '') . "://{$_SERVER['HTTP_HOST']}";
if ($_SERVER['HTTP_PORT'] != 80 || $_SERVER['HTTP_PORT'] != 443) {
$absolute_url .= "{$_SERVER['HTTP_PORT']}";
}
define('WP_HOME', $absolute_url);
define('WP_SITEURL', $absolute_url);