Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Martin Kealey kurahaupo

🏠
Working from home
  • Brisbane, Australia
View GitHub Profile
View transcode.bash
#!/bin/bash
shopt -s globstar
sdir=$HOME/Documents/website
tdir=$HOME/tmp/transcoded-website
scode=WINDOWS-1252
tcode=UTF-8
mkdir -vp "$tdir"
@kurahaupo
kurahaupo / xterm-colourtest
Created Jan 10, 2016
Xterm Colour test pattern
View xterm-colourtest
#!/usr/bin/perl
use 5.008;
use strict;
use warnings;
use Getopt::Long qw(:config bundling);
use POSIX qw( floor );
use utf8;
@kurahaupo
kurahaupo / chresolvconf
Created Jan 14, 2015
Manually change /etc/resolv.conf but protect it from meddling by NetworkManager et al
View chresolvconf
#!/bin/bash
# Update /etc/resolv.conf but keep it unwritable, even by root-owned processes.
# Useful to stop WiFi and/or DHCP from messing with it, and quite essential when
# there are multiple managers for different interface types.
#
# Because symlinks don't work, instead we bind-mount an appropriate file onto
# /etc/resolv.conf, chosen from those in ~/.resolvconf.d/.
#
# Since BIND is running locally, almost all the time that will work, so it's the
@kurahaupo
kurahaupo / xr
Last active Nov 25, 2021
Script using "xrandr" to configure multi-head display
View xr
#!/bin/bash
die() { echo "$*" >&2 ; exit 1 ; }
declare -a R=( normal right inverted left ) # rotation descriptions
declare -A S
declare -A DX
declare -a EX
@kurahaupo
kurahaupo / twelve-days-of-christmas.bash
Last active Aug 29, 2015
twelve days of christmas, in bash
View twelve-days-of-christmas.bash
#!/path/to/your/bash
dox=( [1]='a partridge in a pair tree'
'2 turtle doves, and'
'3 french hens'
'4 calling birds'
$'5 gold rings\n ...'
'6 geese a-laying'
'7 swans a-swimming'
'8 maids a-milking'
View example of bash aliases inside functions
$ alias randomly='if ((RANDOM%2)) ; then'
$ dorand() { randomly print Hi ; fi ; }
$ type dorand
dorand is a function
dorand ()
{
if ((RANDOM%2)); then
print Hi;
fi
}
@kurahaupo
kurahaupo / shorten-symlinks
Created Jan 7, 2014
Convert absolute symbolic links (those whose target starts with /) to be relative (to their containing directory). Written for Linux, but will work anywhere that has `readlink -m` and `ln -T` (the GNU versions do).
View shorten-symlinks
@kurahaupo
kurahaupo / wideascii
Created Jan 3, 2014
Convert normal ascii to equivalent double-width unicode characters
View wideascii
#!/usr/bin/perl
use utf8;
binmode STDOUT, ":utf8";
while (<>) {
s/ / /g;
s/\t/\t\t/g;
s/[!-~]/chr(ord($&)+0xff00-0x20)/xge;
print $_;
@kurahaupo
kurahaupo / foo
Last active Jun 21, 2022
There's no excuse for using #!/usr/bin/env ...
@kurahaupo
kurahaupo / siginfo
Last active Dec 29, 2015
Show signal names from Sig* lines in Linux's /proc/$PID/status
View siginfo
#!/bin/bash
pid=${1:-$PPID}
signals="$(trap -l)"
declare -A SIG
for s in ${signals//') '/=}
do
i=${s%%=*}