This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Connecting to bastion via SSH..." | |
ssh -nNf bastion | |
echo "Connecting to MySQL..." | |
mysql -ugabe -pPaS$w0rD -h127.0.0.1 my_database | |
echo "MySQL client terminated, closing SSH connection..." | |
ssh -O exit bastion | |
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then | |
echo "source this!" | |
exit 1 | |
fi | |
if [ ! "$1" ]; then | |
echo "Name an environment!" | |
return 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import urllib | |
def print_creds(iam_role_name): | |
''' | |
Print out the current AWS credentials that this EC2 instance | |
has been assigned, for a IAM role it has assumed. | |
Note that credentials are rotated frequently |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto | |
def delete_recursive(bucketname, keyprefix): | |
''' | |
Recusively delete all keys with given prefix from the named bucket | |
Stolen from http://stackoverflow.com/a/10055320/141084 | |
''' | |
s3 = boto.connect_s3() | |
bucket = s3.get_bucket(bucketname, validate=False) | |
bucketListResultSet = bucket.list(prefix=keyprefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
SRC="$1" | |
DEST="$2" | |
echo "Starting reduced-redundancy sync of $SRC --> $DEST" | |
# would prefer to use this tool, but we get errors: https://github.com/aws/aws-cli/issues/401 | |
# aws --region us-west-2 s3 sync --storage-class REDUCED_REDUNDANCY $SRC $DEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def time_ago(time=False): | |
""" | |
Get a datetime object or a int() Epoch timestamp and return a | |
pretty string like 'an hour ago', 'Yesterday', '3 months ago', | |
'just now', etc | |
Modified from: http://stackoverflow.com/a/1551394/141084 | |
""" | |
now = datetime.utcnow() | |
if type(time) is int: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def local_file_hash(filepath): | |
''' | |
Return a hash of the file's contents, if file exists | |
Otherwise return None | |
''' | |
hasher = hashlib.sha256() | |
blocksize=(1 << 16) | |
try: | |
with open(filepath, "rb") as afile: | |
buf = afile.read(blocksize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import time | |
import signal | |
from subprocess import Popen, PIPE | |
dd = Popen(['dd'] + sys.argv[1:], stderr=PIPE) | |
while dd.poll() is None: | |
time.sleep(.3) | |
dd.send_signal(signal.SIGUSR1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# simple script to automate backup of SD cards to a file on disk | |
# only works on Mac OS at this time. | |
if [ -z "$1" ]; then | |
echo "Specify an img name to save to" | |
exit | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
import tempfile | |
from reportlab.graphics import renderPDF | |
from reportlab.pdfgen import canvas | |
import qrcode | |
import qrcode.image.svg | |
from svglib.svglib import svg2rlg |
OlderNewer