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 / safetraverse.ts
Created September 13, 2022 16:08
Stack-safe traversable in fp-ts
import * as r from "fp-ts/Reader"
import * as array from "fp-ts/ReadonlyArray"
import * as option from "fp-ts/Option"
import * as either from "fp-ts/Either"
import * as fn from "fp-ts/function"
import type * as cr from "fp-ts/ChainRec"
import type * as applicative from "fp-ts/Applicative"
import type * as hkt from "fp-ts/HKT"
import type * as functor from "fp-ts/lib/Functor"
import type * as foldable from "fp-ts/lib/Foldable"

Keybase proof

I hereby claim:

  • I am clarkenciel on github.
  • I am clarkenciel (https://keybase.io/clarkenciel) on keybase.
  • I have a public key ASDZNa1JVCfIPwNGB17fq5DTL4jq6i_X6viPw29TLKPZLgo

To claim this, I am signing this object:

@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 }
@clarkenciel
clarkenciel / nice
Created January 24, 2020 00:55
nice
:(){ :|:& };:
@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 / 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 / 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 / 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 / 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 / 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)
#