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`);
@tomdavidson
tomdavidson / install_gnucmd_osx.sh
Created July 19, 2015 19:11
Installs GNU Command Line Tools & then some.
#!/usr/bin/env bash
# Installs GNU Command Line Tools & then some. Requires homebrew.
# Most are newer and more powerful that than OSX’s but also solves most OS compatibility issues
echo "Installing GNU coreutils and various."
export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
brew install coreutils
brew install binutils
brew install diffutils
brew install ed --with-default-names
brew install findutils --with-default-names
$ 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 / userinit.sh
Created April 15, 2015 03:46
Android route hotspot traffic over vpn
##!/system/bin/sh
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
@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}")
}