Skip to content

Instantly share code, notes, and snippets.

View jasom's full-sized avatar

Jason Miller jasom

  • Santa Barbara, CA
View GitHub Profile
@jasom
jasom / fib.yaml
Created February 1, 2018 22:42
yamlisp
- defun fibonacci [n, &optional, [a, 0], [b, 1], acc]
- if
- [zerop, n]
- [nreverse acc]
- fibonacci
- [1-, n]
- b
- [+, a, b]
- [cons, a, acc]
@jasom
jasom / ws-example.lisp
Created December 27, 2017 23:38
Websockets + static content with clack
(defvar *static-server* (lack.app.file:make-app))
(defun my-server (env)
(cond
((equal (getf env :path-info) "/socket")
(let ((ws (websocket-driver:make-server env)))
(websocket-driver:on
:message ws
(lambda (message)
(websocket-driver:send ws message)))
(lambda (responder)
(defvar *fast-prng-cipher* nil)
(defun fast-random (nbytes)
(unless *fast-prng-cipher*
(setf *fast-prng-cipher*
(ironclad:make-cipher 'ironclad:salsa20
:key (ironclad:random-data 32) :mode :stream)))
(let ((result (make-array nbytes :element-type '(unsigned-byte 8))))
(ironclad:encrypt *fast-prng-cipher* (make-array nbytes :element-type '(unsigned-byte 8) :initial-element 0) result)
result))
#|
@jasom
jasom / day-5.lisp
Last active December 6, 2017 18:37 — forked from asimpson/day-5.lisp
Let as outtermost form of a DO body is a code-smell (this also gives a ~15% speedup)
(defun process(cells)
(do ((moves 0 (+ 1 moves))
(position 0)
(cell-value (elt cells 0) (ignore-errors (elt cells position))))
((null cell-value) (print moves))
(psetf
position (+ cell-value position)
(elt cells position) (1+ cell-value))))
(defun start()
[jasom@motoko:~]$ nix-channel --list
[jasom@motoko:~]$ sudo nix-channel --list
nixos https://nixos.org/channels/nixos-17.03
@jasom
jasom / tarcp.sh
Created February 22, 2017 17:01
Network copy with tar
#!/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)
{ stdenv }:
stdenv.mkDerivation rec {
name = "foo-1.0";
src = ./foo.txt;
id = let contents = builtins.readFile ./foo.txt;
hash = builtins.hashString "sha256" contents;
in hash;
builder = ./foo.sh;
Processing section "[homes]"
[2016/10/26 21:28:39.748280, 2] ../source3/param/loadparm.c:2596(lp_do_section)
Processing section "[public]"
[2016/10/26 21:28:39.748366, 3] ../source3/param/loadparm.c:1476(lp_add_ipc)
adding IPC service
[2016/10/26 21:28:39.748423, 3] ../source3/auth/auth.c:178(auth_check_ntlm_password)
check_ntlm_password: Checking password for unmapped user []\[GUEST]@[MACBOOK-AIR-2] with the new password interface
[2016/10/26 21:28:39.748445, 3] ../source3/auth/auth.c:181(auth_check_ntlm_password)
check_ntlm_password: mapped user is: [SA]\[GUEST]@[MACBOOK-AIR-2]
[2016/10/26 21:28:39.748488, 3] ../source3/auth/check_samsec.c:400(check_sam_security)
@jasom
jasom / dynamic-flet.lisp
Created June 14, 2016 21:37
Dynamic flet implementation
(declaim (optimize (debug 3)))
(defpackage dynamic-flet
(:use :cl :alexandria)
(:export #:defdynamic #:dynamic-flet))
(in-package dynamic-flet)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *dynamic-fbindings* (make-hash-table)))
(defmacro defdynamic (fname &optional args &body b)
@jasom
jasom / parenscriptm.lisp
Last active January 6, 2016 03:34
Parenscript mithril wrapper
(defpackage "PARENSCRIPTM-GARBAGE")
(defun split-tag-parts (tree)
(loop with tag = (car tree)
for rest on (cdr tree) by #'cddr
while (keywordp (car rest))
if (cadr rest)
collect (ps::encode-js-identifier (string (car rest))) into attrs
and
collect (cadr rest) into attrs