Skip to content

Instantly share code, notes, and snippets.

(defmacro execution-time (&body body)
"Return the number of milliseconds it takes to execute `body`. Also
returns the result as the second value."
(let ((tm (gensym))
(res (gensym)))
`(let* ((,tm (get-internal-real-time))
(,res (progn ,@body))
(,tm (floor (* 1000 (- (get-internal-real-time) ,tm))
internal-time-units-per-second)))
(values (float ,tm) ,res))))
@fukamachi
fukamachi / twitpic-dl.lisp
Last active August 29, 2015 14:06
Twitpic backup script
#|
Twitpic Downloader
==================
This Common Lisp script downloads all image/video files from Twitpic account to the current directory.
## Usage
;; SBCL
;; http://kinokoru.jp/archives/840
(defmacro css (name elems)
`(with-open-file
(*standard-output* ,(string-downcase name) :direction :output :if-exists :supersede)
,@(loop for (elem attrs) in elems
collect
`(format t "~a {~%" ,elem)
append
(mapcar (lambda (attr)
@fukamachi
fukamachi / 00-benchmarking.markdown
Last active August 29, 2015 14:07
Benchmarking Clack, Wookie and Node.js

Target servers

  • Clack (Wookie handler)
  • Wookie
  • Node.js (http module)

Benchmarking environment

  • Mac OS X Mavericks (CPU: 3GHz Intel Core i7, Memory: 8GB)
  • httperf v0.9.0
(cffi:define-foreign-library libevent2-pthreads
(:darwin (:or
"libevent_pthreads.dylib"
; brew's install of libevent on Mac OX X
"/usr/local/lib/libevent_pthreads.dylib"
; macports
"/opt/local/lib/libevent_pthreads.dylib"))
(:unix (:or "/usr/local/lib/event2/libevent_pthreads.so"
"libevent_pthreads.so"
"libevent_pthreads-2.0.so.5"
@fukamachi
fukamachi / hello.go
Created October 15, 2014 22:13
Go Hello World server
package main
import (
"fmt"
"log"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World")
@fukamachi
fukamachi / parser-utils.lisp
Created October 25, 2014 14:06
Common Lisp utilities for parsing a sequence
(in-package :cl-user)
(defpackage parser-utils
(:use :cl)
(:import-from :alexandria
:with-gensyms)
(:export :with-array-parsing
:redo
:gonext
:goto))
(in-package :parser-utils)
@fukamachi
fukamachi / libbcrypt.rb
Last active August 29, 2015 14:10
libbcrypt.rb
require "formula"
class Libbcrypt < Formula
homepage "https://github.com/Rudolph-Miller/openwall-bcrypt"
url "https://github.com/Rudolph-Miller/openwall-bcrypt/archive/53444382b1f03f41f8757493f26f6eae66320d02.tar.gz"
version '1.1'
sha1 "6ad0f93367e7036e4c4c876d44c39cc00bbb584f"
def install
system "make", "library"
ext = OS.mac? ? 'dylib' : 'so'
@fukamachi
fukamachi / a.cl
Created January 21, 2015 15:10 — forked from kmyk/a.cl
; $ sbcl --load a.cl --eval '(sb-ext:save-lisp-and-die "a.out" :toplevel #'\''main :executable t)' && time ( echo 100000000 | ./a.out > /dev/null )
; ( echo 100000000 | ./a.out > /dev/null; ) 10.75s user 0.15s system 99% cpu 10.931 total
; $ sbcl --version
; SBCL 1.2.6
(defun main ()
(declare (optimize (speed 3) (debug 0) (safety 0) (compilation-speed 0)))
(let* ((n (1+ (the fixnum (read))))
(is-prime (make-array n :element-type 'boolean :initial-element t)))
@fukamachi
fukamachi / 00-vector-case.lisp
Last active August 29, 2015 14:16
A fast sequence matching macro
(ql:quickload :alexandria)
(import '(alexandria:ensure-cons alexandria:once-only))
(defmacro vector-case (vec-and-options &body cases)
(destructuring-bind (vec &key (start 0) end case-insensitive)
(ensure-cons vec-and-options)
(let ((otherwise (gensym "otherwise")))
(labels ((case-candidates (el)
(if (and case-insensitive
(characterp el))