Skip to content

Instantly share code, notes, and snippets.

@arnehormann
arnehormann / keycodes.html
Last active October 13, 2015 07:57
javascript keycode finder
<!DOCTYPE html>
<html><head><meta charset="utf-8"><!--
Ok, let me be honest here…
DISCLAIMER:
I drew inspiration and a little CSS from the now defunct
http://whatthekeycode.com/
Still, it's different in a lot of ways.
@arnehormann
arnehormann / iproute2-examples.sh
Last active October 11, 2015 15:28
iproute2 example
# For these...
HOST="1.2.3.4/24"
NET="1.2.3.0/24"
GATEWAY_IP="1.2.3.1"
# Set a static IP
ip addr add $HOST dev eth0
ip route add $NET via $GATEWAY_IP
ip link set eth0 up
@arnehormann
arnehormann / escapeHtml.js
Last active October 11, 2015 09:38
escape text for inclusion by innerHTML as one handy fully namespaced function
var escapeHTML = (function() {
var regexp = /[<>&'"\/]/g
, replacements =
{ '&': '&amp;'
, '<': '&lt;'
, '>': '&gt;'
, '/': '&#x2F;'
, '"': '&quot;'
, "'": '&#39;'
}
@arnehormann
arnehormann / spliceRevertable.js
Created February 19, 2012 16:41
Splice an array - with undo
function spliceRevertable() {
var self = this
, revertArray = [arguments[0], arguments.length - 2]
, result = revertArray.splice.apply(this, arguments)
, revertArguments = revertArray.concat(revertArray.slice.call(arguments, 2))
result.revert = funtion() {
return revertArguments.splice.apply(self, revertArguments)
}
return result
}
@arnehormann
arnehormann / compress.go
Last active August 29, 2015 14:26
Check speed and compression of `compress/flate` and `compress/gzip` against the `github.com/klauspost/compress` variants. Please read the comment below!
package main
import (
"encoding/binary"
"flag"
"fmt"
"io"
"os"
"runtime"
"sort"
@arnehormann
arnehormann / sqlassist.go
Last active August 29, 2015 14:11
go sql helper
import (
"database/sql"
"fmt"
"reflect"
)
type Field interface {
Name() string
Ptr() interface{}
Tags() string
@arnehormann
arnehormann / int-ranges.go
Created December 4, 2014 09:26
Support code for tests in confactor/envflags
package main
import (
"fmt"
"io"
"math/big"
"os"
)
func generateIntBounds(w io.Writer) {
@arnehormann
arnehormann / envflag-example.go
Last active August 29, 2015 14:10
Just an example for envflag (soon to be expanded at github.com/confactor/envflag)
// see http://godoc.org/github.com/arnehormann/goof/envflag
package main
import (
"fmt"
"io"
"os"
"sort"
"strings"
"text/tabwriter"
package main
import (
"errors"
"fmt"
"os"
"time"
pipe "gopkg.in/pipe.v2"
)
@arnehormann
arnehormann / repostats.sh
Created June 13, 2014 09:42
count LOC in .git folders per language
#!/bin/bash
set -e -u -o pipefail # -x
echo $'Project\tCommit\tBranch\tFiletype\tLines'
for dir in *.git; do
export GIT_DIR="$dir"
export PREFIX=$(git for-each-ref --count=1 --sort=committerdate --format=$'%(objectname)\t%(refname)')
export BRANCH=$(echo -e "${PREFIX}" | cut -d $'\t' -f 1)
##### from these filetypes #####
for filetype in java cs rb go py as php html htm css js json xml conf cnf; do
echo -n -e "${dir}\t${PREFIX}\t${filetype}\t"