Skip to content

Instantly share code, notes, and snippets.

Avatar

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
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
@StefanHamminga
StefanHamminga / compile++.sh
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
View compile++.sh
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 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)
View print-png-label-to-networked-brother-label-printer.sh
# 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 Jul 2, 2016
piplay - Raspberry Pi Omxplayer wrapper script with support for wildcards, streaming (YouTube, etc) and skipping of played files.
View piplay
#!/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
Pi2 to Pi2 Debian bootstrap notes / script
View rpi2-bootstrap.sh
#!/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 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
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 <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 Jan 26, 2016
Bash script to detect whether two paths/files are in the same file system
View same_fs.sh
#!/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 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
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.