Skip to content

Instantly share code, notes, and snippets.

View bitops's full-sized avatar

Sebastian Wittenkamp bitops

View GitHub Profile
@bitops
bitops / latency.txt
Created May 31, 2012 20:50 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@bitops
bitops / fortune.el
Created June 14, 2012 06:32
fortune for mac os x
;; a fortune function that works if you have the
;; "fortune" program installed via macports
(defun fortune ()
(interactive)
(let ((fortune-program "/opt/local/bin/fortune"))
(if (file-exists-p fortune-program)
(shell-command fortune-program))))
@bitops
bitops / dotimes.el
Created June 14, 2012 06:39
2.times in emacs lisp
;; from http://stackoverflow.com/questions/7249244/how-can-i-define-functions-taking-blocks-as-parameters-in-elisp
;;
;; the 'do-times function emulates n.times behavior from Ruby.
;;
;; definition
(defmacro do-times (n &rest body)
(let ((i (gensym)))
`(do ((,i 0 (1+ ,i)))
((= ,i ,n))
@bitops
bitops / message_region.el
Created June 27, 2012 00:28
Emacs Lisp read region into variable
;; messages the active region to the minibuffer
(defun message-region ()
(interactive)
(if (region-active-p)
(let ((region-contents-string (buffer-substring (region-beginning) (region-end))))
(message region-contents-string))
(message "Mark is not set")))
@bitops
bitops / posts_controller.rb
Created June 29, 2012 22:50
dhh slightly refactored
class PostsController
before_filter :set_entry
before_filter :reject_spam
def create
@comment = @entry.comments.create!(params[:post].permit(:title, :body).merge(author: current_user))
deliver_comment @comment
post_to_twitter @comment if @comment.share_on_twitter?
post_to_facebook @comment if @comment.share_on_facebook?
@bitops
bitops / gist:3232552
Created August 2, 2012 02:16 — forked from swannodette/gist:3217582
sudoku_compact.clj
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
(defn init [vars hints]
@bitops
bitops / tmux.conf
Created September 27, 2012 17:08
Sebastian's ~/.tmux.conf
# Use Ctrl+O as bind key
unbind C-b
unbind C-o
set -g prefix C-o
# Use vi key bindings to navigate
set-window-option -g mode-keys vi
# Use Ctrl+O, O to switch back and forth between panes
bind-key C-o last-window
@bitops
bitops / extract_variable.el
Created October 4, 2012 23:50
Extract variable refactoring in Emacs
(defun read-region ()
"Read the currently active region and return it as a string"
(if (region-active-p)
(let ((region-contents-string (buffer-substring (region-beginning) (region-end))))
region-contents-string)))
(defun ruby-extract-variable ()
"Extract variable from currently active region."
(interactive)
(if (region-active-p)
@bitops
bitops / commits.txt
Created October 9, 2012 18:38
writing good commit messages
Also, please write good git commit messages. A good commit message
looks like this:
Header line: explaining the commit in one line
Body of commit message is a few lines of text, explaining things
in more detail, possibly giving some background about the issue
being fixed, etc etc.
The body of the commit message can be several paragraphs, and
@bitops
bitops / shell.txt
Created October 9, 2012 22:59
swank.rb issues
ruby swank.rb
# emacs prompts:
# Versions differ: 20100404 (slime) vs. nil (swank). Continue? (y or n)
# if yes, backtrace occurs.
Listening on ["AF_INET6", 4005, "::1", "::1"]
dispatch: [:":emacs-rex", [:"swank:connection-info"], "COMMON-LISP-USER", :t, 1]
dispatch: [:":emacs-rex", [:"swank:create-repl", :nil], "COMMON-LISP-USER", :t, 2]