Skip to content

Instantly share code, notes, and snippets.

View kisp's full-sized avatar

Kilian Sprotte kisp

  • Berlin, Germany
  • 04:20 (UTC +02:00)
View GitHub Profile
@kisp
kisp / _tests.lisp
Last active April 21, 2024 10:49
Using MithrilJS/ospec with parenscript
;; MithrilJS/ospec: Noiseless testing framework
;; https://github.com/MithrilJS/ospec
;; {
;; "devDependencies": {
;; "ospec": "^4.2.0"
;; }
;; }
;; Parenscript
@kisp
kisp / application.js
Created February 12, 2024 21:44
Disable page prefetching when hovering with the mouse over links in turbo for Rails 7
// app/javascript/application.js
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
// Add this line
Turbo.session.linkPrefetchObserver.stop()
@kisp
kisp / grep_for_complements.md
Created February 7, 2024 17:35
grep for complements

grep for complements

Imagine you have a CLI command cat myfile | ./my-filter, and now you want to see all the lines not selected, essentially negating my-filter. Here is a way to achieve that.

The "grep for complements" command is a useful tool for filtering out lines from a file that have not been selected by a custom filter. This can be achieved using a combination of cat, your custom filter (./my-filter), and grep.

Usage

To use "grep for complements", follow these steps:

@kisp
kisp / cosine-rule.mac
Last active January 15, 2024 02:29
Deriving the Law of cosines c^2 = a^2 + b^2 - 2*a*b*cos(θ) in maxima
/*
You can run this file with
maxima -b cosine-rule.mac
or maybe also using M-x quickrun
*/
/*
@kisp
kisp / cartesian-product.lisp
Created January 5, 2024 13:28
Developing a function (cart-prod a b) to compute the cartesian product of two lists a and b and proving it sound and complete.
;; Note: This is a work in progress
;;
;; A function (cart-prod a b) is developed here that computes the cartesian
;; product of two lists.
;;
;; For example:
;;
;; (cart-prod '(1 2 3) '(a b)) => ((1 a) (1 b) (2 a) (2 b) (3 a) (3 b))
;;
;; The function cart-prod is proven sound and complete by the theorems
@kisp
kisp / small-check-series.lisp
Last active December 28, 2023 21:49
Implementing Haskell's Test.SmallCheck.Series in Common Lisp using Screamer
;; -*- mode: lisp; -*- ;; (ql:quickload "screamer")
(in-package :screamer-user)
;; SmallCheck and Lazy SmallCheck - automatic exhaustive testing for small values
;; https://www.cs.york.ac.uk/fp/smallcheck/smallcheck.pdf
(defun an-integer-upto-depth (depth)
(either
0
@kisp
kisp / number-to-digits10.lisp
Last active December 16, 2023 19:53
Proving the conversion of a natural number to a list of digits (base 10) correct with ACL2
;;; The following code implements the conversion of a natural number
;;; to a list of digits and back.
;;; ACL2 Version 8.5
;;; https://www.cs.utexas.edu/users/moore/acl2/
;;; ACL2 is used to prove that one conversion followed by the other
;;; leads back to the initial value (roundtrip). This is proved in
;;; both directions:
;;; starting from a natural number (see main/base10-representation-1
@kisp
kisp / destructuring-match.lisp
Last active December 1, 2023 19:01
Pattern matching for Common Lisp with one simple macro: destructuring-match
(in-package :cl-user)
;;; destructuring-match
;;;
;;; Really simple implementation of pattern matching with multiple
;;; clauses for Common Lisp (using one implementation detail of SBCL
;;; here, namely sb-kernel::defmacro-lambda-list-bind-error).
;;;
;;; Like a combination of destructuring-bind and case.
;;;
@kisp
kisp / maybe.lisp
Last active November 28, 2023 13:02
Defining an algebraic data type in SBCL using defstruct, deftype, and trivia:match: data Maybe a = Nothing | Just a
(in-package :cl-user)
;; (ql:quickload '("alexandria" "trivia"))
;; Let's define maybe as an algebraic data type.
(defstruct (nothing (:constructor nothing ())))
(defstruct (just (:constructor just (value))) value)
(deftype maybe () '(or nothing just))
;; (>>=) :: Monad m => m a -> (a -> m b) -> m b
@kisp
kisp / run-unison.sh
Last active October 17, 2023 15:47
Setup unison sync with local configuration directory
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")"
export UNISON=$(pwd)/.unison
mkdir -p "$UNISON"