Skip to content

Instantly share code, notes, and snippets.

@seh
seh / gist:898948
Created Apr 1, 2011
Emulate VIMClojure's parentheses coloring in Emacs
View gist:898948
(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"
@seh
seh / brace_xor_test.go
Last active Dec 15, 2015
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…
View brace_xor_test.go
package main
import (
"strings"
"testing"
)
func doesntContainRune(s string, r rune) bool {
return !strings.ContainsRune(s, r)
}
@seh
seh / lisp.el
Created Sep 3, 2013
My current SLIME configuration.
View lisp.el
;:* 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 / underline-current.el
Created Oct 20, 2013
Emacs Lisp function to "underline" the current line.
View underline-current.el
;; 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 / mode.go
Created Nov 20, 2013
A function to find the count of the mode in a potentially multimodal data set.
View mode.go
// 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 / errors.go
Created Sep 28, 2016
Helper functions for interpreting fargo errors
View errors.go
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 / benchmarks.txt
Created Feb 13, 2017
Decimal length of a nonnegative integer
View benchmarks.txt
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