Skip to content

Instantly share code, notes, and snippets.

@bjorne
bjorne / 00_README.md
Created July 20, 2018 21:27
Equivalent binary trees

From the Go tour. Only supports trees of size 10 for now.

@bjorne
bjorne / rot13.go
Created July 19, 2018 19:52
rot13 from the Go tour
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
@bjorne
bjorne / _README.md
Last active December 23, 2020 07:47
Command-click to open in emacs from iTerm

@bjorne
bjorne / cycle.as
Created October 22, 2015 09:16
Cycle Safari Windows
tell application "Safari"
set theWindows to windows
set win1 to item 1 of theWindows
set win2 to item 2 of theWindows
repeat
tell win1
set index to 1
set visible to false
set visible to true
end tell
@bjorne
bjorne / widen-github.js
Created September 24, 2015 09:49
Widen Github Diffs. Useful when violators of 80 character lines are in action.
// ==UserScript==
// @name Widen Github
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match https://github.com/*
// @copyright 2012+, You
// ==/UserScript==
var containerWidth = $('.container').css('width');
@bjorne
bjorne / README.md
Last active December 16, 2015 16:28
Node April Fools Proxy

April Fools Proxy

A vanilla node proxy that gives webpages a treat.

Clone this gist and simply run node index.js. Then configure 127.0.0.1:8484 as a proxy and you're good to go.

Have fun and be sure to report any pranks!

@bjorne
bjorne / angular-snippet.js
Created April 23, 2013 19:27
angular source code pearl
// Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
switch (self ? -1 : args.length) {
case 0: return fn();
case 1: return fn(args[0]);
case 2: return fn(args[0], args[1]);
case 3: return fn(args[0], args[1], args[2]);
case 4: return fn(args[0], args[1], args[2], args[3]);
case 5: return fn(args[0], args[1], args[2], args[3], args[4]);
case 6: return fn(args[0], args[1], args[2], args[3], args[4], args[5]);
case 7: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
@bjorne
bjorne / free-keys.el
Created September 27, 2012 21:35
Show free key bindings in Emacs (for the current mode)
(setq free-keys-modifiers (list "C" "M" "C-M"))
(setq free-keys-keys "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,/§1234567890-=[];'\\`±!@#$%^&*()_+}{:\"|?><~")
(defun free-keys ()
(interactive)
(let ((buf (get-buffer-create "*Free keys*")))
(display-buffer buf)
(with-current-buffer buf
(erase-buffer)
(mapc (lambda (modifier)
@bjorne
bjorne / take-photo.sh
Created July 13, 2012 10:55
Take a photo using Cinema Display camera if present, built-in otherwise
#!/bin/bash
dir="$HOME/Documents/commit-photos"
if [[ ! -d $dir ]]; then
mkdir -p $dir
fi
f=`echo \`date "+%Y%m%d-%H%M%S"\``
device=`imagesnap -l | grep -v "Video Devices:" | head -n 1`
@bjorne
bjorne / beautydiff
Created June 15, 2012 08:04
Diff compressed Javascript files by beautifying them first
#!/bin/bash
UGLIFY=`which uglifyjs`
ARGS="--beautify"
F1=/tmp/$RANDOM
F2=/tmp/$RANDOM
cat $1 | $UGLIFY $ARGS > $F1
cat $2 | $UGLIFY $ARGS > $F2