Skip to content

Instantly share code, notes, and snippets.

package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"log"
@jstangroome
jstangroome / log.go
Last active April 5, 2023 22:48
Adapter to enable gradual migration from hashicorp/logutils to uber/zap
import (
"io"
"regexp"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Replaces hashicorp/logutils by directing Golang's log package to Zap but
// extracting the log level from any `[$severity]` pattern in the message.
@jstangroome
jstangroome / set-drag.ps1
Created June 17, 2020 10:27
Change the mouse drag distance required to initiate a drag operation, e.g. moving files in Explorer
param (
[int]$drag = 4
)
# https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
$importDefinition= @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
'@
$importType = Add-Type -MemberDefinition $importDefinition -Name WinAPICall -Namespace SetDragSystemParametersInfo –PassThru
@jstangroome
jstangroome / docker-content-tag.sh
Created April 18, 2020 11:43
Generate a tag derived from the inputs to a Docker image, without needing to build the image itself.
#!/bin/bash
cat <<'EOF' >.dockerfile.content-tag
FROM busybox:1
WORKDIR /src/
ENTRYPOINT ["/bin/sh", "-c", "find . -type f \\! -path ./.dockerfile.content-tag -exec sha256sum -b {} +"]
COPY . /src/
EOF
iid=$( docker image build -q -f .dockerfile.content-tag . )
@jstangroome
jstangroome / kubectl-evict
Created March 4, 2020 12:14
kubectl evict in bash
#!/bin/bash
print_usage () {
printf 'Usage: kubectl evict -n <namespace> <pod>\n' >&2
}
main () {
if [ "-n" != "$1" ] && [ "--namespace" != "$1" ]
then
print_usage
@jstangroome
jstangroome / install.sh
Created April 13, 2019 02:22
WSL useful extra packages
apt-get install -y \
apt-transport-https \
binutils \
build-essential \
python-pip \
socat \
sysstat \
traceroute \
unzip \
zip
@jstangroome
jstangroome / find-long-commit-messages.sh
Created January 30, 2019 04:39
Find long commit messages
#!/bin/bash
while read -r commit_hash
do
message=$(
git cat-file commit "${commit_hash}" |
sed '1,/^$/d'
)
if [ "${message:0:5}" = 'Merge' ] || [ "${message:0:6}" = 'Revert' ]
@jstangroome
jstangroome / collect_usage_in_bytes.sh
Created January 2, 2019 04:33
Create a CSV of each cgroup's memory.usage_in_bytes and some related memory.stat values.
#!/bin/bash
printf '%s,%s,%s,%s,%s,%s,%s,%s\n' \
'dir' 'usage_in_bytes' \
'cache' 'total_cache' \
'rss' 'total_rss' \
'rss_huge' 'total_rss_huge'
cd /sys/fs/cgroup/memory/
@jstangroome
jstangroome / collect_usage_in_bytes.sh
Created January 2, 2019 04:33
Create a CSV of each cgroup
#!/bin/bash
printf '%s,%s,%s,%s,%s,%s,%s,%s\n' \
'dir' 'usage_in_bytes' \
'cache' 'total_cache' \
'rss' 'total_rss' \
'rss_huge' 'total_rss_huge'
cd /sys/fs/cgroup/memory/
@jstangroome
jstangroome / script.sh
Created August 21, 2018 08:19
Rewrite your Windows .kube/config to be usable by Linux kubectl inside WSL
#!/bin/bash
win_profile_dir=$(wslpath "$(cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')")
win_dot_kube_dir="${win_profile_dir}/.kube"
win_kube_config="${win_dot_kube_dir}/config"
wsl_dot_kube_dir="${HOME}/.kube"