This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun read-n-characters (n &optional (stream *standard-input*)) | |
(let ((seq (make-string n))) | |
(read-sequence seq stream) | |
seq)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload '(:drakma :closure-html :cxml :css-selectors)) | |
(let ((page (chtml:parse | |
(drakma:http-request "http://www.google.com") | |
(cxml-dom:make-dom-builder)))) | |
(css:query "div input" page)) | |
;; | |
;; Fails with the following error message: | |
;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleMessage(message) { | |
try { /* master handler */ | |
try { /* sub handler */ | |
try { /* sub sub handler */ | |
if (understandsMessage(message, "sub-sub-handler")) { | |
handleMessage(message, "sub-sub-handler"); | |
} else { | |
throw "can't understand"; | |
} | |
} catch (e) { throw e; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Monkey patch for the monkey lib | |
(defun monkeylib-html::emit-html-to-string (html) | |
(with-output-to-string (s) | |
(let ((monkeylib-text-output:*text-output* s)) | |
(monkeylib-html:emit-html html)))) | |
(export 'monkeylib-html::emit-html-to-string | |
(find-package :monkeylib-html)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Discovered via http://www.adampetersen.se/articles/fizzbuzz.htm | |
;; “Write a program that prints the numbers from 1 to 100. But for | |
;; multiples of three print “Fizz” instead of the number and for the | |
;; multiples of five print “Buzz”. For numbers which are multiples of | |
;; both three and five print “FizzBuzz”.” | |
(defun multiple-p (n multiple) | |
(zerop (mod n multiple))) | |
(defun fizzbuzz () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun functions-in-package (&optional (package-name (package-name *package*))) | |
"Return a list of functions available in a given package." | |
(let ((symbols nil)) | |
(do-symbols (symbol package-name) | |
(when (fboundp symbol) | |
(push symbol symbols))) | |
symbols)) | |
(defun functions-defined-in-package (&optional (package-name (package-name *package*))) | |
"Return a list of functions that are defined in a given package." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload '(:quickproject | |
:external-program)) | |
(push | |
(lambda (pathname &rest args) | |
(setf (current-directory) (fad:pathname-as-directory pathname)) | |
(rename-file "README.txt" "README.markdown") | |
(external-program:run "git" | |
(list "init" ".")) | |
(external-program:run "git" |