Skip to content

Instantly share code, notes, and snippets.

View christophejunke's full-sized avatar

chris christophejunke

  • France
  • 02:09 (UTC +02:00)
View GitHub Profile
(defun fizz-buzz ()
(loop for i from 1 upto 100 do
(when (= 0 (mod i 3))
(princ "Fizz"))
(when (= 0 (mod i 5))
(princ "Buzz"))
(when (fresh-line)
(print i))))
@christophejunke
christophejunke / graph.lisp
Last active August 29, 2022 22:18
display graphs
(defun decorate-for-error (fn on-error signalp)
(cond
(signalp fn)
(t (lambda (&rest args)
(handler-case (apply fn args)
(error () on-error))))))
(defun domain-union (t1 t2)
(let ((union (list 'or t1 t2)))
(defvar *big* (simulate "06-ex" 9999999))
;; 3.75 min later
(defvar *as-str* (format nil "~d" *big*))
(length *as-str*)
=> 378346
(subseq *as-str* 0 20)
=> "41825991834876534637"
(defpackage :test-macro (:use :cl))
(in-package :test-macro)
(define-condition some-info ()
((data :accessor data :initarg :data)))
(defmacro with-metadata (macro-name &body body &environment env)
(let (stuff)
(handler-bind ((some-info (lambda (c) (push (data c) stuff))))
(sb-cltl2:macroexpand-all
type command =
| Up of int
| Down of int
| Forward of int
type p1 = {
horiz : int;
depth : int;
}
@christophejunke
christophejunke / col.lisp
Created August 13, 2021 13:27
colored symbols
(defpackage :col (:use :cl))
(in-package :col)
(ql:quickload :cl-ansi-text)
(defparameter *print-color* t)
;; Attach a color attribute to symbols
(defun color (symbol)
@christophejunke
christophejunke / events.lisp
Last active June 26, 2021 19:42
Event loop with ncurse
(ql:quickload '(:iolib :cl-charms))
(defpackage :tui (:use :cl :cl-charms :iomux))
(in-package :tui)
;;; From http://turtleware.eu/posts/cl-charms-crash-course.html
(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
christophejunke / map-lines.lisp
Created May 16, 2020 13:46
Map lines over an internal buffer - the callback must copy the string if needed, otherwise the underlying data changes.
(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)
(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)))))
(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)