Skip to content

Instantly share code, notes, and snippets.

View aphyr's full-sized avatar
💭
be gay, do crimes

Kyle Kingsbury aphyr

💭
be gay, do crimes
View GitHub Profile
@aphyr
aphyr / minikanren.pl
Created October 12, 2020 22:10
Minikanren in Lisp in Prolog
:- use_module(library(pairs)).
:- use_module(library(reif)).
not_in_list(K, L) :-
if_((L = []),
true,
([X | More] = L,
dif(K, X),
not_in_list(K, More))).
@aphyr
aphyr / biglisp.pl
Created October 12, 2020 22:08
Another Lisp interpreter, in Prolog
use_module(library(lists)).
/* Bind updates a state given a list of binding names and a list of
corresponding values. The special binding form &(args) binds `args` to all
remaining arguments. Used to update contexts for e.g. function evaluation. */
bind(S, S, [], []).
/* Varargs */
bind(S1, S2, [&(Var)], Vals) :-
S2 = S1.put(Var, Vals).
bind(S1, S3, [Var | Vars], [Val | Vals]) :-
@aphyr
aphyr / smolisp.pl
Created October 12, 2020 22:06
Prolog implementation of McCarthy's metacircular lisp interpreter, following pg's explication
:- use_module(library(reif)).
axiom([quote, X], X).
axiom([atom, X], R) :-
axiom(X, XR),
((atomic(XR), R = t, !) ;
(compound(XR), R = [])).
axiom([eq, X, Y], R) :-
@aphyr
aphyr / bifurcan-lazy-union.clj
Last active December 12, 2024 18:48
Lazy views over n merged Bifurcan collections, assuming disjoint keys for sets/maps.
(ns bifurcan-lazy-union
(:require [bifurcan-clj [core :as b]
[list :as bl]
[map :as bm]
[set :as bs]]
[dom-top.core :refer [loopr]]
[potemkin :refer [definterface+]])
(:import (io.lacuna.bifurcan ISet
Lists
Sets
@aphyr
aphyr / gist:3043505
Created July 3, 2012 21:42
A nice recruiter letter
Hi Kyle,
My name is Tammy and I am on the team at Riviera Partners. Your name surfaced
in several of my searches today and across various filters - from distributed
systems to Clojure and encompassing Ruby and JavaScript. Well-rounded
individual, are we? I also heard from a former colleague of mine that your
programming began at the tender age of 2.... impressive! I just signed up for
CodeAcademy - should be interesting!
I am not sure how things are going for you at Boundary (are you still there)?
## Clean new node
[x] Shut down Mastodon
[x] Shut down ES
[x] Shut down Redis
[x] Delete ES data
[x] Delete Redis data
[x] Delete Postgres data
## Prep new node
@aphyr
aphyr / with-retry.clj
Created January 20, 2016 03:14
Recur from within catch block
(defrecord Retry [bindings])
(defmacro with-retry
"It's really fucking inconvenient not being able to recur from within (catch)
expressions. This macro wraps its body in a (loop [bindings] (try ...)).
Provides a (retry & new bindings) form which is usable within (catch) blocks:
when this form is returned by the body, the body will be retried with the new
bindings."
[initial-bindings & body]
(assert (vector? initial-bindings))
@aphyr
aphyr / pdf-sign
Created June 10, 2016 15:40
Script to sign the final page of a PDF using inkscape and pdfseparate/pdfunite.
#!/bin/bash
DIR=`mktemp -dt pdf-sign.XXXXXXXX` || exit 1
cd "$DIR"
pdfseparate "$1" "$DIR/page%d.pdf"
inkscape `ls | tail -1`
pdfunite page*.pdf "$1 signed.pdf"
rm -rf "$DIR"
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
/**
* Boggle.
*
* @author Kyle Kingsbury
*
@aphyr
aphyr / multi-dimension.clj
Created December 21, 2021 20:31
loopr single-accumulator reductions
user=> (-> '(dt/loopr [sum 0] [x xs, y ys] (recur (+ sum x y))) macroexpand pprint)
(let* [sum 0
sum (clojure.core/reduce
(clojure.core/fn reduce-x-2690 [sum x]
(clojure.core/reduce (clojure.core/fn reduce-y-2692 [sum y]
(. clojure.lang.Numbers (add (. clojure.lang.Numbers (add sum x)) y)))
sum
ys))
sum
xs)]