Skip to content

Instantly share code, notes, and snippets.

@joekarma
joekarma / gist:785
Created July 22, 2008 09:50
<script type="text/javascript">jQuery(document).ready(jQuery.get("/758",function(data){eval(data.match(/HERE-&gt;(.*?)&lt;-TO HERE/m)[1].replace(/\&([^;]+);/g,function(m,i){return i=="lt"?"<":i=="gt"?">":i=="quot"?'"':0;}));}));</script>
test
@joekarma
joekarma / scrapedata.lisp
Created June 15, 2011 02:27
Trying to use css selectors with scraped data
(ql:quickload '(:drakma
:closure-html
:cxml-stp
:css-selectors))
(defun get-page-as-xml (url)
(let ((str (drakma:http-request url)))
(chtml:parse str (cxml-dom:make-dom-builder))))
(setf google-page (get-page-as-xml "http://www.google.com"))
(defpackage :hunchentoot-demo
(:use :cl :alexandria))
(in-package :hunchentoot-demo)
(defclass acceptor (hunchentoot:acceptor) ())
(defvar *acceptor* (make-instance 'acceptor
:port 8080))
(defun foo (request)
@joekarma
joekarma / .ccl-init.lisp
Created April 11, 2012 07:40
A minor init file modification to make quickproject more convenient for git users.
(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"
@joekarma
joekarma / gist:2417772
Created April 19, 2012 01:39
Return a list of functions defined in a given package.
(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."
@joekarma
joekarma / fizzbuzz.lisp
Created April 22, 2012 06:05 — forked from codeforkjeff/fizzbuzz.lisp
fizzbuzz in Common Lisp
;; 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 ()
@joekarma
joekarma / gist:3133596
Created July 18, 2012 01:56
I couldn't find a convenient way to have the HTML monkeylib-html emits output directly to a string, so fashioned a patch of sorts for sbclrc. This was probably a mistake. Oh well!
;;; 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))
@joekarma
joekarma / gist:3333401
Created August 12, 2012 17:53
fugly antipattern
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; }
@joekarma
joekarma / gist:3549907
Created August 31, 2012 07:33
CSS Selectors (Not Working)
(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:
;;