Skip to content

Instantly share code, notes, and snippets.

View StefanHamminga's full-sized avatar

Stefan Hamminga StefanHamminga

View GitHub Profile
# HiKey970 grub config enabling "grub-reboot 'Experimental kernel'" to one-time boot testing kernels.
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
@StefanHamminga
StefanHamminga / compile++.sh
Created November 21, 2017 07:50
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
StefanHamminga / print-png-label-to-networked-brother-label-printer.sh
Created December 22, 2016 14:41
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 https://github.com/pklaus/brother_ql
# 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
StefanHamminga / piplay
Last active November 18, 2020 06:17
piplay - Raspberry Pi Omxplayer wrapper script with support for wildcards, streaming (YouTube, etc) and skipping of played files.
#!/bin/bash
# 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 & movie.en.srt => en
SUBTITLELANGUAGES=( nl nld dut en eng )
@StefanHamminga
StefanHamminga / rpi2-bootstrap.sh
Last active May 14, 2016 09:58
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
SD=/dev/sdb
BASEDIR="."
TARGETDIR="rpi-img"
@StefanHamminga
StefanHamminga / flat-object-to-key-value-string.js
Last active April 9, 2016 11:05
One liner flat object to key="value" conversion in ES6/ES2015 JavaScript
// 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
StefanHamminga / gist
Last active April 24, 2016 12:20
Wrapper script for GitHub Gist repositories. Allows keeping multiple Gist files in one directory and one command updates.
#!/bin/bash -e
# gist - GitHub Gist tool.
# Created by Stefan Hamminga <stefan@prjct.net>. Use any of these licenses: MIT,
# GPL v2.0 or higher, LGPL v2 or higher, or CC BY-4.0.
# Repository: https://gist.github.com/44233d48eeff4c510829.git
usage() {
echo -e "
\e[1mgist\e[0m - Wrapper script for GitHub Gist repositories. Allows keeping multiple
@StefanHamminga
StefanHamminga / same_fs.sh
Last active January 26, 2016 21:52
Bash script to detect whether two paths/files are in the same file system
#!/bin/bash
MOUNTS=`cat /proc/mounts | cut -d ' ' -f 2 | sort | uniq | tr '/' '\\/'`
IFS=$'\n'
what_fs() {
for MOUNT in ${MOUNTS}; do
readlink -f $1 | grep -o "^${MOUNT}"
# echo -e "$1"
# echo -e "${MOUNT}"
@StefanHamminga
StefanHamminga / connectedTo
Last active January 26, 2016 21:46
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.
#!/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
StefanHamminga / rsync-skip-compress
Last active September 8, 2023 05:17
List of compressed file formats for use with Rsync --skip-compress=$RSYNC_SKIP_COMPRESS
export RSYNC_SKIP_COMPRESS=3g2/3gp/3gpp/3mf/7z/aac/ace/amr/apk/appx/appxbundle/arc/arj/asf/avi/br/bz2/cab/crypt5/crypt7/crypt8/deb/dmg/drc/ear/gz/flac/flv/gpg/h264/h265/heif/iso/jar/jp2/jpg/jpeg/lz/lz4/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/webm/webp/wim/wma/wmv/xz/z/zip/zst