Skip to content

Instantly share code, notes, and snippets.

View seh's full-sized avatar

Steven E. Harris seh

View GitHub Profile
@seh
seh / benchmarks.txt
Created February 13, 2017 19:16
Decimal length of a nonnegative integer
go test -run=NONE -bench=.
BenchmarkDecimalByDecay-8 50000000 32.7 ns/op
BenchmarkDecimalByDecay2-8 50000000 30.5 ns/op
BenchmarkDecimalByRecursiveDecay-8 20000000 84.5 ns/op
BenchmarkDecimalByLogarithmFloor-8 30000000 46.5 ns/op
BenchmarkDecimalByLogarithmCeiling-8 30000000 45.2 ns/op
BenchmarkDecimalByLinearTableScan-8 100000000 17.9 ns/op
BenchmarkDecimalByLinearTableScan2-8 100000000 18.6 ns/op
BenchmarkDecimalByBinaryTableSearch-8 50000000 27.9 ns/op
BenchmarkDecimalByManualBinarySearch-8 200000000 6.51 ns/op
@seh
seh / errors.go
Created September 28, 2016 18:15
Helper functions for interpreting fargo errors
package fargo
import (
"net/http"
"github.com/hudl/fargo"
)
// errorBoreHTTPStatusCode returns true if the supplied error originated from an HTTP response
// bearing the given HTTP status code.
@seh
seh / mode.go
Created November 20, 2013 20:00
A function to find the count of the mode in a potentially multimodal data set.
// Package mode provides functions related to the statistical mode of
// a set of data, the mode being the value that occurs most frequently
// in such a set.
package mode
import "sort"
func sortedIntsFrom(input []int) []int {
// Don't bother with sort.IntsAreSorted().
sorted := make([]int, len(input))
@seh
seh / underline-current.el
Created October 20, 2013 18:12
Emacs Lisp function to "underline" the current line.
;; a la Graham's "On Lisp"
(defmacro nonzero-bind (var exp &rest body)
`(let ((,var ,exp))
(unless (zerop ,var)
,@body)))
(defun underline-current (&optional str)
"Insert multiple copies of STR under and of same width as current line.
The default underline string is =.
@seh
seh / lisp.el
Created September 3, 2013 02:04
My current SLIME configuration.
;:* lisp.el
;:*=======================
(defmacro make-key-inserter (def)
"Substitute for `self-insert-command'."
`(lambda (arg)
(interactive "*P")
(insert-char ,def (prefix-numeric-value arg))))
(define-key lisp-mode-shared-map "[" 'insert-parentheses)
(define-key lisp-mode-shared-map "]" 'move-past-close-and-reindent)
@seh
seh / brace_xor_test.go
Last active December 15, 2015 01:19
In response to @laboon's Twitter post concerning a predicate that determines whether a text string contains only one kind of open or close curly braces (https://twitter.com/BillLaboon/status/313085206347276288), I wanted to explore a more efficient approach—one that doesn't involve regular expressions. I may have the predicate inverted here; min…
package main
import (
"strings"
"testing"
)
func doesntContainRune(s string, r rune) bool {
return !strings.ContainsRune(s, r)
}
@seh
seh / gist:898948
Created April 1, 2011 22:02
Emulate VIMClojure's parentheses coloring in Emacs
(require 'rainbow-delimiters)
(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
(add-hook 'slime-repl-mode-hook 'rainbow-delimiters-mode)
(let ((depth 0))
(dolist (color
;; These are nicked from VIMClojure:
;; vimclojure/vim/syntax/clojure.vim
'("orange1"
"yellow1"
"greenyellow"