Skip to content

Instantly share code, notes, and snippets.

View mikeyk's full-sized avatar

Mike Krieger mikeyk

  • San Francisco, CA
View GitHub Profile
@mikeyk
mikeyk / omnifocus.py
Created March 19, 2016 21:41
Amazon Echo>OmniFocus email
from __future__ import print_function
import json
import boto3
ses_client = boto3.client('ses')
TARGET = "mike"
@mikeyk
mikeyk / watch_wal-e.py
Created January 16, 2013 20:24
Watch_wal-e script
#! /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 / watch_wal-e.py
Created July 26, 2012 00:43
Watch WAL-E
#! /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:
@mikeyk
mikeyk / create_status_alarm.py
Created July 25, 2012 18:31
Create a StatusCheckFailed alarm
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):
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')
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')
""" 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"])
#! /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()
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@mikeyk
mikeyk / (deprecated)UINotificationKeyboardHeight.m
Created September 8, 2011 23:31
Get keyboard height from an NSNotification
@implementation NSNotification (KeyboardHeight)
- (CGFloat)keyboardHeight {
CGRect bounds;
NSValue *boundsValue = [self.userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
if (boundsValue) {
[boundsValue getValue:&bounds];
return bounds.size.height;
} else {
return 0;