Skip to content

Instantly share code, notes, and snippets.

View lox's full-sized avatar

Lachlan Donald lox

View GitHub Profile
@lox
lox / stream-to-cw-logs
Created May 24, 2023 02:35
Stream stdin to cloudwatch logs
#!/bin/bash
# Enable bash strict mode
set -euo pipefail
IFS=$'\n\t'
# Disable the pager for aws commands (no less on the host)
export AWS_PAGER=""
# Get the log group arn as a parameter and cut the group name out of it
@lox
lox / gist:c7a3b44970201b716e600f3538a6e351
Last active March 14, 2023 22:20
A Buildkite pre-bootstrap hook that protects against attacks via known dangerous environment variables
#!/bin/bash
set -euo pipefail
# Buildkite pre-bootstrap hook that fails a build if there are any
# dangerous environment variables set.
blocklist=(
# General Linux
"PATH" # Executable search path
"LD_PRELOAD" # Preloaded shared libraries
@lox
lox / docker-compose.yml
Created December 21, 2022 05:40
Donald Family Minecraft
version: "3.5"
services:
minecraft:
image: 05jchambers/legendary-minecraft-geyser-floodgate:latest
restart: "unless-stopped"
stdin_open: true
tty: true
volumes:
- ./minecraft:/minecraft
environment:
@lox
lox / test_mysql_docker.sh
Created June 9, 2022 06:33
MySQL in Docker seems slow to start 🤔
#!/bin/bash
set -euo pipefail
wait_for_container() {
echo -n "Waiting for $1"
for _ in $(seq 1 120); do
test "$(docker inspect --format "{{.State.Health.Status}}" "$1")" == "healthy" && break
sleep 1
echo -n .
done
@lox
lox / indicate.go
Created January 2, 2022 02:18
Thinking on an API for spinner/progress bar library
// Spinners and Progress bars are the same thing.
// They are assembled with a go template with some built in functions or templated strings
// for things like messages before and after.
// Render a spinner that looks like:
// ⡀ Loading blah... [3s]
spinner := indicate.New(context.Background(),
`{{ spinner "⠁⠂⠄⡀⢀⠠⠐⠈ " }} {{ template "message" }} [{{ elapsed }}]`).
WithDefaults(indicate.SpinnerDefaults).
@lox
lox / main.go
Created July 14, 2021 02:36
A utility for generating GitHub Access Tokens from a GitHub App
package main
import (
"bytes"
"crypto/rsa"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
@lox
lox / test.sh
Created July 30, 2020 10:41
Testing interpolation
echo "test"
@lox
lox / child.sh
Last active November 4, 2019 01:49
#!/bin/bash
set -euo pipefail
terminate(){
printf "Terminating child process $$ after signal."
exit 1
}
printf "Running $0, pid is %d, pgid is %d\n" "$$" "$(ps -o pgid= $$)"
@lox
lox / buildkite.yml
Created February 4, 2019 07:52
A pipeline with no checkout
steps:
- command: echo hello world!
#!/bin/bash
set -euo pipefail
measure() {
f=$1
n=$2
shift 2
echo wall,user,sys,rss > "$f"
for i in $(seq $n); do
[[ -d $i ]] && rm -rf $i