Skip to content

Instantly share code, notes, and snippets.

@kjoconnor
kjoconnor / find_memcached_expiries.py
Created January 30, 2014 22:04
Find what percentage of memcache keys don't have expiries set
import re
import telnetlib
import time
from collections import Counter
hosts = [
('localhost', 11211)
]
@kjoconnor
kjoconnor / find_in_all_sg.py
Created February 7, 2014 00:53
Find security group grants in ElastiCache and EC2
from boto.ec2 import connect_to_region
from boto.elasticache import connect_to_region as elasticache_region
target = 'sg-name'
ec2 = connect_to_region('us-east-1')
ec = elasticache_region('us-east-1')
sgs = ec2.get_all_security_groups()
@kjoconnor
kjoconnor / check_if_sg_is_used.py
Created May 16, 2014 21:43
Find if a security group is in use anywhere
import sys
from boto.ec2 import connect_to_region
target_sg = sys.argv[1]
ec2 = connect_to_region('us-west-1')
target_sg_object = ec2.get_all_security_groups([target_sg])[0]
@kjoconnor
kjoconnor / redirect_loop.py
Created July 9, 2014 16:01
Create a redirect loop with Tornado (for testing)
import tornado.httpserver
import tornado.ioloop
import tornado.web
PORT = 10045
class Application(tornado.web.Application):
def __init__(self):
handlers = [
@kjoconnor
kjoconnor / generate_password.sh
Created February 24, 2015 23:39
Generate SHA512 passwords for /etc/shadow
#!/bin/bash
type -P chpasswd 2>&1 > /dev/null
if [ $? -ne 0 ]; then
echo "chpasswd not available"
exit 1
fi
read -p "Username: " USERNAME
@kjoconnor
kjoconnor / gist:1007305
Created June 3, 2011 22:38
Logstash Web init script
#! /bin/sh
#
# Logstash Start/Stop logstash
#
# chkconfig: 345 99 99
# description: Logstash
# processname: logstash
logstash_bin="java -Djava.net.preferIPv4Stack=true -jar /opt/logstash/logstash-1.0.11pre-monolithic.jar"
logstash_log="/opt/logstash/logstash-web.log"
@kjoconnor
kjoconnor / watch_mem.sh
Created September 15, 2011 16:34
Stupidly simple memory monitoring script
#!/bin/bash
# Tested on Ubuntu 8.04 32 bit
# When the memory limit drops below $memory_limit megabytes, bash will ring a bell
# and echo the current memory usage.
# Set the free memory limit (in megabytes)
memory_limit=150
# Check interval (in seconds)
@kjoconnor
kjoconnor / gist:1997099
Created March 7, 2012 23:15
Do something if memory is below X
if [ `sudo cat /proc/meminfo | grep MemFree | awk '{print $2;}'` -lt "200000" ]; then sudo /etc/init.d/apache2 restart ; fi
--
sudo monit summary | grep -i rabbit | grep running ; if [ "$?" -ne "0" ]; then sudo /etc/init.d/rabbitmq-server stop; sudo /etc/init.d/rabbitmq-server start; sudo monit monitor rabbitmq-server; fi
<?php
// Clear django_sessions table
date_default_timezone_set("UTC");
$link = mysql_connect("localhost", "username", "password")
or die("Couldn't connect to MySQL server.\n");
mysql_select_db("database")
@kjoconnor
kjoconnor / subs.py
Created October 16, 2012 03:48
Rosalind Subs
# For http://rosalind.info/problems/subs/
import re
import sys
string = None
substring = None
for line in open('rosalind_subs.txt', 'r'):
if string is None: