Skip to content

Instantly share code, notes, and snippets.

@toddlers
toddlers / Makefile
Created May 25, 2020 10:57
language interpreters in Makefiles
.ONESHELL:
.SILENT:
main: \
python \
ruby \
R \
bash \
docker
@toddlers
toddlers / cfn-policy.sh
Created April 13, 2020 16:36
apply nested stack policy
function protect_nested_stacks() {
local parent_stack=$1 stack_policy_file=$2
local nested_stacks=$(aws cloudformation list-stack-resources \
--stack-name ${parent_stack} \
--query "StackResourceSummaries[?ResourceType=='AWS::CloudFormation::Stack'].[PhysicalResourceId]" \
--output text
)
for stack in ${nested_stacks}; do
aws cloudformation set-stack-policy --stack-name ${stack} --stack-policy-body file://${stack_policy_file}
@toddlers
toddlers / embed_interface.go
Created January 8, 2020 17:42
interfaces and type embedding golang
package main
import "fmt"
type Boss struct{}
func (b *Boss) AssignWork() {
fmt.Println("Boss assigned work")
}
@toddlers
toddlers / golambda.sh
Created January 6, 2020 16:23
golang-lambda
mkdir helloworld
cd !$
go get github.com/aws/aws-lambda-go/lambda
GOOS=linux go build -o helloworld
aws iam create-role --role-name lambda-basic-execution
--assume-role-policy-document file://lambda-trust-policy.json
@toddlers
toddlers / cobra-klog.go
Created December 28, 2019 13:10
klog-with-cobra
package main
import (
"flag"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog"
)
@toddlers
toddlers / awscli-jq.sh
Created July 26, 2019 09:27
awscli+jq usage
wget http://stedolan.github.io/jq/download/linux64/jq
aws ec2 describe-instances --filters "Name=tag:Name,Values=$NAME" \
"Name=instance-state-name,Values=running" \
| jq -r \
".Reservations[] | .Instances[] | .InstanceId" \
aws ec2 describe-volumes --filters \
"Name=status,Values=available" \
| jq -r ".Volumes[] | .VolumeId" \
@toddlers
toddlers / abbreviated-unbound.conf
Created January 15, 2019 14:40 — forked from bryanjswift/abbreviated-unbound.conf
Unbound (http://unbound.net/) configuration for local network device testing.
# The server clause sets the main parameters.
server:
# Allow network connections outside of localhost
interface: 0.0.0.0
# Don't automatically run in the background because I want to be able to kill it without hunting a pid
do-daemonize: no
# TODO: Change this to your network range, like `192.168.0.0/16 allow`
access-control: 10.0.0.0/16 allow
# TODO: Change this to your username, or whatever user you want to run/own the `unbound` process
username: "bryanjswift"
@toddlers
toddlers / go-shebang-story.md
Created June 29, 2018 08:47 — forked from posener/go-shebang-story.md
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@toddlers
toddlers / awscli.sh
Created April 10, 2018 09:24
aws instance ip and id
aws ec2 describe-instances –region=us-east-1 | jq ‘.”Reservations”[].”Instances”[] | .PrivateIpAddress + ” ” + .InstanceType’ | sed s/\”//g
@toddlers
toddlers / s3logs_analysis.sql
Created March 21, 2018 04:54
s3logs_analysis via Athena
/* Create a database in Athena */
CREATE DATABASE s3_AccessLogsDB;
/*
Create a table within the Athena database
Replace s3://MY_S3_BUCKET/ with your S3 bucket
which has the access logs you want to query
*/
CREATE EXTERNAL TABLE IF NOT EXISTS s3_AccessLogs.Accesslogs(
BucketOwner string,