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
mikeyk / redis_session_backend.py
Created Apr 8, 2011
A redis backend for Django Sessions, tested on Django 1.3+
View redis_session_backend.py
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
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'])
View parse_vmtouch.py
#! /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')
time.sleep(30)
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
mikeyk / watch_wal-e.py
Created Jan 16, 2013
Watch_wal-e script
View watch_wal-e.py
#! /usr/bin/env python
from boto.ses.connection import SESConnection
import os
import sys
import subprocess
import socket
TMPFILE = '/var/run/postgresql/last-wal-archive-error-file.tmp'
if __name__ == '__main__':
@mikeyk
mikeyk / create_status_alarm.py
Created Jul 25, 2012
Create a StatusCheckFailed alarm
View create_status_alarm.py
import boto.ec2.cloudwatch
import sys
import os
AWS_KEY = os.environ.get("AWS_ACCESS_KEY_ID")
AWS_SECRET = os.environ.get("AWS_SECRET_ACCESS_KEY")
AWS_REGION = os.environ.get("AWS_EC2_REGION", "us-east-1")
TOPIC = 'YOUR_TOPIC'
def create_status_alarm(instance_id):
@mikeyk
mikeyk / reconnect.diff
Created Jun 30, 2011
Automatically retry on AutoReconnect exception in pymongo
View reconnect.diff
diff --git a/pymongo/connection.py b/pymongo/connection.py
index b444f50..7635c78 100644
--- a/pymongo/connection.py
+++ b/pymongo/connection.py
@@ -46,6 +46,7 @@ from pymongo import (database,
helpers,
message)
from pymongo.cursor_manager import CursorManager
+from pymongo.decorators import reconnect
from pymongo.errors import (AutoReconnect,
@mikeyk
mikeyk / omnifocus.py
Created Mar 19, 2016
Amazon Echo>OmniFocus email
View omnifocus.py
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 0.0.0.0:8080 test_mc:app
or
gunicorn -k sync -b 0.0.0.0:8080 test_mc:app
"""
import memcache as memcache
# toggle to try pylibmc instead
# import pylibmc as memcache
client = memcache.Client(["127.0.0.1:11222", "127.0.0.1:11223"])
View watch_wal-e.py
#! /usr/bin/env python
from boto.ses.connection import SESConnection
import sys
import subprocess
import socket
if __name__ == '__main__':
return_code = 'unknown'
host = socket.getfqdn()
try:
You can’t perform that action at this time.