Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
#!/bin/sh
# A good generator of IPSec PSK's
< /dev/urandom tr -dc a-zA-Z0-9_ | head -c30
@amosshapira
amosshapira / get-stack-name
Created February 1, 2016 04:58
Fetch the name of the CloudFormation stack of an EC2 instance
# get instance-id from meta-data, if you like:
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 describe-instances \
--instance-id $INSTANCE_ID \
--query 'Reservations[*].Instances[*].Tags[?Key==`aws:cloudformation:stack-name`].Value' \
--output text
@amosshapira
amosshapira / copy-from-time-machine.sh
Created January 23, 2016 22:32 — forked from vjt/copy-from-time-machine.sh
Copy data from a Time Machine volume mounted on a Linux box.
#!/bin/bash
#
# Copy data from a Time Machine volume mounted on a Linux box.
#
# Usage: copy-from-time-machine.sh <source> <target>
#
# source: the source directory inside a time machine backup
# target: the target directory in which to copy the reconstructed
# directory trees. Created if it does not exists.
#
#!/bin/bash
# Reference: https://github.com/pypa/pip/issues/3165
sudo -H pip install skew --ignore-install six
require 'gsl'
require 'time'
module Diskalerter
class ThresholdEstimator
attr_reader :timestamps, :signal, :threshold, :now
# timestamps - a list of timestamps in epoch milliseconds
# signal - a list of values for the provided timestamps
# threshold - the "exhaustion" threshold (e.g., 100 for a percentage signal)
@amosshapira
amosshapira / get-all-s3-prefix-lists
Created December 2, 2015 03:54
Fetch the S3 prefix list ID's for S3 in all AWS regions. These are can then be used as destinations in route tables
#!/bin/bash
# Fetch the S3 prefix list ID's for S3 in all AWS regions.
# These are can then be used as destinations in route tables
aws ec2 describe-regions --query 'Regions[*].RegionName' | \
jq -r '.[]' | \
while read REGION
do
echo ==== $REGION ====
@amosshapira
amosshapira / extract-vpc-endpoint-policy-document
Created December 1, 2015 01:17
Extract the PolicyDocument of an AWS VPC Endpoint
#!/bin/bash
aws ec2 describe-vpc-endpoints --region ap-southeast-2 | \
jq -r '.VpcEndpoints[].PolicyDocument'
@amosshapira
amosshapira / list-aws-availability-zones
Created November 30, 2015 06:06
List all AWS regions and EC2 availability zones using AWS cli
#!/bin/bash
# Uses jq to extract data from JSON
aws ec2 describe-regions | \
jq -r '.Regions[] | .RegionName' | \
while read i
do
echo ==== $i ====
aws ec2 describe-availability-zones --region $i | \
jq -r '.AvailabilityZones[] | .ZoneName'
# If you're looking into the C10M problem (10 million concurrent connections)
# you might want to play with DPDK (Originally proprietry Intel, now open source)
#
# C10M: http://c10m.robertgraham.com/
# DPDK: http://dpdk.org/
#
# This is a quick summary how to install dpdk on ubuntu
# running inside virtualbox on a mac
# On my Mac:
@amosshapira
amosshapira / new_gist_file_0
Created November 20, 2015 05:22
Calculate total space (in GB) used by RDS snapshots in a given region. AWS does NOT charge for storage of snapshots up to the total size of the primary DB as long as the RDS instance is running. Ref about pricing: https://aws.amazon.com/rds/pricing/
aws rds describe-db-snapshots --region=us-east-1 | \
jq '.DBSnapshots | .[] | .AllocatedStorage' | \
awk '{s+=$1}END{print s}'