Skip to content

Instantly share code, notes, and snippets.


Stefan Hamminga StefanHamminga

View GitHub Profile
View grub.cfg
# HiKey970 grub config enabling "grub-reboot 'Experimental kernel'" to one-time boot testing kernels.
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
StefanHamminga /
Created Nov 21, 2017
Bash function to build, sanitise, debug and PGO profile a single source C++ file such as a (header-only) library test file
function compile++ {
local outfn="${1%.*}"
ionice -c 3 \
nice -n 19 \
g++ \
-std=gnu++17 \
-pipe \
-march=haswell \
-mtune=skylake \
-O3 \
StefanHamminga /
Created Dec 22, 2016
Bash function to print black and white PNG (and JPEG, GIF, BMP) files to a networked Brother label printer (such as the QL-720NW)
# Print a black and white PNG file on the first available Brother label printer
# Requires
# Source (.) this file to set bash completion and add the print function.
function print-png-label() {
if [ -f "$1" ]; then
# Change these to match your printer:
local LBLPMODEL="QL-720NW"
local LBLPSIZE="62"
StefanHamminga / piplay
Last active Jul 2, 2016
piplay - Raspberry Pi Omxplayer wrapper script with support for wildcards, streaming (YouTube, etc) and skipping of played files.
View piplay
# piplay - Raspberry Pi Omxplayer wrapper script.
# Required packages on Debian: omxplayer youtube-dl attr
# TODO / future plans: Use the D-Bus interface to store media playback position and resume from there.
REQUIREMENTS=(omxplayer youtube-dl find sort getfattr setfattr nice ionice)
# Subtitle languages, in order of preferences. Format: movie.mkv & => en
SUBTITLELANGUAGES=( nl nld dut en eng )
StefanHamminga /
Last active May 14, 2016
Pi2 to Pi2 Debian bootstrap notes / script
#!/bin/bash -e
echo "WARNING: Read and edit this before you run! Needs root privileges."
exit 1
apt install debootstrap hdparm sdparm
StefanHamminga / flat-object-to-key-value-string.js
Last active Apr 9, 2016
One liner flat object to key="value" conversion in ES6/ES2015 JavaScript
View flat-object-to-key-value-string.js
// Any flat object with enumerable properties
var properties = {
id: "myid",
value: "myvalue"
// This prepends a space to each key. If you only need separators between add them in the join.
// ↓ ↓
var string = Object.keys(properties).map(function(n){return ` ${n}="${properties[n]}"`;}).join("");
// ' id="myid" value="myvalue"'
StefanHamminga / gist
Last active Apr 24, 2016
Wrapper script for GitHub Gist repositories. Allows keeping multiple Gist files in one directory and one command updates.
View gist
#!/bin/bash -e
# gist - GitHub Gist tool.
# Created by Stefan Hamminga <>. Use any of these licenses: MIT,
# GPL v2.0 or higher, LGPL v2 or higher, or CC BY-4.0.
# Repository:
usage() {
echo -e "
\e[1mgist\e[0m - Wrapper script for GitHub Gist repositories. Allows keeping multiple
StefanHamminga /
Last active Jan 26, 2016
Bash script to detect whether two paths/files are in the same file system
MOUNTS=`cat /proc/mounts | cut -d ' ' -f 2 | sort | uniq | tr '/' '\\/'`
what_fs() {
for MOUNT in ${MOUNTS}; do
readlink -f $1 | grep -o "^${MOUNT}"
# echo -e "$1"
# echo -e "${MOUNT}"
StefanHamminga / connectedTo
Last active Jan 26, 2016
Bash script to test if connected to a specific network and (optionally) if a given host is available on said network. Useful for cron / automated scripts.
View connectedTo
#!/bin/bash -e
if [ $# -lt 1 ]; then
echo -e "
Connection and host availability test
Usage:\n$0 'My network name' [ip_or_hostname] && command_to_run_when_available
The network name needs to be quoted and as Network Manager reports it. Try
'nmcli c show'.
StefanHamminga / rsync-skip-compress
Last active May 28, 2020
List of compressed file formats for use with Rsync --skip-compress=$RSYNC_SKIP_COMPRESS
View rsync-skip-compress
export RSYNC_SKIP_COMPRESS=3g2/3gp/3gpp/7z/aac/ace/amr/apk/appx/appxbundle/arc/arj/asf/avi/bz2/cab/crypt5/crypt7/crypt8/deb/dmg/drc/ear/gz/flac/flv/gpg/iso/jar/jp2/jpg/jpeg/lz/lzma/lzo/m4a/m4p/m4v/mkv/msi/mov/mp3/mp4/mpeg/mpg/mpv/oga/ogg/ogv/opus/pack/png/qt/rar/rpm/rzip/s7z/sfx/svgz/tbz/tgz/tlz/txz/vob/wim/wma/wmv/xz/z/zip/zst
You can’t perform that action at this time.