Skip to content

Instantly share code, notes, and snippets.

View farrellit's full-sized avatar

Dan Farrell farrellit

View GitHub Profile
iid=i-04XXXXXXXXXXXXX4f
# find security group of instance
securitygroups=`aws --profile dev ec2 describe-instances --region us-east-2 --instance-id $iid --query Reservations[*].Instances[*].SecurityGroups[*][GroupId] --output text`
# see open rules ( there's usually not many )
aws --profile dev --region us-east-2 ec2 describe-security-groups --group-ids $securitygroups --query '*[*][GroupId,IpPermissions[?FromPort!=null].[FromPort,ToPort,IpRanges[*].CidrIp]]' --output text
# find subnet
subnet=`aws --profile dev ec2 describe-instances --region us-east-2 --instance-id $iid --query Reservations[*].Instances[*][SubnetId] --output text`
# now check default route. If it's through an IGW, we should be good!
aws ec2 --region us-east-2 --profile dev describe-route-tables --filters Name=association.subnet-id,Values=$subnet --query RouteTables[*].Routes[?DestinationCidrBlock=='`0.0.0.0/0`']
# get it's public IP
@farrellit
farrellit / gist:4e526552f1b322706d8d0003d607edfe
Created December 21, 2016 02:36
which elbs in route53?
aws route53 list-hosted-zones --query HostedZones[?Id!=null].Id --output text | grep -v None | xargs -n 1 aws route53 list-resource-record-sets --query 'ResourceRecordSets[?AliasTarget!=null][AliasTarget.DNSName]' --hosted-zone-id --output text | grep -F elb.amazonaws.com
olddate=''
cmd='make r53'
while true; do newdate=`stat -f %m rotate-by-r53.py `; [[ "$olddate" == "$newdate" ]] || { olddate="$newdate"; $cmd; }; sleep 0.25; done
@farrellit
farrellit / gist:8cc1c16449ee04170103a73bec1c85d1
Created December 13, 2017 23:32
find repos without local changes
# find directories containing .git subdirs
find ~/ -type d -name '.git' -print0 | xargs -n 1 -0 dirname \
| xargs -I % -n 1 bash -c 'cd "%" && pwd 1>&2; (git status --porcelain| grep -q . && [[ ! -n "`git diff`" ]] ) || echo %'\
| xargs -I % bash -c '[[ -n "`cd %; git status --porcelain; git diff;`" ]] && echo %' \
| tee /dev/stderr | sort > purportedly-empty-repos.txt
#That makes sure you don't have any uncommitted changes. But it still doesn't check to make sure you don't have unpushed commits.
@farrellit
farrellit / docker-cleanup.sh
Created December 29, 2017 22:55
docker cleanup
# remove containers which have exited
docker ps -a | awk '/Exited[ ]\(/ {print $1}' | xargs docker rm
# remove images without tag nor repo
docker images | awk '/^<none>[[:space:]]*<none>/ {print $3}' | xargs docker rmi
ip=...
#pubkey=... # default should suffice if you have the default key location
ssh $ip "bash -c 'mkdir -p ~/.ssh; chmod 0700 ~/.ssh; cat > ~/.ssh/authorized_keys'" < ${pubkey:-~/.ssh/id_rsa.pub
aws route53 list-hosted-zones --query HostedZones[?Id!=null].Id --output text \
| grep -v None \
| xargs -n 1 -P 10 \
aws route53 list-resource-record-sets \
--query 'ResourceRecordSets[?AliasTarget!=null][AliasTarget.DNSName]' \
--output text --hosted-zone-id | grep -F elb.amazonaws.com
@farrellit
farrellit / README.md
Last active October 25, 2018 15:21
thoughts on git commands for automatic k8s branch deployments

Git commands for a slim deployment pipeline for github branches

get current branch

TODO: what happens if you're not on a branch?

git rev-parse --abbrev-ref HEAD

Get upstram of current branch

@farrellit
farrellit / stdin_yaml_to_json.sh
Last active September 19, 2019 20:58
shell inline python invocation to transform yaml to json
python -c "import yaml, sys, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))"
@farrellit
farrellit / t.c
Last active December 3, 2019 01:43
C Gist
#include <stdio.h>
void f() {
printf("Hello, world") ;
}
int main() {
f();
}