Skip to content

Instantly share code, notes, and snippets.

View samloh84's full-sized avatar

Samuel Loh Yin Kang samloh84

View GitHub Profile
import boto3
client = boto3.client('route53')
def delete_zone(zone_id):
""" List all records and deletes non SOA/NS records, before deleting the zone
"""
record_sets = client.list_resource_record_sets(HostedZoneId=zone_id)
# print(record_sets)
import boto3
client = boto3.client('route53')
def delete_zone(zone_id):
""" Deleting a hosted zone in AWS is a real pain if you have any number of
resource records defined because you must first delete all RR's in order to
remove the zone. This is a one-stop script to do all of that in one command.
"""
#!bin/bash
set -euxo pipefail
ALLOCATION_IDS=$(aws ec2 describe-addresses | jq -r '.Addresses[] | select(.AssociationId == null) | .AllocationId')
for ALLOCATION_ID in $ALLOCATION_IDS; do
aws ec2 release-address --allocation-id $ALLOCATION_ID
done
const _ = require('lodash');
const octet_regex = new RegExp('[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]');
const ipv4_regex = new RegExp(`^(${octet_regex.source})\.(${octet_regex.source})\.(${octet_regex.source})\.(${octet_regex.source})$`);
const ipv4_cidr_regex = new RegExp(`^(?<ipv4>(${octet_regex.source})\.(${octet_regex.source})\.(${octet_regex.source})\.(${octet_regex.source}))\/(?<prefix>[0-9]|[1-2][0-9]|3[0-2])$`);
let validate_ipv4_cidr = function (cidr) {
return ipv4_cidr_regex.test(cidr);
#!/bin/bash
function docker_machine_start() {
if [[ -x "$(command -v docker-machine)" ]]; then
if [[ "$(docker-machine status)" == "Running" ]]; then
if [[ $(expr $(date +%s) - $(docker run --rm centos date +%s) | tr -d -) -gt 300 ]]; then
docker-machine restart
fi
else
docker-machine start
fi
@samloh84
samloh84 / ssh-agent.sh
Created May 24, 2019 03:01
SSH Agent Startup Script
#!/bin/bash
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo -e "You should run the following command:\nsource bin/${0}"
exit 1
fi
PRIVATE_KEYS=$(grep -l -r "\\-\\+BEGIN [[:alpha:]]\+ PRIVATE KEY\\-\\+" ${HOME}/.ssh)
eval $(ssh-agent)
@samloh84
samloh84 / docker.sh
Created May 13, 2019 01:33
Docker Utility Script
#!/bin/bash
DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME:-default}
DOCKER_REGISTRY_NAMES=${DOCKER_REGISTRY_NAMES:-}
DOCKER_IMAGE_NAMES=${DOCKER_IMAGE_NAMES:-$(basename ${PWD})}
DOCKER_IMAGE_TAGS=${DOCKER_IMAGE_TAGS:-latest}
DOCKER_RUN_WORKING_DIRECTORY=${DOCKER_RUN_WORKING_DIRECTORY:-/usr/src/app}
@samloh84
samloh84 / index.html
Created May 2, 2019 13:00
Monaco Editor
<!doctype html>
<html lang="en">
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.16.2/min/vs/editor/editor.main.css"
rel="stylesheet">
<style>
#container {
width: 90%;
height: 800px;
margin-left: auto;
@samloh84
samloh84 / latest_centos_ami.tf
Created April 29, 2019 01:51
Terraform gists
// Find latest Centos AMI
data "aws_ami" "centos" {
most_recent = true
executable_users = [
"self"]
filter {
name = "product-code"
values = [
"aw0evgkw8e5c1q413zgy5pjce"]
#!/bin/bash
dscacheutil -flushcache; sudo killall -HUP mDNSResponder