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
## 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 / 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)]
@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 / download.txt
Last active January 9, 2020 19:20
clj-ssh errors
java.lang.IllegalArgumentException: No matching clause: 
at clj_ssh.ssh$scp_sink.invokeStatic(ssh.clj:981) ~[classes/:na]
at clj_ssh.ssh$scp_sink.invoke(ssh.clj:977) ~[classes/:na]
at clj_ssh.ssh$scp_from.invokeStatic(ssh.clj:1094) ~[classes/:na]
at clj_ssh.ssh$scp_from.doInvoke(ssh.clj:1044) ~[classes/:na]
(defn converger
"Generates a convergence context for n threads, where values are converged
when (converged? values) returns true."
[n converged?]
(atom {; The convergence function
:converged? converged?
; What threads are involved?
:threads []
; And what values did they most recently come to?
:values (vec (repeat n ::init))}))
@aphyr
aphyr / banned-friends.rb
Created June 12, 2019 15:48
A small script to list which of the people you follow are visible in public twitter autocomplete searches.
#!/usr/bin/ruby
# This script tells you which of your friends (people you follow) are
# auto-completable in public twitter user searches, e.g. by typing
# @username" into the search box. It takes four arguments for twitter
# API credentials: consumer_key, consumer_secret, access_token, and
# access_token_secret. You can create an twitter API app at
# https://developer.twitter.com/.
# Output is a tab-separated list of accounts, one per line, where the
Let:
T1 = {:type :ok, :f :txn, :value [[:r 132 [1 2]] [:append 134 2] [:r 127 [1 2 3 6]]], :process 13, :time 174587090574, :index 2314}
T2 = {:type :ok, :f :txn, :value [[:append 132 3] [:r 133 [1]] [:append 134 1] [:r 132 [1 2 3]]], :process 14, :time 174415701895, :index 2300}
T3 = {:type :ok, :f :txn, :value [[:append 134 4] [:r 127 [1 2 3 6]]], :process 14, :time 174480602924, :index 2308}
Then:
- T1 < T2, because T1 did not observe T2's append of 3 to 132.
- T2 < T3, because T3 appended 4 after T2 appended 1 to 134.
- However, T3 < T1, because T1 appended 2 after T3 appended 4 to 134: a contradiction!
Let:
T1 = {:type :ok, :f :txn, :value [[:append 237 3] [:r 233 [1 3 5 6 7 8 9]] [:append 237 4] [:append 238 1]], :process 16, :time 207412818568, :index 4098}
T2 = {:type :ok, :f :txn, :value [[:append 233 10] [:r 239 [1]] [:append 237 5]], :process 22, :time 206702615066, :index 4054}
T3 = {:type :ok, :f :txn, :value [[:r 233 [1 3 5 6 7 8 9 10]] [:r 238 [2]] [:append 237 7] [:r 239 [1]]], :process 22, :time 206769955506, :index 4058}
T4 = {:type :ok, :f :txn, :value [[:append 238 3] [:append 237 8]], :process 22, :time 206852651070, :index 4060}
T5 = {:type :ok, :f :txn, :value [[:append 238 4] [:r 239 [1]] [:r 241 nil]], :process 22, :time 206919825209, :index 4064}
T6 = {:type :ok, :f :txn, :value [[:r 238 [2 3 4]] [:append 239 2] [:append 241 1] [:append 239 3]], :process 22, :time 206984932481, :index 4068}
T7 = {:type :ok, :f :txn, :value [[:r 241 [1 2 3]] [:r 239 [1 2 3]] [:append 238 6]], :process 22, :time 207330867948, :index 4090}
Then: