Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin O'Connor kjoconnor

  • Reddit
  • San Francisco, CA
View GitHub Profile
@kjoconnor
kjoconnor / clean_gmail_emails.py
Created Jan 23, 2020
I used this script to delete a bunch of cron emails that had built up in my inbox. You should be able to change the search params to cover anything you might want to get rid of. Note this will _permanently delete_, not just move to trash.
View clean_gmail_emails.py
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://mail.google.com/']
View keybase.md

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:

@kjoconnor
kjoconnor / generate_password.sh
Created Feb 24, 2015
Generate SHA512 passwords for /etc/shadow
View generate_password.sh
#!/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 / redirect_loop.py
Created Jul 9, 2014
Create a redirect loop with Tornado (for testing)
View redirect_loop.py
import tornado.httpserver
import tornado.ioloop
import tornado.web
PORT = 10045
class Application(tornado.web.Application):
def __init__(self):
handlers = [
@kjoconnor
kjoconnor / check_if_sg_is_used.py
Created May 16, 2014
Find if a security group is in use anywhere
View check_if_sg_is_used.py
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 / find_in_all_sg.py
Created Feb 7, 2014
Find security group grants in ElastiCache and EC2
View find_in_all_sg.py
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 / find_memcached_expiries.py
Created Jan 30, 2014
Find what percentage of memcache keys don't have expiries set
View find_memcached_expiries.py
import re
import telnetlib
import time
from collections import Counter
hosts = [
('localhost', 11211)
]
@kjoconnor
kjoconnor / delete_snapshots.py
Created Nov 6, 2013
boto script to delete snapshots matching a filter and older than X days
View delete_snapshots.py
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_in_sg.py
Created Oct 22, 2013
Remove an IP from all EC2 security groups
View find_in_sg.py
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 / get_icon.py
Created Jun 20, 2013
Grab icons from RSS feed URLs via the awesome getfavicon.appspot.com service
View get_icon.py
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/"\
You can’t perform that action at this time.