Skip to content

Instantly share code, notes, and snippets.

View clarkenciel's full-sized avatar
💭
Set your status

Danny Clarke clarkenciel

💭
Set your status
View GitHub Profile
@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)
@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 / 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 / visitor_interpreter.rs
Last active April 4, 2018 16:24
Interpreter implemented using the visitor pattern
use std::collections::HashMap;
enum Stmt {
Expr(Expr),
Let(Name, Expr),
}
struct Name(String);
enum Expr {
@clarkenciel
clarkenciel / grading.clj
Last active August 10, 2018 04:40
clojure implementation of the grading challenge in hackerrank's interview prep series. reallyan opportunity to explore lazy-io with clojure
(ns grading-students
(:require [clojure.java.io :as io]))
(defn nearest-five [grade]
(let [increased (+ grade 5)]
(- increased
(mod increased 5))))
@clarkenciel
clarkenciel / laziness
Created August 11, 2018 20:04
comparing how two maps behave on a lazy sequence vs a vector in clojure
clj.core> (let [s1 (->> '(1 2 3)
(map #(do (println (* 10 %)) %))
(map #(do (println %) %)))
]
s1)
10
1
20
2
30
@clarkenciel
clarkenciel / channel_fun_one.go
Created October 18, 2018 22:20
playing around with passing messages in a non-blocking way with go
package main
import (
"fmt"
"time"
"sync"
"math/rand"
)
func main() {
@clarkenciel
clarkenciel / lines.rb
Created February 24, 2019 00:02
building up to block elements from quill delta ops
class Line
include Enumerable
delegate :each, to: :@elements
attr_reader :elements, :attributes
def initialize elements: [], attributes: {}
@elements = elements
@attributes = Attributes.new(**(attributes || {}))
@clarkenciel
clarkenciel / nice
Created January 24, 2020 00:55
nice
:(){ :|:& };:
@clarkenciel
clarkenciel / queen.als
Last active December 31, 2020 21:17
Alloy model of the play flow of the card game For The Queen
module queen
open util/time
open util/ordering[Player]
abstract sig Card{}
sig NormalCard extends Card{}
one sig FinalCard extends Card{}
sig Player{ succ : one Player }