Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
split() {
local IFS="$1"
shift
set -- $*
echo "$@"
}
join() {

nginx snippets

internal redirects

../test-internal-redirects.conf

location = /real1 { try_files /real1.txt =404; }
location = /real2 { try_files /real2.txt =404; }
#!/bin/sh
# create remote origin and push
# use 'trunk' unless init.defaultBranch is set
default_branch=$(git config init.defaultBranch || echo 'trunk')
remote_host='your-remote-host'
# assuming the remote host has a directory in $HOME named git
toplevel=$(git rev-parse --show-toplevel)
remote_repo_path="git/${toplevel##*/}.git"
@putnamhill
putnamhill / README.md
Last active February 3, 2023 21:51
parse firewall rules with xslt

parse firewall rules with xslt

to run

xsltproc firewall.xsl source.xml

to test with bash

diff --report-identical-files <(xsltproc firewall.xsl source.xml) expect

Git current branch

The shell used in the following examples is bash, but the commands can be adapted for other shells.

reading it

Determine if working in a git repository

The goal here is to have a performant way to determine if we are in a git repo without printing anything.

git status --porcelain --untracked-files=no &>/dev/null && \
@putnamhill
putnamhill / ics2stdout.awk
Created February 23, 2019 23:03
an awk script to convert Apple's reminder lists to plain text
#!/usr/bin/env awk -f
BEGIN {
FS = ":"
RS = "\r\n"
OFS = "\t"
}
/BEGIN:VTODO/ {
my_status = ""
@putnamhill
putnamhill / hdiutil-attach-detach.sh
Last active January 25, 2024 22:16
Steps to attach a dmg disk image using hdiutil while capturing the mount point and dev entry for detaching when done
#!/bin/bash
dmg_path="$1"
# use process redirection to capture the mount point and dev entry
IFS=$'\n' read -rd '\n' mount_point dev_entry < <(
# mount the diskimage (leave out -readonly if making changes to the file system)
hdiutil attach -readonly -plist "$dmg_path" | \
@putnamhill
putnamhill / ven-slice.pl
Last active January 11, 2018 00:42
Print items of in-list that are not in other-list; i.e. the relative complement of in-list and other-list.
#!/usr/bin/perl -w
use Getopt::Long;
# use diagnostics;
sub usage {
my $name = $0;
$name =~ s/.*\///;
print <<EOT;
Usage: $name [options] in-list other-list
@putnamhill
putnamhill / coinmarketcap-parse.sh
Created November 19, 2017 15:56
Reads the coinmarketcap ticker and writes the prices for a cryptocoins to a file
#!/bin/bash
get_data() {
# if the parameter is a local file just cat it (for testing) otherwise try curl
{ test -r "$1" && cat "$1" || curl -s "$1"; } | \
jq --raw-output \
'.[] | "\(.symbol | ascii_downcase) \(.price_usd)"'
}
process() {
@putnamhill
putnamhill / git-bare-repo-commands.sh
Last active December 14, 2017 14:46
Steps to create a bare git repo
## setting up a personal git repository that you can push change sets to
## ssh-host: a host defined in ~/.ssh/config (see: ssh_config(5))
## camaro: the name of the repo
# on a remote host or local filesystem:
git init --bare camaro.git # (option: use --shared if there are other contributors)
# on local host cd to camaro directory:
git remote add origin ssh-host:[path/]camaro.git
# (for origin on local filesystem: git remote add origin file:///media/volume-name/camaro.git)