Skip to content

Instantly share code, notes, and snippets.

View jasom's full-sized avatar

Jason Miller jasom

  • Santa Barbara, CA
View GitHub Profile
fastcgi.server = ( ".cl" =>
(( "socket" => "/tmp/cl-fastcgi.socket",
"bin-path" => "/path/to/init.cl",
))
)
@jasom
jasom / errexit.asciidoc
Last active April 17, 2020 00:56
Shell Error handling thoughts

Thoughts on bourne shell error handling

POSIX errexit is a terrible, no good, very bad thing because of its non-local action.

errexit feels like typical exception handling, but isn’t

Consider the following python from the days-of-yore before the with statement:

@jasom
jasom / Makefile
Created November 19, 2019 00:21
Example of multiuple output files
all: foo.out1 foo.out2 bar.out1 bar.out2
foo.out1: foo.in
sh multiple.sh foo.in
foo.out2: foo.out1
true
bar.out1 bar.out2: bar.in
sh multiple.sh bar.in
#!/bin/sh
usage() {
cat <<EOF >&1
Usage: $1 [OPTION].. SRC DSTDIR
Recursively copy SRC to destination directory DSTDIR.
-f Create DSTDIR if it does not exist
-H FORMAT Use tar format FORMAT (default=pax)
@jasom
jasom / example.lisp
Created March 5, 2019 01:28
cl-who composing
(defvar *html-outstream*)
(defun index-body (&optional (outstream *html-outstream*))
(cl-who:with-html-output (*html-outstream* outstream)
(:body (:main :class "wrapper"
(navigation)
(:header :class "header" :id "entrance"
(:section :class "container" :id "header"
(:img :src "/images/lambda-pink.png"
:height "45")
@jasom
jasom / ltk-first.lisp
Created February 1, 2019 19:49
LTK example
(defpackage ltk-first-example
(:use "CL" "LTK"))
(in-package "LTK-FIRST-EXAMPLE")
(defun gui ()
(let ((ltk:*debug-tk* t))
(with-ltk ()
(wm-title *tk* "Feet to Meters")
(let ((c (make-instance 'frame)))
@jasom
jasom / rpn.lisp
Created November 19, 2018 23:11
RPN calculator using lisp stack as RPN stack
(defpackage rpn (:use :cl) (:export :rpn))
(defpackage rpn-internal (:export :+ :print))
(in-package :rpn)
(defgeneric rpn-eval (token &optional y))
(defun rpn ()
(rpn-eval (let ((*package* (find-package 'rpn-internal))) (read))))
@jasom
jasom / bit-ldb.lisp
Last active October 9, 2018 21:41
bit-ldb
(defun bit-ldb (vector byte-spec)
(loop
for idx downfrom (- (length vector) (byte-position byte-spec) 1)
for pos from 0 below (byte-size byte-spec)
unless (zerop (bit vector idx)) sum (ash 1 pos)))
(define-setf-expander bit-ldb (vector bytespec &environment env)
"Set some bits in a bit-vector to a value based on a bytespec"
(multiple-value-bind (dummies vals newval setter getter)
(get-setf-expansion vector env)
@jasom
jasom / fib.lisp
Created September 18, 2018 16:52
(loop for n from 0
for next = 1 then (+ cur next)
for cur = 0 then next
when (= n 10)
return cur)
@jasom
jasom / cxml.lisp
Created February 22, 2018 20:43
Lisp XML namespaces
(cxml:parse #P"foo.xml" (cxml-xmls:make-xmls-builder)) ;;=>
;(("stream" . "http://etherx.jabber.org/streams")
; ((("lang" . "http://www.w3.org/XML/1998/namespace") "en")
; (("stream" . "http://www.w3.org/2000/xmlns/")
; "http://etherx.jabber.org/streams")
; ("version" "1.0") ("to" "localhost")
; ((NIL . "http://www.w3.org/2000/xmlns/") "jabber:client"))
; "
; "
; (("iq" . "jabber:client")