Skip to content

Instantly share code, notes, and snippets.

@jdz
jdz / setup-paredit.el
Created July 14, 2021 09:35
Paredit stuff
;;; -*- lexical-binding: t -*-
(defun usr:match-pattern-backwards (pattern)
;;; XXX: Check if we hit (point-min)?
(cond ((integerp pattern)
(when (char-equal (char-before) pattern)
(backward-char)
t))
((and (consp pattern)
(keywordp (car pattern)))
@jdz
jdz / sample.lisp
Created February 18, 2020 13:45
sample
(defmethod sample ((input list) k &aux (length (length input)))
(assert (<= 1 k length))
(let ((indices (loop with result = '()
with i = k
for j = (random length)
unless (member j result)
do (push j result)
(decf i)
while (< 0 i)
finally (return result))))
@jdz
jdz / test.lisp
Created February 13, 2020 14:00
Something's fishy
(in-package #:cl-user)
(eval-when (:load-toplevel :compile-toplevel :execute)
(unless (find-package "WHO")
(require "cl-who")))
(defun test ()
(values
(who:with-html-output-to-string (html nil :prologue nil :indent nil)
(:span (who:str "whatever")))
@jdz
jdz / text-graphics.lisp
Last active November 21, 2019 10:02
Turns out there was a bug...
;; Alternative graphics: "⣀⣄⣤⣦⣶⣷⣿" or "⠆⡇⡷⣿"
(defun bar (stream width n max &optional (graphics "▏▎▍▌▋▊▉█"))
"Draw an N/MAX bar no wider than WIDTH using charecters from GRAPHICS."
(declare (type number width n max)
(type string graphics))
(assert (<= 1 (length graphics))
(graphics)
"Invalid graphics provided: ~S" graphics)
(let* ((nchars (length graphics))
(inc (/ 1 nchars 2)))
@jdz
jdz / log.lisp
Created September 19, 2018 11:59
cl-log setup
(in-package #:pastelyser.log)
(defvar *categories* (make-instance 'cl-log:category-set))
(macrolet ((defcategory (category &optional expands-as)
`(cl-log:defcategory ,category ,expands-as *categories*)))
(defcategory :hit)
(defcategory :critical)
(defcategory :error (or :error :critical))
(defcategory :warning (or :warning :error))
@jdz
jdz / pg.md
Created February 10, 2017 09:15 — forked from benschwarz/pg.md
Awesome postgres

Keybase proof

I hereby claim:

  • I am jdz on github.
  • I am smuglispweenie (https://keybase.io/smuglispweenie) on keybase.
  • I have a public key whose fingerprint is 057D C86F 35D8 3051 88C1 4E1A 1AB6 BD2A AC66 2788

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am jdz on github.
* I am smuglispweenie (https://keybase.io/smuglispweenie) on keybase.
* I have a public key whose fingerprint is AC46 2D08 9883 7EC9 31DD 0799 9FC1 24B0 C3E5 B22E
To claim this, I am signing this object:
@jdz
jdz / gist:39febf2a1f50c7f0b119
Created May 13, 2014 20:39
Silly program in dynamic language
;;; The Ubuntu image file is 564MB, the largest file close to 1G I could
;;; quickly find.
(defun process (&optional (file #p"~/Downloads/ubuntu-14.04-server-amd64.iso"))
(declare (optimize (speed 3) (safety 1)))
(with-open-file (in file :direction :input
:element-type 'unsigned-byte)
(let ((buf (make-array #xffff :element-type '(unsigned-byte 8)))
(result 0))
(loop for read = (read-sequence buf in)
until (zerop read)