Skip to content

Instantly share code, notes, and snippets.

View kisom's full-sized avatar

Kyle Isom kisom

View GitHub Profile
@kisom
kisom / yolo.lisp
Created March 2, 2014 21:54
I don't even what is this has anyone ever gone so far as to even... YOLO
;;; sbcl --load yolo.lisp
;;; requires quicklisp in your .sbclrc
;;; or just load it in any other CL repl after loading quicklisp
(ql:quickload :usocket) ;; or load it some other way
;;;; some ideas:
;; echo '(defparamter *foo* 42)' | nc 127.0.0.1 4141
;; echo '(+ 2 2)' | nc 127.0.0.1 4141
;; used to demonstrate evaluation

Reader Macros in Common Lisp

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

Macros and read-macros see your program at different stages. Macros get hold of the program when it has already been parsed into Lisp objects by the reader, and read-macros operate on a program while it is still text. However, by invoking read on this text, a read-macro can, if it chooses, get parsed Lisp objects as well. Thus read-macros are at least as powerful as ordinary macros.

@kisom
kisom / files.txt
Created April 10, 2014 04:39
golang v. find|xargs
This file has been truncated, but you can view the full file.
total 1920004
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346539308486
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346540035848
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346540246418
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346540567344
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346540853738
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346541058648
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346541260301
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346541543718
-rw-r--r-- 1 kyle kyle 65536 Apr 9 22:32 dump-1397104346541762984
// This program is a simple web server that listens for IP address
// updates. There's no authentication or security at all; I use it
// to keep track of beaglebones on a LAN.
package main
import (
"fmt"
"log"
"net/http"
"os"
@kisom
kisom / gtcov
Created October 19, 2014 01:24
gtcov
#!/bin/sh
# Produce an HTML file displaying code coverage. Dependencies:
# - cloc (apt-get install cloc)
# - cover (go get code.google.com/p/go.tools/cmd/cover)
if [ -z "$1" ]; then
PKG=""
else
PKG=$1
fi
@kisom
kisom / dump-container
Created November 14, 2014 17:34
Export a container to a GPG-encrypted tarball.
#!/bin/sh
CONTAINER="$1"
BASENAME="$2"
OWNER="kyle@tyrfingr.is"
if [ -z "$BASENAME" ]
then
echo "No basename provided."
exit
@kisom
kisom / Monads.lhs
Last active August 29, 2015 14:09
Source file for the monad post.
(This post is a Literate Haskell file that was run through pandoc to
produce markdown).
It seems customary in the Haskell space to write an introduction to
monads; my attempt in this exposition is not to outdo anyone else, but
to make the topic clear enough that I can write about it. My hope is
that by doing so, it becomes more clear to me.
> module Perhaps where
@kisom
kisom / count-macroexpansions.lisp
Created April 7, 2015 22:28
Fun little function to count the number of times a macro gets expanded.
(defun count-macroexpansions (form)
(labels ((count-expansions (form n)
(multiple-value-bind
(expansion expanded)
(macroexpand-1 form)
(if expanded
(count-expansions expansion (+ n 1))
n))))
(count-expansions form 0)))
#!/bin/sh
# convert Nikon NEF RAW images to FITS.
#
# depends on dcraw and imagemagick:
# apt-get install dcraw imagemagick
IMAGE_LIST="$1"
if [ -z "$IMAGE_LIST" ]
then
ATTRS{idVendor}=="5332", ATTRS{idProduct}=="1300", ACTION=="add", SUBSYSTEM=="usb", ATTR{power/control}="on"