Skip to content

Instantly share code, notes, and snippets.

@milo-minderbinder
milo-minderbinder / build-excludes.txt
Last active March 4, 2023 06:47
global excludes file for restic
*.class
build/**/*.[jwe]ar
gems/
gradle/wrapper/*.jar
node_modules/
target/**/*.[jwe]ar
@milo-minderbinder
milo-minderbinder / pbcopyt.bash
Last active April 4, 2022 11:49
Simple drop-in alternative for `pbcopy` which wipes the clipboard contents after a set time (30 seconds by default).
#!/usr/bin/env bash
#
# Simple drop-in alternative for `pbcopy` which wipes the clipboard contents
# after a set time (30 seconds by default).
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
trap 'e=$?; if [ "$e" -ne "0" ]; then printf "LINE %s: exit %s <- %s%s\\n" "$BASH_LINENO" "$e" "${BASH_COMMAND}" "$(printf " <- %s" "${FUNCNAME[@]:-main}")" 1>&2; fi' EXIT
export SHELL = /bin/bash
MAKEFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
PYTHON_VERSION := 3
PYTHON := $(PYTHON_VERSION:%=python%)
PYTHON_ENV_TAG := $(shell .venv/bin/python -c 'import wheel.bdist_wheel as d; print(d.python_tag(), d.get_abi_tag(), d.get_platform(None), sep="-")' 2> /dev/null || printf '\e[33mWARNING\e[0m: missing python virtual environment; run "make venv" first and then retry\n' 1>&2)
REQUIREMENTS_IN := $(wildcard *requirements.in)
#REQUIREMENTS_OUT_DIR := $(MAKEFILE_DIR)
REQUIREMENTS_OUT_DIR := $(abspath $(MAKEFILE_DIR)/requirements-out)/
REQUIREMENTS_OUT := $(REQUIREMENTS_IN:%.in=$(abspath $(REQUIREMENTS_OUT_DIR)/%-$(PYTHON_ENV_TAG).txt))
#!/usr/bin/env bash
set -o errexit -o pipefail -o noclobber -o nounset
trap 'e=$?; if [ "$e" -ne "0" ]; then printf "LINE $BASH_LINENO: exit %s <- ${BASH_COMMAND}%s\\n" "$e" "$(printf " <- %s" "${FUNCNAME[@]:-main}")" 1>&2; fi' EXIT
get_summary() {
local no_color
local target_dir
@milo-minderbinder
milo-minderbinder / create-gradle-wrapper.bash
Last active September 26, 2023 19:26
Creates a Gradle wrapper in $PWD for the latest Gradle version (optionally, latest for the given major version, e.g. `./create-gradle-wrapper.bash 4` will fetch the latest Gradle 4.X wrapper).
#!/usr/bin/env bash
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
trap 'e=$?; if [ "$e" -ne "0" ]; then printf "LINE %s: exit %s <- %s%s\\n" "$BASH_LINENO" "$e" "${BASH_COMMAND}" "$(printf " <- %s" "${FUNCNAME[@]:-main}")" 1>&2; fi' EXIT
PROGNAME="${0##*/}"
contains_value() {
@milo-minderbinder
milo-minderbinder / git-diff-stat-sort.sh
Last active December 11, 2020 21:39
sort git diff --stat by total number of lines changed (now with color!) (credit to jakub-g with the original solution: https://gist.github.com/jakub-g/7599177)
#!/usr/bin/env bash
# Any additional arguments are passed through to sort command.
# For example, you can order the sort by most changes to least by running with:
# > git-diff-stat-sort -r
# To pipe the output through the "less" command while preserving coloring, you can use:
# > git-diff-stat-sort -r | less -R
# Finally, to create a global git command alias, just run the following:
# > git config --global alias.diff-stat-sort '!git diff --stat --stat-width "$(tput cols)" --color=always | sort -t "|" -n -k2'
# The above alias will allow you to run the command without having to save/run the below command as a separate script,
@milo-minderbinder
milo-minderbinder / common.bash
Last active September 26, 2023 19:18
bash-scripts
#!/usr/bin/env bash
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
trap 'e=$?; if [ "$e" -ne "0" ]; then printf "LINE %s: exit %s <- %s%s\\n" "$BASH_LINENO" "$e" "${BASH_COMMAND}" "$(printf " <- %s" "${FUNCNAME[@]:-main}")" 1>&2; fi' EXIT
PROGNAME="${0##*/}"
/**
* MIT License
*
* Copyright (c) 2018 Chris Passarello <www.insecurity.co>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
/**
* MIT License
*
* Copyright (c) 2018 Chris Passarello <www.insecurity.co>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
/**
* MIT License
*
* Copyright (c) 2018 Chris Passarello <www.insecurity.co>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is