Skip to content

Instantly share code, notes, and snippets.

@kjoconnor
kjoconnor / ec2_info.py
Created April 1, 2013 23:43
Grains for salt on EC2
import json
import logging
import requests
try:
from boto.ec2 import connect_to_region as _connect_to_region
has_boto = True
except ImportError:
has_boto = False
@kjoconnor
kjoconnor / get_icon.py
Created June 20, 2013 08:56
Grab icons from RSS feed URLs via the awesome getfavicon.appspot.com service
import logging
import requests
import tldextract
from collections import deque
from urllib import quote_plus
from urlparse import urlparse, urlunparse
DEFAULT_ICON = "http://mozorg.cdn.mozilla.net/media/img/"\
@kjoconnor
kjoconnor / find_in_sg.py
Created October 22, 2013 08:50
Remove an IP from all EC2 security groups
from boto.ec2 import connect_to_region
ec2 = connect_to_region('us-west-1')
target = '127.0.0.1/32'
remove = False
sgs = ec2.get_all_security_groups()
for sg in sgs:
for rule in sg.rules:
@kjoconnor
kjoconnor / delete_snapshots.py
Created November 6, 2013 21:33
boto script to delete snapshots matching a filter and older than X days
import sys
from boto.ec2 import connect_to_region
from datetime import datetime, timedelta
try:
days = int(sys.argv[1])
except IndexError:
days = 7
@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

Keybase proof

I hereby claim:

  • I am kjoconnor on github.
  • I am gooeyblob (https://keybase.io/gooeyblob) on keybase.
  • I have a public key ASBnf2dJdzlAv0fp95hoai_HHUAXITBOc1f0LX0Jtv3RuQo

To claim this, I am signing this object: