Skip to content

Instantly share code, notes, and snippets.

@joekarma
joekarma / gist:5430913
Last active December 16, 2015 11:58
regex-replace-all-to-list can be used to replace parts of a string with arbitrary objects. An example use-case (shown below) is to linkify parts of a string while still escaping the rest for HTML.
(defun scan-to-ranges (regex target-string)
(let ((matches (ppcre:all-matches regex target-string))
(end-pos (length target-string))
(starts-with-match nil)
(all-ranges nil))
(when (not matches)
(return-from scan-to-ranges
(list (cons 0 end-pos))))
@joekarma
joekarma / television-subreddit.css
Last active December 15, 2015 21:19
Tweaks to /r/television's subreddit CSS.
.side .spacer
{
margin:4px 0 3px;
}
.submit-text
{
display:none;
}
@joekarma
joekarma / gist:5321929
Last active December 15, 2015 20:58
sha512 password digesting function
(defun 5-random-base64-encoded-bytes ()
(base64:usb8-array-to-base64-string
(map 'vector (lambda (place)
(declare (ignore place))
(random 255))
(make-sequence 'vector 5))))
(defun digest-password (password &optional (salt (5-random-base64-encoded-bytes)))
(values
(base64:usb8-array-to-base64-string
(in-package :cl-user)
(defun yaclml-defaults (thunk)
(eval `(let ((,(intern "*YACLML-INDENT*" :yaclml) nil))
(funcall ,thunk))))
(asdf:defsystem :foo
:serial t
:description "Foo is baz for bar."
:author "Joe Taylor"
;; cl-who
(let ((colors '("red" "green" "blue")))
(who:with-html-output-to-string (s)
(:html
(:head
(:title "Colors"))
(:body
(:ul
(dolist (c colors)
CL-USER> (setf yaclml::*yaclml-indent* t)
T
CL-USER> (<:html (<:head (<:title "Hello, world")))
<html
><head
><title
>Hello, world</title
></head
></html
>
(defvar *foo* (get-foo))
(defun get-foo ()
42)
(format t "~a" *foo*)
;; The above code will not work, but it's analogous to the JavaScript below, which will:
;; var foo = getFoo();
(defun a-bound-p ()
(boundp 'a))
(defun funcall-with-a-as-special-variable (function &optional a)
(declare (special a))
(funcall function))
(funcall-with-a-as-special-variable
#'a-bound-p) ;;; => T
(defun draw-frame ()
(sdl:clear-display sdl:*black*)
(sdl:draw-box-* 0 0 100 100)
(sdl:update-display))
(sdl:with-init ()
(sdl:window 1024 768)
(sdl:with-events ()
(:quit-event () t)
(:idle ()
(defun draw-frame ()
(sdl:clear-display sdl:*black*)
(sdl:draw-box-* 30 30 100 100)
(sdl:update-display))
(sdl:with-init ()
(sdl:window 1024 768)
(sdl:with-events ()
(:quit-event () t)
(:idle ()