Skip to content

Instantly share code, notes, and snippets.

@fukamachi
fukamachi / shlyfile.lisp
Created August 27, 2013 00:09
A small Common Lisp program to sum up file sizes from `ls -l`.
;; https://twitter.com/potix2/status/371962749246394368
;; Usage
;; $ ls -l | shly sumsize
(ql:quickload :cl-ppcre)
(defun sumsize ()
(loop with sum = 0
for line = (read-line *standard-input* nil)
while line
@fukamachi
fukamachi / gist:6364983
Last active May 8, 2022 03:04
A Common Lisp function to extract a tarball (.tar.gz) file to a directory (*default-pathname-defaults*).
(ql:quickload '(chipz archive))
(defun extract-tarball (pathname)
"Extract a tarball (.tar.gz) file to a directory (*default-pathname-defaults*)."
(with-open-file (tarball-stream pathname
:direction :input
:element-type '(unsigned-byte 8))
(archive::extract-files-from-archive
(archive:open-archive 'archive:tar-archive
(chipz:make-decompressing-stream 'chipz:gzip tarball-stream)
@fukamachi
fukamachi / hello-world.lisp
Last active December 22, 2015 08:38
Print "Hello World" to the *standard-output* without using integer, string and character literals in Common Lisp.
;; This is a answer for a question of CodeIQ.
;; https://codeiq.jp/ace/cielavenir/q431
(in-package :cl-user)
(defmacro print-capitalized (symbol &rest symbols)
`(progn
(princ ,(string-capitalize symbol))
,@(loop for s in symbols
collect `(princ ,(name-char 'space))
@fukamachi
fukamachi / gist:6462977
Last active December 22, 2015 10:59
"Autoload" facility for Common Lisp which is similar to what Emacs Lisp has.
;; Macros in this file provides a "autoload" facility like Emacs Lisp has.
;; These are supposed to be used in a Lisp init file.
;;
;; Without those, you have to load all libraries you not sure whether they will be used or not.
;;
;; (ql:quickload :repl-utilities)
;; (use-package :repl-utilities)
;;
;; "Autoload" facility delays loading libraries until they are needed.
;; See the following 3 macros and their documentations.
@fukamachi
fukamachi / clhs.lisp
Last active December 24, 2015 17:39
Common Lisp script to open a HyperSpec HTML which corresponds to a specified symbol. (Works only with SBCL on Mac)
#!/usr/bin/env sbcl --script
;; -*- mode: common-lisp -*-
;; Usage:
;; clhs [SYMBOL]
(require 'asdf)
(defparameter *hyperspec-home*
(merge-pathnames "Dropbox/Documents/HyperSpec/" (user-homedir-pathname))
(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"