Skip to content

Instantly share code, notes, and snippets.

View adlai's full-sized avatar
☠️
THERE IS WAR, I AM SAD

Adlai adlai

☠️
THERE IS WAR, I AM SAD
View GitHub Profile
@adlai
adlai / bitbet.lisp
Last active October 16, 2018 10:56
Parimutuel Payout pProximation
(use-package (mapcan 'ql:quickload '(:drakma :cl-json :local-time)))
(defun fetch-bet-json (id)
(http-request (format () "http://bitbet.us/bet/~D/?json" id)))
(defun parse-json-str (str) (with-input-from-string (in str) (decode-json in)))
(defun process-bet-data (data)
(loop for bet in (cdr (assoc :bets data))
for side = (cdr (assoc :side bet))
@adlai
adlai / coinswap.txt
Last active March 19, 2021 23:40
Adapting CoinSwap for a Fungibility Market
In the protocol all parties are assumed to have private communications channels.
Phase 0. Sets up the escrows and their timeout refunds.
Phase 1. Makes it so that if Bob gets paid there is no way for Alice to fail to get paid.
Phase 2. Just releases the escrows directly because everyone is happy that cheating isn't possible.
Alice Bob
=========================================================
0. Compute TX_0: A>2of2{A,B'} | Compute TX_1: B>2of2{B,A'} \
1. Send TX_0 TXID ------------> |
@adlai
adlai / perceptron.lisp
Created December 22, 2014 06:36
"Learning from Data" HW1
(defparameter *minimum* -1d0)
(defparameter *maximum* +1d0)
(defun random-point ()
(list (+ *minimum* (random (- *maximum* *minimum*)))
(+ *minimum* (random (- *maximum* *minimum*)))))
(defun random-line () (loop repeat 2 collect (random-point)))
(defun dot-product (a b) (reduce #'+ (mapcar #'* a b)))
@adlai
adlai / rehome-class.lisp
Last active September 19, 2024 21:09
package hackery for moving classes between packages
(defgeneric rehome-class (class new-home)
(:method ((class symbol) new-home)
(rehome-class (find-class class) (find-package new-home)))
(:method ((class class) (new-home package))
(let ((old-home (symbol-package (class-name class)))
(symbols `(,(class-name class)
,@(mapcar 'sb-mop:slot-definition-name
(sb-mop:class-direct-slots class)))))
(mapc (lambda (symbol) (unintern symbol old-home)) symbols)
(import symbols new-home)