Skip to content

Instantly share code, notes, and snippets.

@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
$ 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 / 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
@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 / aws-creds.bash
Last active February 5, 2024 19:32
Fetch AWS STS keys and set environment variables
#!/bin/bash
# Fetch 24-hour AWS STS session token and set appropriate environment variables.
# See http://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html .
# You must have jq installed and in your PATH https://stedolan.github.io/jq/ .
# Add this function to your .bashrc or save it to a file and source that file from .bashrc .
# https://gist.github.com/ddgenome/f13f15dd01fb88538dd6fac8c7e73f8c
#
# usage: aws-creds MFA_TOKEN [OTHER_AWS_STS_GET-SESSION-TOKEN_OPTIONS...]
function aws-creds () {
local pkg=aws-creds
@ddgenome
ddgenome / k8.bash
Last active July 5, 2019 08:00
Kubernetes bash functions
# bash kubernetes functions
# kubectl with kubeconfig
function k () {
kubectl --kubeconfig=kubeconfig "$@"
}
# exec shell in pod
function k8sh () {
local p="$1"
shift
@ddgenome
ddgenome / cli.yml
Created January 31, 2017 02:36
Default Rug CLI configuration
# Set up the path to the local repository
local-repository:
path: "${user.home}/.atomist/repository"
# Set up remote repositories to query for Rug archives. Additionally one of the
# repositories can also be enabled for publication (publish: true).
remote-repositories:
maven-central:
publish: false
url: "http://repo.maven.apache.org/maven2/"
@ddgenome
ddgenome / cli-publish.yml
Last active February 3, 2017 05:19
Rug CLI configuration for publishing Rug archives
# Set up the path to the local repository
local-repository:
path: "${user.home}/.atomist/repository"
# Set up remote repositories to query for Rug archives. Additionally one of the
# repositories can also be enabled for publication (publish: true).
remote-repositories:
maven-central:
publish: false
url: "http://repo.maven.apache.org/maven2/"
@ddgenome
ddgenome / travis-ci-git-commit.bash
Last active February 16, 2023 06:13
Make a commit on a branch in a Travis CI build, dealing with detached HEAD state safely
#!/bin/bash
# function to make a commit on a branch in a Travis CI build
# be sure to avoid creating a Travis CI fork bomb
# see https://github.com/travis-ci/travis-ci/issues/1701
function travis-branch-commit() {
local head_ref branch_ref
head_ref=$(git rev-parse HEAD)
if [[ $? -ne 0 || ! $head_ref ]]; then
err "failed to get HEAD reference"
return 1
@ddgenome
ddgenome / atomist-link-image-webhook-codeship.bash
Created May 22, 2018 18:12
Atomist Link Image Webhook - Codeship