Skip to content

Instantly share code, notes, and snippets.

View mafredri's full-sized avatar

Mathias Fredriksson mafredri

View GitHub Profile
@mafredri
mafredri / README.md
Last active February 23, 2020 13:29
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 config.properties to configure switch / AP / etc...
  3. Place config.gateway.json and config.properties in data/sites/default
  4. Restart controller (maybe?)
  5. Reprovision all devices

Resources

@mafredri
mafredri / itone.zsh
Created August 26, 2017 07:17
Convert mp3 to m4r (Apple Tone), limit to 39 seconds for use as iPhone ringtone
#!/usr/bin/env zsh
if (( ! ${#@} )); then
print "Convert mp3 to m4r (Apple Tone)"
print
print "Usage: $0 file1.mp3 file2.mp3"
exit 1
fi
tmpdir=$(mktemp -d)
@mafredri
mafredri / brew-go-get.sh
Last active August 29, 2021 17:16
Homebrew managed go get
#!/bin/bash
# brew-go-get
# Original: https://blog.filippo.io/cleaning-up-my-gopath-with-homebrew/
set -euo pipefail
name_to_repo() {
local name="$1"
name="${name/go-get-}"
echo "${name//--//}"
@mafredri
mafredri / build_chromium_headless.sh
Created March 9, 2017 16:09
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
mafredri / set_variable_performance_test.result.log
Last active January 12, 2017 14:13
Quick performance test for setting a variable via capturing output to sub-shell vs a typeset in the running function
=== RUN test_bench_print_subshell_05
--- PASS: test_bench_print_subshell_05 (0.02s)
=== RUN test_bench_print_subshell_10
--- PASS: test_bench_print_subshell_10 (0.02s)
=== RUN test_bench_print_subshell_100
--- PASS: test_bench_print_subshell_100 (0.14s)
=== RUN test_bench_print_subshell_1000
--- PASS: test_bench_print_subshell_1000 (0.79s)
=== RUN test_bench_typeset_var_05
--- PASS: test_bench_typeset_var_05 (0.00s)
@mafredri
mafredri / benchmark.log
Last active January 9, 2017 07:08
Benchmark opening new zpty instances vs keeping a long running one (zsh-async) for executing asynchronous tasks
Start async job (async_job):
1: 0.00011992
2: 0.00011015
3: 0.00010586
4: 0.00010514
5: 0.00022697
6: 0.00013900
7: 0.00010586
8: 0.00010395
9: 0.00011015
@mafredri
mafredri / phoenix-amd-loader.js
Created May 8, 2016 17:52
Fake AMD module loader for kasper/phoenix (tested with TypeScript + outFile)
/**
* Fake AMD-style modules for kasper/phoenix
*
* Works when compiling TypeScript with a single outfile and AMD modules.
*/
(function (global, require) {
var defines = {},
defQueue = [];
global.require = function (mod) {
@mafredri
mafredri / main.go
Created February 13, 2016 12:58
tealeg/xlsx PR #149 breaking change demonstration
package main
import "github.com/tealeg/xlsx"
func main() {
file := xlsx.NewFile()
sheet, err := file.AddSheet("Sheet1")
if err != nil {
panic(err.Error())
}
@mafredri
mafredri / zsh-git.rb.patch
Created August 10, 2015 22:27
Install zsh HEAD from git through Homebrew
diff --git a/Library/Formula/zsh.rb b/Library/Formula/zsh.rb
index e7e67a5..4dff75e 100644
--- a/Library/Formula/zsh.rb
+++ b/Library/Formula/zsh.rb
@@ -5,8 +5,11 @@ class Zsh < Formula
mirror "http://www.zsh.org/pub/zsh-5.0.8.tar.bz2"
sha256 "8079cf08cb8beff22f84b56bd72bb6e6962ff4718d816f3d83a633b4c9e17d23"
+ head "https://github.com/zsh-users/zsh.git"
+
@mafredri
mafredri / pure_benchmark.zsh
Created July 22, 2015 21:14
Benchmarking modifications to prompt pure
#!/usr/bin/env zsh
BRANCH=$1
BRANCHES=(master pure-nitro pure-nitro2)
BENCHDIR=benchmark
ROUNDS=100
if [[ ! -n $BRANCH ]]; then
[[ ! -d $BENCHDIR ]] && mkdir $BENCHDIR
for i in $BRANCHES; do