Skip to content

Instantly share code, notes, and snippets.

@hummus
hummus / gist:5682969
Created May 31, 2013 04:38
mysql: quick drop all foreign key constraints
mysql -u $USER -p$PASS -e 'select * from information_schema.TABLE_CONSTRAINTS where CONSTRAINT_TYPE="FOREIGN KEY"' -B | awk '{if (NR!=1) print("ALTER TABLE "$2"."$5" DROP FOREIGN KEY "$3";")}' | mysql -u $USER -p$PASS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font: 14px sans-serif;
}
.axis path, .axis line {
fill: none;
@hummus
hummus / gist:7889036
Last active December 30, 2015 21:39 — forked from somic/gist:123889
#!/bin/bash
# Prints out how many seconds ago this EC2 instance was started
# It uses Last-Modified header returned by EC2 metadata web service, which as far
# as I know is not documented, and hence I assume there is no guarantee
# that Last-Modified will be always set correctly.
# if this fails for some non-ec2 instance, then
# try to stat a file that might be from os-install time
# Use at your own risk.
python <<EOP
from datetime import datetime;import urllib2;
@hummus
hummus / README
Created December 23, 2013 07:48 — forked from sasha-id/README
MongoDB upstart scripts for Ubuntu.
Run following commands after installing upstart scripts:
ln -s /lib/init/upstart-job /etc/init.d/mongoconf
ln -s /lib/init/upstart-job /etc/init.d/mongodb
ln -s /lib/init/upstart-job /etc/init.d/mongos
To start services use:
@hummus
hummus / gist:8538023
Created January 21, 2014 10:59
ssh throughput oneliner
ssh hostname 'openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero' | pv > /dev/null
@hummus
hummus / gist:8592113
Last active September 26, 2024 01:29
aws cli + jq example
wget http://stedolan.github.io/jq/download/linux64/jq
aws ec2 describe-instances --filters "Name=tag:Name,Values=$NAME" \
"Name=instance-state-name,Values=running" \
| jq -r \
".Reservations[] | .Instances[] | .InstanceId" \
aws ec2 describe-volumes --filters \
"Name=status,Values=available" \
| jq -r ".Volumes[] | .VolumeId" \
from collections import defaultdict
from itertools import imap
from boto import dynamodb
from magnitude import mg
REGION='us-west-1'
conn = dynamodb.connect_to_region(REGION)
WANT_PROPS = (
@hummus
hummus / gist:23c12103b7d3c748b4fc
Created November 15, 2014 02:37
ansible oneliner
ansible localhost -i <(echo "localhost") -c local -m setup
@hummus
hummus / gen-cert
Last active June 13, 2017 21:52
generate self-signed ssl cert
#!/bin/bash
# original url: http://www.jamescoyle.net/how-to/1073-bash-script-to-create-an-ssl-certificate-key-and-request-csr
set -e
set -x
domain="${1-$(cat /etc/hostname)}"
commonname="$domain"
# if the domain is a freakin IP it must also specify an IP SAN
# hopefully you have a python
# SimpleHTTPServer oneliner
openssl req -new -x509 -keyout /dev/stdout -out /dev/stdout -days 365 -nodes -subj "/C=XX/O=Default Company Ltd" 2>/dev/null > yourpemfile.pem ; python -c 'import sys, BaseHTTPServer, SimpleHTTPServer; import ssl; httpd = BaseHTTPServer.HTTPServer(("0.0.0.0", 4443), SimpleHTTPServer.SimpleHTTPRequestHandler); httpd.socket = ssl.wrap_socket (httpd.socket, server_side=True, certfile=sys.argv[1]); httpd.serve_forever()' yourpemfile.pem