Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 0xfat-30.sh
Created October 16, 2015 01:25
Solution for 0xf.at level 30 (https://www.0xf.at/play/30/)
#!/bin/bash
# Solution for 0xf.at level 30 (https://www.0xf.at/play/30/)
# solved in 49 minutes, 54 seconds
# This script expects the filename of the downloaded challenge image as its only parameter and will output the correct answer string.
# To prevent cheating, this version of the script has been modified in a few subtle ways so it will output an incorrect answer.
# Development process:
# - Use imagemagick to split input image into 40x40 px blocks
@n-st
n-st / view-on-archive-org.js
Created February 28, 2016 16:20
Bookmarklet to view current page on the Internet Archive Wayback Machine (https://archive.org/)
javascript:(function(){if(location.href.indexOf('http')!=0){input=prompt('URL:','http://');if(input!=null){location.href='http://web.archive.org/web/*/'+input}}else{location.href='http://web.archive.org/web/*/'+location.href;}})();
@n-st
n-st / qr.js
Created February 28, 2016 16:28
Bookmarklet to generate a QR code containing the URL of the current page. Can also generate QR codes with arbitrary content when executed from an empty browser tab or called via a bookmark shortcut keyword.
javascript:void(function(){if('%s'.length>2){window.open('http://qr.kaywa.com/?s=8&d='+escape('%s'))}else{if(document.location.href.indexOf('http')!=0){t=prompt('Enter%20QR%20code%20content:','http://');if(t!=null){document.location.href='http://qr.kaywa.com/?s=8&d='+escape(t)}}else{window.open('http://qr.kaywa.com/?s=8&d='+escape(document.location.href))}}}());
@n-st
n-st / sort-gitconfig.sh
Created March 24, 2016 21:51
Sort the sections of a Git config file (and the contents of the sections) alphabetically
awk '{ if ($1 ~ /^\[/) { section=$0; print $0 } else { printf section; print $0 } }' gitconfig | sort -t ']' -k1,1 | sed 's/\[.\+\]\([^\s]\+\)/\1/' > gitconfig.new
mv gitconfig.new gitconfig
@n-st
n-st / .bash_profile
Created May 29, 2016 12:04
Start zsh from bashrc. Useful when you can't use chsh or when the same LDAP account is used both on systems with zsh installed and ones without.
# .bash_profile is executed for login shells,
# .bashrc is executed for interactive non-login shells.
# We want the same behaviour for both, so we source .bashrc from .bash_profile.
# Also, when .bash_profile exists, bash ignores .profile, so we have to source
# it explicitly.
if [ -f "$HOME/.profile" ]; then
. "$HOME/.profile"
fi
@n-st
n-st / ipv6-slash64.md
Last active March 4, 2017 18:19
IPv6. You're doing it wrong.

IPv6. You're doing it wrong.

If you're reading this, you've probably been called out on assigning unreasonably small IPv6 subnets or even individual IPv6 addresses to your customers.
Here's why you should reconsider and assign a separate /64 subnet to each customer:

@n-st
n-st / Arubacloud.DC2-IT-Arezzo.txt
Last active April 5, 2017 20:20
Arubacloud benchmarks
-------------------------
nench.sh benchmark
2017-02-25 21:06:15 UTC
-------------------------
Processor: Intel(R) Xeon(R) CPU E5-2650L v4 @ 1.70GHz
CPU cores: 1
Frequency: 1698.925 MHz
RAM: 509M
Swap: