Skip to content

Instantly share code, notes, and snippets.

@clarkenciel
clarkenciel / cross_product.py
Created February 17, 2018 01:15
cartesian product on an arbitrary number of lists. inspired by haskellers saying this is "just `sequence` on the list monad"
# sequence :: Monad m => [m a] -> m [a]
#
# a way of implementing this functionality is through a left fold
# that unwraps the each monad in the first list and accumulates it
# in the second list, rewrapped in the target monad:
#
# sequence actions = foldl unwrapAccumulateRewrap (return []) actions
# where unwrapAccumulateRewrap wrappedAccumulator action =
# wrappedAccumulator >>= \accumulator -> action >>= \value -> return (value : accumulator)
#
@clarkenciel
clarkenciel / npnn.py
Created December 2, 2017 00:00
numpy neural net
import numpy as np
from random import choice
def feed_forward(network, input, activation):
activations = [input]
output = input
for layer in network:
output = activation(np.dot(output, layer))
@clarkenciel
clarkenciel / policy.lisp
Created September 16, 2017 06:48
sketch for a `defpolicy` macro in common lisp
(defclass user ()
((name :reader user-name :initarg :name)
(roles :reader user-roles :initarg :roles)))
(defclass role ()
((name :reader role-name :initarg :name)))
(defclass post ()
((author-name :reader author :initarg :author)
(title :accessor post-title :initarg :title :initform nil)