Skip to content

Instantly share code, notes, and snippets.

View kisom's full-sized avatar

Kyle Isom kisom

View GitHub Profile
@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

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.

; -*-lisp-*-
;; Load swank.
;; *prefix-key* ; swank will kick this off
(ql:quickload :swank)
(let ((server-running nil))
(defcommand swank () ()
"Toggle the swank server on/off"
(if server-running
(progn
@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
~/src/coreos-vagrant
(0) <monalisa> $ vagrant ssh
Last login: Wed Jan 15 23:47:47 UTC 2014 from 10.0.2.2 on ssh
______ ____ _____
/ ____/___ ________ / __ \/ ___/
/ / / __ \/ ___/ _ \/ / / /\__ \
/ /___/ /_/ / / / __/ /_/ /___/ /
\____/\____/_/ \___/\____//____/
core@localhost ~ $
@kisom
kisom / gtgov.sh
Created August 31, 2013 18:57
Go test code coverage.
#!/bin/sh
if [ -z "$1" ]; then
PKG=$(pwd)
PKG=${PKG##${GOPATH}/src/}
else
PKG=$1
fi
OUTBASE=${PKG##*/}
SLOC=$(gofmt -comments=false $(find ${GOPATH}/src/${PKG} -iname \*.go | xargs)\
0000000000421e20 <runtime.aeshashbody>:
421e20: f3 0f 7e 02 movq (%rdx),%xmm0
421e24: 66 data16
421e25: 48 0f rex64 (bad)
421e27: 3a 22 cmp (%rdx),%ah
421e29: c1 01 66 roll $0x66,(%rcx)
421e2c: 0f 6f 14 25 a0 6b 57 movq 0x576ba0,%mm2
421e33: 00
421e34: 66 0f 6f 1c 25 b0 6b movdqa 0x576bb0,%xmm3
421e3b: 57 00
@kisom
kisom / onp.go
Created June 16, 2013 17:08
scripts to fetch OpenNICProject nameservers, suitable for putting in resolv.conf.
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"os"
"regexp"
"strings"
)
@kisom
kisom / go.benchmarks.txt
Created April 30, 2013 14:05
Go Benchmarks for the Beaglebone/Black
PASS
ok archive/tar 0.087s
*** Test killed: ran too long (10m0s).
FAIL archive/zip 600.056s
PASS
BenchmarkReaderCopyOptimal 20000 100551 ns/op
BenchmarkReaderCopyUnoptimal 10000 273210 ns/op
BenchmarkReaderCopyNoWriteTo 5000 334045 ns/op
BenchmarkWriterCopyOptimal 10000 282170 ns/op
BenchmarkWriterCopyUnoptimal 10000 272459 ns/op
@kisom
kisom / mydaemon
Created April 28, 2013 06:10
Sample Upstart and sysvinit script for Go daemons.
#! /bin/sh
### BEGIN INIT INFO
# Provides: mydaemon
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mydaemon does stuff
# Description: this is an actual executable script, and should be saved in
# /etc/init.d/mydaemon.