Skip to content

Instantly share code, notes, and snippets.

View mafredri's full-sized avatar

Mathias Fredriksson mafredri

View GitHub Profile
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
"github.com/mafredri/cdp"
@mafredri
mafredri / translate-bookmarklet.js
Created August 11, 2018 10:03
A bookmarklet to quickly translate the current webpage using Google Translate
javascript:(function(){window.location='https://translate.google.com/translate?sl=auto&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&edit-text=&u='+encodeURIComponent(window.location.href)})();void(0);

Keybase proof

I hereby claim:

  • I am mafredri on github.
  • I am mafredri (https://keybase.io/mafredri) on keybase.
  • I have a public key ASAcL0fP34_ZPvJ6-aV3RbVAF8TYNpudE2uPwkxbOw2KIgo

To claim this, I am signing this object:

@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 / check_connection.sh
Last active May 22, 2017 01:57
Upgrade WiFi AP (e.g on OpenWRT) when there is a stronger BSSID in vicinity (based on signal strength). Useful when you are a member of a SSID which has multiple APs under the same SSID but you don't want to commit to only one BSSID.
#!/bin/sh
COUNT=0
LIMIT=5
INTERFACE=wlan1
NAME=$(basename $0)
CLEAN_NAME=${NAME%.sh}
PID="/var/run/$CLEAN_NAME.pid"
LOGGER="logger -t $CLEAN_NAME -s"
@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())
}