Skip to content

Instantly share code, notes, and snippets.

@llibra
llibra / gist:3889104
Created October 14, 2012 16:31
mapM and seqM
(defpackage :monad (:use :cl :optima))
(in-package :monad)
(defun seqM (ms)
(labels ((rec (ms)
(match ms
((list m)
(fmap m (lambda (x) (cons x nil))))
((cons m ms)
(bind m (lambda (x)
@llibra
llibra / gist:3767300
Created September 22, 2012 18:23
modified urlencode
;;;; urlencodeの実験
(let ((str (map 'string (lambda (_)
(declare (ignore _))
(code-char (random 255)))
(make-string (* 1024 1024)))))
(null (time (puri::encode-escaped-encoding str puri::*reserved-characters* t)))
(null (time (urlencode:urlencode str))))
(in-package :urlencode)
@llibra
llibra / gist:3766833
Created September 22, 2012 17:12
URI encoding
;; do-urlencodeはUTF-8に変換してる分不利
;; ただ、1MBの処理に1GB超は少し辛い?
;; 実際にそんな大きいデータを扱うことはないけど、積み重なると結構差が出そう
(let ((str (map 'string (lambda (_)
(declare (ignore _))
(code-char (random 255)))
(make-string (* 1024 1024)))))
(null (time (puri::encode-escaped-encoding str puri::*reserved-characters* t)))
(null (time (urlencode:urlencode str))))
@llibra
llibra / drakma.diff
Created September 11, 2012 22:25
A patch for gist:3701770
--- /home/manabu/quicklisp/dists/quicklisp/software/drakma-1.2.7/request.lisp 2012-09-11 06:07:54.146125000 +0900
+++ /home/manabu/work/request.lisp 2012-09-12 08:00:26.953125000 +0900
@@ -663,18 +663,17 @@
(when (and content-length
(not (or (and (integerp content-length)
(not (minusp content-length)))
- (arrayp content)
- (listp content)
+ (typep content '(or (vector octet) list))
(eq content :continuation))))
@llibra
llibra / test.lisp
Created September 11, 2012 20:30
DRAKMA:HTTP-REQUEST drops some input characters
(ql:quickload :cl-ppcre)
(ql:quickload :bordeaux-threads)
(ql:quickload :usocket)
(ql:quickload :drakma)
(asdf:component-version (asdf:find-system :drakma))
;=> "1.2.7"
(flet ((echo-content ()
(usocket:with-socket-listener (socket "127.0.0.1" 8080 :reuse-address t
@llibra
llibra / sort.lisp
Created June 18, 2012 14:55
Sorting algorithms written in Common Lisp
(in-package :cl-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :alexandria)
(ql:quickload :fiveam))
(defpackage :sort
(:use :cl)
(:import-from :alexandria :iota)
(:export :bubble-sort/naive :bubble-sort/not-enough :bubble-sort/knuth
(do ((n 0 (1+ n)))
((= n 10))
(if (zerop (mod n 5))
(format t "~&~a" n)
(format t "~a" n)))
(let ((l '#1=("~&~a" "~a" "~a" "~a" "~a" . #1#)))
(do ((n 0 (1+ n))
(l l (cdr l)))
((= n 10))
@llibra
llibra / gist:2166352
Created March 23, 2012 02:47
cffi:w-f-o
(cffi:with-foreign-object (p :pointer)
(print (cffi:mem-ref p :pointer))
(setf (cffi:mem-ref p :pointer) (cffi:null-pointer))
(print (cffi:mem-ref p :pointer))
(print (cffi:pointer-address p)))
;-> #<A Foreign Pointer #x36>
; #<A Null Foreign Pointer>
; 37879600
@llibra
llibra / gist:2036899
Created March 14, 2012 14:34
Series version foldl
(defun foldl (kons knil &rest series-inputs)
(apply #'series::basic-collect-fn (constantly knil) kons series-inputs))
(define-compiler-macro foldl (kons knil &rest series-inputs)
`(collect-fn t (constantly ,knil) ,kons ,@series-inputs))
(foldl #'- 0 (scan '(0 1 2 3 4)))
;=> -10
@llibra
llibra / aif-ptr.lisp
Created December 3, 2011 03:30
anaphoric if for pointers of CFFI
;; It's anaphoric if for pointers. If the first argument is NOT a null pointer,
;; evaluates the second argument. Otherwise evaluates third.
(defmacro aif/ptr (test then &optional else)
`(let ((it ,test))
(if (null-pointer-p it) ,else ,then)))