Skip to content

Instantly share code, notes, and snippets.

mafredri /
Created Mar 9, 2017
Script to build (and update) headless Chromium on Ubuntu
#!/usr/bin/env zsh
# This script checks out the latest chromium and builds the headless
# version of it. When the chromium source is already present, the
# repository is updated.
# A .tar.gz is created in $DIR containing the headless_shell binary,
# this binary runs chromium. The resulting binary should be quite
# portable given that the (few) dependencies are installed on the target
# machine.
mafredri /
Last active Nov 8, 2017
Homebrew managed go get
# brew-go-get
# Original:
set -euo pipefail
name_to_repo() {
local name="$1"
echo "${name//--//}"
mafredri / itone.zsh
Created Aug 26, 2017
Convert mp3 to m4r (Apple Tone), limit to 39 seconds for use as iPhone ringtone
View itone.zsh
#!/usr/bin/env zsh
if (( ! ${#@} )); then
print "Convert mp3 to m4r (Apple Tone)"
print "Usage: $0 file1.mp3 file2.mp3"
exit 1
tmpdir=$(mktemp -d)
mafredri /
Last active Feb 23, 2020
Add custom SSH keys to the Ubiquiti UniFi Controller

Setting up custom SSH keys for UniFi hardware

  1. Create config.gateway.json to configure USG
  2. Create to configure switch / AP / etc...
  3. Place config.gateway.json and in data/sites/default
  4. Restart controller (maybe?)
  5. Reprovision all devices


mafredri /
Last active Oct 16, 2020
Scripts for the reMarkable tablet (backup and factory reset)
# Creates remarkable_backup-(date).tar.gz with todays date, backs up /home/root.
ssh root@ 'tar cf - .' \
| gzip >remarkable_backup-$(date '+%Y-%m-%d').tar.gz
) 2 >err.log
cat err.log
mafredri / translate-bookmarklet.js
Created Aug 11, 2018
A bookmarklet to quickly translate the current webpage using Google Translate
View translate-bookmarklet.js
View cdp_issue54.go
package main
import (
View cdp_issue45.go
// This example gives permission to access geolocation
// and fetches the current position via JavaScript.
// Tested on: cdp v0.18.7 and Chrome Canary 70.0.3532.0,
// and seems to work in both headless and headfull mode.
package main
import (
mafredri /
Last active Dec 17, 2018
gpg-yubikey-sign: Sign Git commits with any of your valid GPG subkeys
#!/usr/bin/env zsh
# gpg-yubikey-sign
# This script lets you use any of your unexpired subkeys connected to
# your public key (0xDEADBEEFCAFEBAAD) to sign git commits. It will also
# display "Waiting for YubiKey touch..." to remind you that an action is
# required.
# Add this script to your PATH and configure git to use it for gpg
# signing.
mafredri / usg_wireguard_upgrade.expect
Created Mar 1, 2019
Expect script to automate WireGuard upgrade on UniFi Security Gateway
View usg_wireguard_upgrade.expect
#!/usr/bin/env expect -f
# Description: Expect script to automate WireGuard upgrade on UniFi Security Gateway
# Author: Mathias Fredriksson <>
# This script assumes non-interactive ssh login.
# Usage upgrade.expect <[user@]usg> <${RELEASE}/wireguard-${BOARD}-${RELEASE}.deb>
set timeout 60