Skip to content

Instantly share code, notes, and snippets.


Christophe christophejunke

  • France
View GitHub Profile
christophejunke / events.lisp
Last active Jun 26, 2021
Event loop with ncurse
View events.lisp
(ql:quickload '(:iolib :cl-charms))
(defpackage :tui (:use :cl :cl-charms :iomux))
(in-package :tui)
;;; From
(defun start-color ()
(when (eql (charms/ll:has-colors) charms/ll:FALSE)
(error "Your terminal does not support color."))
(let ((ret-code (charms/ll:start-color)))
christophejunke / map-lines.lisp
Created May 16, 2020
Map lines over an internal buffer - the callback must copy the string if needed, otherwise the underlying data changes.
View map-lines.lisp
(defpackage :map-lines (:use :cl))
(in-package :map-lines)
(defparameter *max-line-size* 65536)
(defparameter *default-buffer-size* 16384)
(declaim (inline map-lines-on-shared-buffer))
(define-condition internal-buffer-overflow (error)
((buffer :reader internal-buffer-overflow/buffer :initarg :buffer)
View day-14.lisp
(defpackage :advent.2019.14
(:use :cl :alexandria :cl-ppcre)
(:import-from :series #:collect #:map-fn #:scan-stream))
(in-package :advent.2019.14)
(defun parse-reactions (stream)
(labels ((reaction (line)
(destructuring-bind (in out) (split " => " line)
(mapcar #'compound (list* out (split ", " in)))))
View day-13.lisp
(in-package :advent.2019.intcode)
;; utils
(defun make-command-queue (size)
(assert (plusp size))
(let* ((commands (make-list size))
(head commands))
(lambda (value callback)
(setf (car head) value)
View day-10.lisp
(defpackage :advent.2019.10 (:use :cl :alexandria))
(in-package :advent.2019.10)
;; (setf *default-pathname-defaults* #P"~/data/advent/2019/")
;; day 10 - part 1
(defun map-map (fn stream &aux (y 0) (x 0))
(flet ((callback () (funcall fn x y)))
View day-03-alt.lisp
(defpackage :advent.2019.03-alt (:use :cl :alexandria :cl-ppcre))
(in-package :advent.2019.03-alt)
(defstruct seg lo hi o d z)
(defstruct (hseg (:constructor hseg (lo hi o d z)) (:include seg)))
(defstruct (vseg (:constructor vseg (lo hi o d z)) (:include seg)))
(defun seg (type from to z)
(funcall type
(min from to)
View day-03.lisp
(in-package :advent.2019)
(defstruct (point (:conc-name) (:constructor point (x y))) x y)
(defstruct (segment (:conc-name)) from to)
(defstruct (hsegment (:constructor hsegment (from to)) (:include segment)))
(defstruct (vsegment (:constructor vsegment (from to)) (:include segment)))
(defun manhattan (p1 p2)
(+ (abs (- (x p2) (x p1)))
(abs (- (y p2) (y p1)))))
View regular-time.lisp
(defpackage :o (:use :cl :bricabrac.sdl2.event-loop :sdl2))
(in-package :o)
(defgeneric handle-event (state event type)
(:method (state event type))
(:method (state event (type (eql :quit)))
(throw :quit :quit)))
(defun clock-ms ()
(round (* (osicat:get-monotonic-time) 1000)))
View gist:f2cfb21aa20ffcf4f30e6d6907defeb6
(defpackage :ev (:use :cl :optima :alexandria))
(in-package :ev)
(defstruct (meta (:constructor meta (form))) form)
(defun alist/augment (env namespace key value)
(acons namespace (acons key value (cdr (assoc namespace env))) env))
(defun alist/augment* (env namespace fresh-alist)
(acons namespace (nconc fresh-alist (cdr (assoc namespace env))) env))
christophejunke /
Last active Dec 31, 2018
FizzBuzz alternative
% tested with
divisors_term(_, [3,5],"FizzBuzz").
divisors_term(_, [3], "Fizz").
divisors_term(_, [5], "Buzz").
divisors_term(N, [], N).
% first clause, always fails, but with side-effects
fizz_buzz :-
% backtrackably iterates N from 1 to 100 by 1