Skip to content

Instantly share code, notes, and snippets.

@joekarma
joekarma / gist:3550384
Created August 31, 2012 08:44
Using CSS Selectors To Scrape Data With Common Lisp
(ql:quickload '(:drakma :closure-html :cxml :stp-query))
(defun get-before-and-after-pictures (page-number)
"Fetches relative urls for before and after pictures from a thread on Mark's Daily Apple."
(mapcar (alexandria:rcurry #'$:attr "src")
($:query "blockquote.postcontent > img"
(chtml:parse
(drakma:http-request (format nil "http://www.marksdailyapple.com/forum/thread6138-~D.html" page-number))
(cxml-stp:make-builder)))))
@joekarma
joekarma / gist:3688592
Created September 10, 2012 03:01
Read `n' characters from stream.
(defun read-n-characters (n &optional (stream *standard-input*))
(let ((seq (make-string n)))
(read-sequence seq stream)
seq))
@joekarma
joekarma / gist:3754531
Created September 20, 2012 07:57
RESTAS Example
(eval-when (:compile-toplevel :load-toplevel)
(ql:quickload :restas))
(restas:define-module :my-site
(:use :cl))
(in-package :my-site)
(restas:define-route hello ("/hello")
"Hello!")
@joekarma
joekarma / gist:3785568
Created September 26, 2012 02:00
Printing to Emacs from Hunchentoot
(defpackage :printing-from-hunchentoot
(:use :cl))
(in-package :printing-from-hunchentoot)
(defparameter *my-acceptor* (make-instance 'hunchentoot:acceptor :port 8080))
(defparameter *out* *standard-output*)
(hunchentoot:start *my-acceptor*)
@joekarma
joekarma / gist:3883827
Created October 13, 2012 08:32 — forked from meadhikari/gist:3873415
First common lisp function
(loop :for n :from 1 :below 1000
:when (or (zerop (mod n 3))
(zerop (mod n 5)))
:sum n)
(some-function :foo
:bar)
(some-function (:foo)
:bar)
@joekarma
joekarma / gist:3916212
Created October 19, 2012 04:22
Simple example of cl-sendmail being used to send an HTML based email. Use cl-smtp instead.
(cl-sendmail:with-email (html "[email protected]" :from "[email protected]" :subtype "html")
(setf (cl-sendmail::content html)
(xmls:parse "<body><h1>Testing</h1><p>This is a test!</p></body>")))
@joekarma
joekarma / gist:3925120
Created October 20, 2012 22:54
Get a list of packages that are created as a side effect of evaluating a given bunch of forms (such as quickloading a system)
(defmacro packages-created-by (&rest forms)
(with-gensyms (packages-before)
`(let ((,packages-before (list-all-packages)))
,@forms
(set-difference (list-all-packages) ,packages-before))))
(("stassats" . 40572) ("Xach" . 38278) ("nyef" . 37542) ("pjb" . 36812)
("sykopomp" . 27405) ("p_l" . 27385) ("beach" . 25487) ("pkhuong" . 24938)
("tcr" . 22036) ("drewc" . 19171) ("stassats`" . 17795) ("Zhivago" . 17075)
("_3b" . 16209) ("fusss" . 15704) ("Fare" . 15631) ("madnificent" . 15121)
("H4ns" . 14446) ("antifuchs" . 14346) ("gigamonkey" . 13040)
("Ralith" . 12161) ("fe[nl]ix" . 11921) ("Guthur" . 11524) ("Fade" . 11351)
("Adlai" . 11318) ("nikodemus" . 10038) ("rsynnott" . 10017) ("rahul" . 9910)
("schme" . 8600) ("mathrick" . 8582) ("Krystof" . 8452) ("hefner" . 8430)
("tic" . 8072) ("weirdo" . 7948) ("Phoodus" . 7711) ("jdz" . 7256)
("dlowe" . 7219) ("francogrex" . 7132) ("drdo" . 6495) ("adeht" . 6304)