Skip to content

Instantly share code, notes, and snippets.

@minimal
minimal / core_test.clj
Last active November 27, 2018 15:10
testing monoids with test.check
(defn passes-monoid-props
[f id a b c]
(and (= (f (f a b) c) (f a (f b c))) ;; associativity
(= (f a id) a) ;; identity element
(= (f id a) a)))
(defspec plus-zero-are-monoid 100
(prop/for-all [[a b c] (gen/vector gen/int 3)]
(passes-monoid-props + 0 a b c)))
(defn flip-map
"Map of vals to keys"
[col]
(persistent! (reduce-kv (fn [m k v] (assoc! m v k))
(transient {}) col)))
(ns protobuf-exp.core
(:require [flatland.protobuf.core :as pb])
(:import pi.Pages$Page))
(def Page (pb/protodef Pages$Page))
(def p (pb/protobuf Page :id 1 :url "http://blah.com" :description "I am a protobuf"))
(defn write-to-file [proto path]
(with-open [myout (clojure.java.io/output-stream path)]
(.write myout (pb/protobuf-dump proto))))
(ann get-from-state
(t/All [a b]
[(t/Option (t/Map b a)) (t/Option (t/Coll b)) -> (t/Option a)]))
(defn get-from-state [state keys]
(t/loop [acc :- (t/Option a) nil
keys :- (t/Option (t/Coll b)) keys]
(if-not (and state (seq keys))
acc
(recur (get state (first keys))
(rest keys)))))
@minimal
minimal / keybase.md
Created September 19, 2014 10:44
keybase

Keybase proof

I hereby claim:

  • I am minimal on github.
  • I am chrismcdevitt (https://keybase.io/chrismcdevitt) on keybase.
  • I have a public key whose fingerprint is AD6C C227 E816 B829 5EE1 9083 AAA3 B78C 930D DCC6

To claim this, I am signing this object:

(ns corematch-exp.core
(:require [clojure.core.match :refer (match)]))
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(let [x [1 2 3]]
(match [x]
module Data.PhoneBook where
import Data.List
import Data.Maybe
import Control.Plus (empty)
type Entry = { firstName :: String, lastName :: String, phone :: String }
type PhoneBook = List Entry
@minimal
minimal / core.clj
Created January 4, 2014 14:10
Load json from Netflix PigPen
(ns pigpen-exp.core
(:require [pigpen.core :as pig]
[pigpen.raw :as raw]
[clojure.data.json])
(:gen-class))
(defmacro load-json
"Loads json data from a file. Each line should contain one value and
will be parsed using clojure.data.json/read-str into a value. Keys are
converted to keywords.

how to use clang in your clojurescript project

https://github.com/pangloss/clang

  • add [clang "0.1.0-SNAPSHOT"] to your project :dependencies
  • checkout clang repo somewhere

in your project root:

@minimal
minimal / core.clj
Last active December 24, 2015 18:49
(ns typed-clj-exp.core
(:require [clojure.core.typed :refer [ann check-ns typed-deps
def-alias ann-datatype for>
fn> ann-form AnyInteger doseq>
cf inst letfn> override-method
dotimes> loop>]
:as t]))
;; avoid null pointer exceptions at compile time