Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
@amosshapira
amosshapira / find-unused-amis
Last active March 22, 2024 16:00
Find self-owned AMI's which are not used by any instances or launch configurations in a region
#!/bin/bash
# Find self-owned AMI's which are not used by any instances or launch configurations in the default region.
comm -23 \
<(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \
<((aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text;
aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[].[ImageId]' --output text) | sort -u)
@amosshapira
amosshapira / export-all-k8s-resources.sh
Created September 13, 2022 23:54
Export all K8s resources
#!/bin/env bash
## Source: https://github.com/kubernetes/kubernetes/issues/24873#issuecomment-416689257
## https://github.com/kubernetes/kubernetes/issues/24873#issuecomment-416189335
# This version excludes service account tokens from the export
i=$((0))
for n in $(kubectl get -o=custom-columns=NAMESPACE:.metadata.namespace,KIND:.kind,NAME:.metadata.name pv,pvc,configmap,ingress,service,secret,deployment,statefulset,hpa,job,cronjob --all-namespaces | grep -v 'secrets/default-token')
do
@amosshapira
amosshapira / clone-all-gh.sh
Last active March 9, 2021 04:30
Bash script to clone all repositories of a given GitHub organisation
#!/usr/bin/env bash
# "CLONE_ALL_GH_TOKEN" should be a Personal Token from https://github.com/settings/tokens
# with scope "repo"
ORG=<YOUR_ORG_NAME_HERE>
GIT_OUTPUT_DIRECTORY=${1:-"$HOME/github"}
echo Cloning to $GIT_OUTPUT_DIRECTORY
# "100" is the maximum adhered to by GitHub
PER_PAGE=100
@amosshapira
amosshapira / AuthyToOtherAuthenticator.md
Created February 24, 2021 07:51 — forked from gboudreau/AuthyToOtherAuthenticator.md
Export TOTP tokens from Authy

Generating Authy passwords on other authenticators


There is an increasing count of applications which use Authy for two-factor authentication. However many users who aren't using Authy, have their own authenticator setup up already and do not wish to use two applications for generating passwords.

Since I use 1Password for all of my password storing/generating needs, I was looking for a solution to use Authy passwords on that. I couldn't find any completely working solutions, however I stumbled upon a gist by Brian Hartvigsen. His post had a neat code with it to generate QR codes for you to use on your favorite authenticator.

His method is to extract the secret keys using Authy's Google Chrome app via Developer Tools. If this was not possible, I guess people would be reverse engineering the Android app or something like that. But when I tried that code, nothing appeared on the screen. My guess is that Brian used the

@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 / instructions.md
Last active August 7, 2019 21:24 — forked from ba11b0y/instructions.md
Minikube Installation on Ubuntu 18.04 which really works!

Installation of Minikube with kvm2 driver which really works!

Disclaimer: Tried on Ubuntu 18.04 LTS

Installation of minikube

  • Apparently installation from snap doesn't work as expected, use curl for installation of the latest version.

  • curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

  • sudo install minikube-linux-amd64 /usr/local/bin/minikube

@amosshapira
amosshapira / introrx.md
Created June 21, 2019 04:35 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@amosshapira
amosshapira / gist:37a38bbbe388f4271ce2
Created April 28, 2015 02:05
Extract subnet id's from AWS using jq and aws cli
# "vpc-12345678" is a default VPC we want to exclude
# "-r" tells jq not to quote the output
aws ec2 describe-subnets | \
jq -r '.Subnets[] | select(.VpcId != "vpc-12345678")| .SubnetId' | \
sort -u
@amosshapira
amosshapira / sprintrole-verification.txt
Created March 31, 2019 17:30
springrole.com verification
f7be86d295858e09e63eee11f0859653d6d3f302775a2fc23223dbfeaf261976f612e38456d6ec9c2e9955c65c0736606446640e42a6af7284bd7efd58c42418
@amosshapira
amosshapira / zipfilestring.py
Created November 28, 2016 03:30
sample code for generating a zip file in memory using Python. Useful for AWS Lambda Python
import StringIO
import zipfile
import os
import os.path
def append_requests_module_code(zf):
requests_path = os.path.dirname(os.path.realpath(requests.__file__))
for root, dirs, files in os.walk(requests_path):
ziproot = os.path.join('requests', root[len(requests_path)+1:])
for fn in files: