Skip to content

Instantly share code, notes, and snippets.

View defunkydrummer's full-sized avatar

defunkydrummer defunkydrummer

  • Fintech company
  • Peru
View GitHub Profile
@defunkydrummer
defunkydrummer / geta.lisp
Last active November 25, 2020 21:32
Helper for traversing ALISTs in depth
(defun geta (alist key)
"Similar to assoc-value... but operates in depth!
key can be a list or a single key."
(when (and alist key)
(etypecase key
((or string symbol)
(alexandria:assoc-value alist key :test 'string=))
(cons
;; associate in depth
(if (cdr key)
@defunkydrummer
defunkydrummer / endless.lisp
Created August 13, 2019 17:25
Endless shitposting cube
(defun endless (str pos len)
(if (<= pos len)
(elt str pos)
(if (zerop (mod pos len))
(elt str len)
(elt str (1- (mod pos len))))))
(defun square-val (x y str len)
(cond
((eql y 0) (elt str x))
;; (c) 2019 Defunkydrummer
;; MIT License
(defun indent (str &key with-indent)
"Indent a string"
(format t
(format nil "~~~dT ~~a" (1+ with-indent))
str))
(defun |brutally practical line| (l &optional (indent 0))
@defunkydrummer
defunkydrummer / save-lisp-tree-shake-and-die.lisp
Created April 30, 2019 20:18 — forked from burtonsamograd/save-lisp-tree-shake-and-die.lisp
A quick and dirty tree shaker for SBCL, giving about a 40% reduction in dump size.
;; -*- mode: lisp -*-
;;
;; A quick and dirty tree shaker for SBCL. Basically, it destroys the
;; package system and does a gc before saving the lisp image. Gives
;; about a 40% reduction in image size on a basic hello world test.
;; Would like to hear how it works on larger projects.
;;
;; Original idea from: https://groups.google.com/d/msg/comp.lang.lisp/6zpZsWFFW18/WMy4PyA9B4kJ
;;
;; Burton Samograd
@defunkydrummer
defunkydrummer / traverse.lisp
Created April 30, 2019 15:08
Recursive getf to traverse nested plist structures
(defun getf* (l r)
"Recursive getf, to traverse nested plists.
Ej:
list =
(:id 10 :detail (:name \"Flavio\" :dni 666))
(getf* list '(:detail :dni)) --> obtains 666