Skip to content

Instantly share code, notes, and snippets.

@hummus
hummus / gist:8592113
Last active April 26, 2024 19:45
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" \
python -c 'import string; CHARS=string.digits + string.ascii_lowercase; b36e = lambda integer,encoded="": encoded if integer<=0 else b36e(integer//36, CHARS[integer%36] + encoded); import sys; print b36e(int(sys.argv[1], 16))' ACEBACEACE
echo '{"foo": true}' | python -c "from jwt.api_jws import PyJWS;from cryptography.hazmat.backends import default_backend;from cryptography.hazmat.primitives.serialization import load_pem_private_key; jws=PyJWS(); pk = load_pem_private_key(open('key.pem').read(), password=None, backend=default_backend()); import sys; msg = jws.encode(sys.stdin.read(), pk, algorithm='RS512'); print msg"
print qq/Hello\n/; # same as: print "Hello\n";
print q/He owes $5.00/; # same as: print 'He owes $5.00', "\n";
@states=qw( E T A L ); # same as ("E", "T", "A","L")
$today = qx(date); # same as $today = `date`;
# request CA via the host
openssl s_client -showcerts -connect www.example.com:443 < /dev/null | openssl x509 -outform PEM 2>/dev/null
# awk statement for wrangling
awk '/----BEGIN CERTIFICATE----/ { flag = 1; ++ctr } flag && ctr < 2 { print } /-----END CERTIFICATE-----/ { flag = 0 }' out | openssl x509 -noout -sha256 -fingerprint
# good luck though, not all servers give or have the CA accessible wtf.
@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
python -c "import sys,hashlib; print(hashlib.sha256(open(sys.argv[1], 'rb').read()).hexdigest())" <filename>
# 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
@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 / 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: