Skip to content

Instantly share code, notes, and snippets.

@ddgenome
ddgenome / coreos-ami-info.bash
Created August 10, 2016 15:40
Get CoreOS AMI information from AWS
#!/bin/bash
for c in stable beta alpha; do
for ra in $(curl -s "https://coreos.com/dist/aws/aws-$c.json" | jq --raw-output 'del(.release_info) | del(."us-gov-west-1") | map_values(.hvm) | to_entries | .[] | "\(.key):\(.value)"'); do
r=$(echo "$ra" | cut -d : -f 1)
a=$(echo "$ra" | cut -d : -f 2)
echo "$c $r $a"
aws --region "$r" ec2 describe-images --image-id "$a" | jq '.Images[].Name?'
done
done
exit 0
@ddgenome
ddgenome / defer-capture-error.go
Last active October 5, 2016 15:38
Capture an error in a Go defer function
import (
"fmt"
"io/ioutil"
"os"
)
func f() (e error) {
tmpDir, tmpErr := ioutil.TempDir("", "prefix")
if tmpErr != nil {
return nil, tmpErr
$ for d in $(for g in $(find "$GOPATH" -name .git); do r=${g%.git}; b=$(cd $r && git rev-parse --abbrev-ref HEAD); if [[ $b == HEAD ]]; then echo "$r"; fi; done | grep -v -F '/atomisthq/'); do echo "$d"; (cd "$d" && git fetch && git checkout master && git rebase); done
@ddgenome
ddgenome / go-static-compilation
Created May 2, 2015 21:20
Compile Go program into a static binary
# Go 1.4
CGO_ENABLED=0 GOOS=linux go get -a -installsuffix cgo -ldflags '-s' github.com/elastic/logstash-forwarder
# Go 1.3
CGO_ENABLED=0 GOOS=linux go get -a -ldflags '-s' github.com/elastic/logstash-forwarder
# GOOS is the OS target of the binary
# -a forces recompilation of all components
# you can replace get with build and the GitHub URL with a path to the directory with the code
# the -s ld option strips the symbols from the binary making it smaller