Skip to content

Instantly share code, notes, and snippets.

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`;
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
# 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.
python -c "import sys,hashlib; print(hashlib.sha256(open(sys.argv[1], 'rb').read()).hexdigest())" <filename>
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"
# 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 / 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
@hummus
hummus / gist:23c12103b7d3c748b4fc
Created November 15, 2014 02:37
ansible oneliner
ansible localhost -i <(echo "localhost") -c local -m setup
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: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" \