Skip to content

Instantly share code, notes, and snippets.

@n-st
n-st / pre-commit
Created August 9, 2015 13:07
Git pre-commit hook: Reject commit if a DNS zone file has been changed without changing its SOA serial. The serial needs to be on a separate line that contains ' ; serial'.
#!/bin/bash
# Check if all changed zone files have had their SOA serial incremented.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
@n-st
n-st / he-tunnelserver-ping.sh
Last active January 2, 2022 07:04
Check and compare ping times for all Hurricane Electric (tunnelbroker.net) IPv6 tunnel servers.
#!/bin/bash
tunservers="Hong_Kong,_HK:216.218.221.6 Singapore,_SG:216.218.221.42 Tokyo,_JP:74.82.46.6 Amsterdam,_NL:216.66.84.46 Berlin,_DE:216.66.86.114 Budapest,_HU:216.66.87.14 Frankfurt,_DE:216.66.80.30 London,_UK:216.66.80.26 Paris,_FR:216.66.84.42 Prague,_CZ:216.66.86.122 Stockholm,_SE:216.66.80.90 Warsaw,_PL:216.66.80.162 Zurich,_CH:216.66.80.98 Ashburn,_VA,_US:216.66.22.2 Chicago,_IL,_US:184.105.253.14 Dallas,_TX,_US:184.105.253.10 Denver,_CO,_US:184.105.250.46 Fremont,_CA,_US:72.52.104.74 Fremont,_CA,_US:64.62.134.130 Kansas_City,_MO,_US:216.66.77.230 Los_Angeles,_CA,_US:66.220.18.42 Miami,_FL,_US:209.51.161.58 New_York,_NY,_US:209.51.161.14 Seattle,_WA,_US:216.218.226.238 Toronto,_ON,_CA:216.66.38.58 Winnipeg,_MB,_CA:184.105.255.26"
tunserver_array=($tunservers)
tunserver_count=${#tunserver_array[@]}
i=1
(
echo -e "Location\tIP\tmin\tavg\tmax\tmdev"
(
@n-st
n-st / scrub-eta.sh
Last active April 29, 2017 14:35
Quick'n'dirty script to display the progress and ETA of a running btrfs scrub
#!/bin/zsh
# usage: $0 <path being scrubbed>
set -e
# adapted from my own oneliner script at http://www.commandlinefu.com/commands/view/12621/
format_filesize () {
printf "%d" $1 | awk 'function hr(bytes){hum[1024**4]="TiB";hum[1024**3]="GiB";hum[1024**2]="MiB";hum[1024]="kiB";for(x=1024**4;x>=1024;x/=1024){if(bytes>=x){return sprintf("%8.3f %s",bytes/x,hum[x]);}}return sprintf("%4d B",bytes);}{print hr($1) "\t" $2}'
}
@n-st
n-st / pianobar-notify-send.sh
Last active August 29, 2015 14:02
Display title, artist and station via the default notification tool when pianobar starts playing a new song.
#!/bin/bash
# Modify the following line for your system and add it to your pianobar config
# (usually ~/.config/pianobar/config):
# event_command = /home/johndoe/bin/pianobar-event.sh
[ "$1" = "songstart" ] || exit 0
while read line
do
@n-st
n-st / intcat.py
Last active August 29, 2015 14:01
"interval cat": print every n-th character received on stdin
#!/usr/bin/env python
# intcat = interval cat:
# Prints a human-readable character for every n-th character received on stdin.
# Throughput depends heavily on n (faster for larger n).
n = 1000000
import sys, os
@n-st
n-st / README
Last active August 29, 2015 14:01
TARDIS Cloister Bell clock/alert script
Usage:
./tardis-bell.sh [ clock | <number of chimes> ]
This script requires the 'play' command and accompanying mp3 format plugin from
Sound eXchange (sox).
The sound used is a shortened version of the Doctor Who TARDIS Cloister Bell
from http://dannystewart.com/2009/09/01/doctor-who-ringtones.
@n-st
n-st / update-all.sh
Last active August 29, 2015 13:57
Quickly update multiple remote Debian/Ubuntu systems.
#!/bin/bash
# Uncomment the next line to start any pending updates automatically:
#yes="--yes"
for host in host1 host2 # etc.
do
echo -e "\e[0;33m$host\e[0m"
ssh "$host" -t "
@n-st
n-st / dont-blink.sh
Created March 10, 2014 23:38
Disable blinking "heartbeat" LED on BeagleBone Black. (Requires root privileges.)
% Lorenz curve
% by n.st, originally created on 2014-02-08
% based on
% - http://www.texample.net/tikz/examples/line-plot-example/
% - http://tex.stackexchange.com/a/51766
\documentclass[crop,tikz,convert={outext=.svg,command=\unexpanded{pdf2svg \infile\space\outfile}},multi=false]{standalone}
\usepackage[utf8]{inputenc}
@n-st
n-st / replace-master-branch.sh
Created February 8, 2014 17:19
Merge 'dev' into 'master', discarding the state of 'master'. Created by https://gist.github.com/ojacobson/.
git commit-tree dev^{tree} -p master -p dev <<'MESSAGE'
Replace master with dev branch.
MESSAGE