Skip to content

Instantly share code, notes, and snippets.

View joemiller's full-sized avatar

joe miller joemiller

View GitHub Profile
@joemiller
joemiller / git-diff-size-check-total-only.rb
Last active January 3, 2023 07:40
proof of concept script for checking the size of staged git commits and rejecting based on individual file or overall total
#!/usr/bin/env ruby
MAX_DIFF_SIZE_MB = 4 # MB
def bytes_to_mb(bytes)
bytes.to_f / (1024*1024)
end
total_diff_bytes = 0
@joemiller
joemiller / go.sh
Created April 20, 2012 14:02
parallel provisioning with Vagrant
#!/bin/sh
# concurrency is hard, let's have a beer
MAX_PROCS=4
parallel_provision() {
while read box; do
echo "Provisioning '$box'. Output will be in: $box.out.txt" 1>&2
echo $box
@joemiller
joemiller / docker-backup.sh
Created August 7, 2018 22:06
minimal docker image backup/restore. used once when resetting the docker/mac VM
#!/bin/bash
set -eou pipefail
dump_images() {
for i in $(docker images -q | uniq); do
local tarball="$i.tar.gz"
if [[ -e "$tarball" ]]; then
echo "$tarball exists, skipping $i"
continue
@joemiller
joemiller / jconsole_ssh.sh
Created September 12, 2012 20:22
bash helper function 'jcon' for establishing remote jconsole sessions over ssh proxy
#
# Bash helper function for connecting to a remote JVM via jconsole using an SSH
# tunnel.
#
# Supports multiple concurrent jconsole sessions to different hosts.
#
# Tested on mac osx, but should work on linux too.
#
# Install
# -------
@joemiller
joemiller / vault-cert-parse.rb
Last active June 23, 2022 14:55
quick script to parse vault pki issue responses into tls.pem file
#!/usr/bin/env ruby
#
# Usage:
#
# vault write pki/issue/role common_name=foo ttl=1h | ruby vault-cert-parse.rb
#
# Creates the file tls.pem containing private-key, cert, and issuing-ca
#
# Can also be used with curl for living on the edge:
#
@joemiller
joemiller / gist:4c4e22c0795134c5ad7088bc822ae82c
Created April 5, 2022 23:41
vault kv allows for a key to both contain data and have subkeys
$ vault server -dev -dev-root-token-id=root &
$ VAULT_ADDR='http://127.0.0.1:8200' VAULT_TOKEN=root vault kv put secret/foo bar=baz quux=blah
$ VAULT_ADDR='http://127.0.0.1:8200' VAULT_TOKEN=root vault kv put secret/foo/subkey blah=blah
$ VAULT_ADDR='http://127.0.0.1:8200' VAULT_TOKEN=root vault kv list secret/
Keys
----
foo
foo/
@joemiller
joemiller / run-all-wrapper.sh
Last active January 6, 2022 01:24
terragrunt wrapper to leverage bash/zsh shell globbing support for the run-all command set
#!/bin/bash
#
# uber simple wrapper to leverage bash/zsh shell globbing support with terragrunt's `--terragrunt-include-dir=` flag.
set -eou pipefail
[[ -n "${DEBUG:-}" ]] && set -x
if [[ "$#" -lt 2 ]]; then
echo "Usage: $0 [init|plan|apply] GLOB"
#!/bin/bash
#
# Start the server in dev mode:
#
# bash setup-pki-vault-server.sh
#
# In another window, generate a cert:
#
# VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=root vault write pki/issue/any common_name=foo
#
@joemiller
joemiller / softirq-watch.rb
Created July 21, 2016 19:16
watch /proc/softirqs and print deltas of each metric at an interval
#!/usr/bin/ruby
# CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 CPU8 CPU9 CPU10 CPU11 CPU12 CPU13 CPU14
# HI: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# TIMER: 2344143 2305156 2295889 2278479 2274008 2260063 2237324 2245718 0 0 0 0 0 0 0
# NET_TX: 11309569 76523 76961 77020 77086 76261 78908 76016 0 0 0 0 0 0 0
# NET_RX: 11442620 47843 49607 48089 48989 45698 49201 41453 0 0 0 0 0 0 0
# BLOCK: 0 0 0 0 0 0 0 0
@joemiller
joemiller / renewer.go
Created June 16, 2021 15:57
demo of vault token renewer go routine from internal project
type VaultDriver struct {
vaultClient *vaultapi.Client
project string
}
func (d VaultDriver) TokenRenewer(ctx context.Context) error {
renewer, err := d.vaultClient.NewRenewer(&vaultapi.RenewerInput{
Secret: &vaultapi.Secret{
Auth: &vaultapi.SecretAuth{
ClientToken: d.vaultClient.Token(),