Skip to content

Instantly share code, notes, and snippets.

@fukamachi
fukamachi / gist:2050237
Created March 16, 2012 14:16
Find port number not in use
(defun port-available-p (port)
(handler-case (let ((socket (usocket:socket-listen "127.0.0.1" port :reuse-address t)))
(usocket:socket-close socket))
(usocket:address-in-use-error (e) (declare (ignore e)) nil)))
;; Find port number not in use from 50000 to 60000.
(loop for port from (+ 50000 (random 1000)) upto 60000
if (port-available-p port)
return port)
@magnars
magnars / gist:2350388
Created April 10, 2012 10:50
Push mark when using ido-imenu
;; Push mark when using ido-imenu
(defvar push-mark-before-goto-char nil)
(defadvice goto-char (before push-mark-first activate)
(when push-mark-before-goto-char
(push-mark)))
(defun ido-imenu-push-mark ()
(interactive)
@magnars
magnars / gist:2360578
Created April 11, 2012 17:05
ido-imenu as used in Emacs Rocks #10
(defun ido-imenu ()
"Update the imenu index and then use ido to select a symbol to navigate to.
Symbols matching the text at point are put first in the completion list."
(interactive)
(imenu--make-index-alist)
(let ((name-and-pos '())
(symbol-names '()))
(flet ((addsymbols (symbol-list)
(when (listp symbol-list)
(dolist (symbol symbol-list)
@priyadarshan
priyadarshan / gist:2464631
Created April 22, 2012 15:28
An O(n) implementation of McCreight's suffix-tree algorithm.
;;; Original URL: http://fpn.mit.edu/Downloads/SuffixTree
;;; Copyright [email protected] 2004.
(defpackage :suffix-tree
(:export :build-suffix-tree :stree-root :*stree-print-string*
:random-string :subtree-size :count-leaves)
(:use :common-lisp))
;; An O(n) implementation of McCreight's suffix-tree algorithm.
;; Usage example:
@fukamachi
fukamachi / gist:2514283
Created April 27, 2012 23:34
Clack uploading sample
(import 'clack.request:make-request 'clack.request:body-parameter)
(clack:clackup
#'(lambda (env)
(format t "~S~%"
(body-parameter (make-request env)))
'(200
(:content-type "text/html")
("<form method='POST' enctype='multipart/form-data'><input type='file' name='pdf'><input type='submit'></form>"))))
@fukamachi
fukamachi / gist:2514290
Created April 27, 2012 23:36
Clack uploading sample
(import 'clack.request:make-request 'clack.request:body-parameter)
(clack:clackup
#'(lambda (env)
(format t "~S~%"
(body-parameter (make-request env)))
'(200
(:content-type "text/html")
("<form method='POST' enctype='multipart/form-data'><input type='file' name='pdf'><input type='submit'></form>"))))
;;;; -*- Mode: Lisp -*-
;;;; http://pastebin.com/S1FzEZpn
;;
;; vim: filetype=lisp
(in-package :stumpwm)
;; Load swank.
;; ! what's this?
(load "/opt/quicklisp/dists/quicklisp/software/slime-20120307-cvs/swank-loader.lisp")
@yefim
yefim / create-repo.sh
Created May 4, 2012 06:10
Create a new GitHub repo
#!/bin/bash
read -s -p "GitHub password: " pass
# I assume the GitHub API and authentication works because I don't want to parse JSON
curl -u "yefim323:$pass" https://api.github.com/user/repos -d "{\"name\":\"$1\"}" > /dev/null
git remote add origin [email protected]:yefim323/$1.git
@fukamachi
fukamachi / inverse-fizzbuzz.lisp
Created May 17, 2012 15:16
Inverse FizzBuzz in Common Lisp
;; http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
;; http://d.hatena.ne.jp/matarillo/20120515/p1
#.(progn
(ql:quickload :optima)
(ql:quickload :alexandria)
(ql:quickload :cl-test-more)
(values))
(setq *print-circle* t)
@jboner
jboner / latency.txt
Last active April 19, 2025 21:29
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD