Skip to content

Instantly share code, notes, and snippets.

@tomdavidson
tomdavidson / scrit-as-root.sh
Created November 30, 2021 16:06
snippit to help with scripts that should be run as root
#!/usr/bin/env bash
if [ $SUDO_USER ]; then
realUser=$SUDO_USER
else
realUser=$(whoami)
fi
realUserHome=$(bash -c "cd ~$(printf %q "$realUser") && pwd")
@tomdavidson
tomdavidson / bootstrap.sh
Last active November 30, 2021 06:07
bootstrap script for setting up toms new computer
#!/usr/bin/env bash
# promts for sudo and can be installed via:
# wget -O - https://gist.githubusercontent.com/tomdavidson/64828803dbd4718514a465be1d7e908a/raw/75ec0521175b3d8b7d92c188d3dc0d251dbf5469/install-node-zx.sh | bash
! type sudo >/dev/null 2>&1 && apt install sudo && usermod -aG sudo "$(whoami)"
export CLOUDSDK_CORE_PROJECT='dots-333103'
# install NodeJS & zx if not already installed
@tomdavidson
tomdavidson / slugify.sh
Created November 20, 2021 05:13
Lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with '-'. No leading or trailing '-'. Useful with URLs, host names, domain names, and stack names.
#!/usr/bin/env bash
shopt -s extglob
# Lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with '-'.
# No leading or trailing '-'. Useful with URLs, host names, domain names, and stack names.
slugify() {
: "${1:?'Usage: slugify NAME'}"
local next="$1"
next="${next,,}" # lowercase
next="${next//+([^a-z0-9])/-}" # replace non-alphanumeric wiht '-'
next="${next#-}" # remove - from the start
@tomdavidson
tomdavidson / lolaus.sh
Created November 5, 2021 09:57
lolaus.sh
#!/usr/bin/env bash
set -euo pipefail
DEBUG=${DEBUG:-}
help() {
cat <<EOF
Simple monorepo lifecycle/pipeline tool for running one or more commands on one
or more directories that have diffs compared to an ancestor. The primary
#!/usr/bin/env zx
const shellFiles = globby.globbySync(['**/*.sh', '**/*.bash'], { gitignore: true });
nothrow($`npx -y shellcheck -f diff ssa-pg/scripts/deploy-infra.sh | git apply`);
$ cat Dockerfile
FROM docker.io/hello-world
$ docker build --tag uscm5 .
STEP 1: FROM docker.io/hello-world
STEP 2: COMMIT uscm5
--> d1165f22123
Successfully tagged localhost/uscm5:latest
Successfully tagged docker.io/library/hello-world:latest
d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
@tomdavidson
tomdavidson / .editorconfig
Last active March 20, 2021 09:26
coordinated code configs
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
@tomdavidson
tomdavidson / tf-config-files.tf
Created December 5, 2019 06:41
Terraform example loading config from dir of files
variable "config_files_path" {
default = "../../teams/*.yaml"
description = "The path to team config files"
}
data "local_file" "configs" {
for_each = { for k, file in fileset(dirname(var.config_files_path), basename(var.config_files_path)) :
k => abspath("${dirname(var.config_files_path)}/${file}")
}
#!/usr/bin/env bash
help() {
cat <<EOF
Simple monorepo lifecycle/pipeline tool for running one or more commands on one
or more directories that have diffs compared to an ansector. The primary
use case is for selective CI jobs within a trunk based workflow.
Takes two arguments, <glob> <command>. The command is invoked from each
directory context matching the glob.
@tomdavidson
tomdavidson / ghteams.tf
Last active September 3, 2019 21:31
tf to create children teams after looking up parent ids
## Existing list of teams with members list:
"0" = {
"description" = "No one cared enough to add a description to this team"
"members" = [
{
"role" = "maintainer"
"username" = "bob"
},
{