Skip to content

Instantly share code, notes, and snippets.

Mike Krieger mikeyk

  • Instagram
  • San Francisco, CA
Block or report user

Report or block mikeyk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mikeyk /
Created Apr 8, 2011
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
mikeyk / gist:1329319
Created Oct 31, 2011
Testing storage of millions of keys in Redis
View gist:1329319
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
#! /usr/bin/env python
import fileinput
import argparse
from operator import itemgetter
parser = argparse.ArgumentParser()
parser.add_argument('--target-mb', action = 'store', dest = 'target_mb', default = 61000, type = int)
parser.add_argument('vmtouch_output_file', action = 'store', nargs = '+')
args = parser.parse_args()
View gist:2307647
def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
mikeyk /
Created Jan 16, 2013
Watch_wal-e script
#! /usr/bin/env python
from import SESConnection
import os
import sys
import subprocess
import socket
TMPFILE = '/var/run/postgresql/last-wal-archive-error-file.tmp'
if __name__ == '__main__':
mikeyk /
Created Jul 25, 2012
Create a StatusCheckFailed alarm
import boto.ec2.cloudwatch
import sys
import os
AWS_KEY = os.environ.get("AWS_ACCESS_KEY_ID")
AWS_REGION = os.environ.get("AWS_EC2_REGION", "us-east-1")
def create_status_alarm(instance_id):
mikeyk / reconnect.diff
Created Jun 30, 2011
Automatically retry on AutoReconnect exception in pymongo
View reconnect.diff
diff --git a/pymongo/ b/pymongo/
index b444f50..7635c78 100644
--- a/pymongo/
+++ b/pymongo/
@@ -46,6 +46,7 @@ from pymongo import (database,
from pymongo.cursor_manager import CursorManager
+from pymongo.decorators import reconnect
from pymongo.errors import (AutoReconnect,
mikeyk /
Created Mar 19, 2016
Amazon Echo>OmniFocus email
from __future__ import print_function
import json
import boto3
ses_client = boto3.client('ses')
TARGET = "mike"
View gist:1508150
""" Run with:
gunicorn -k gevent -b test_mc:app
gunicorn -k sync -b test_mc:app
import memcache as memcache
# toggle to try pylibmc instead
# import pylibmc as memcache
client = memcache.Client(["", ""])
#! /usr/bin/env python
from import SESConnection
import sys
import subprocess
import socket
if __name__ == '__main__':
return_code = 'unknown'
host = socket.getfqdn()
You can’t perform that action at this time.