Skip to content

Instantly share code, notes, and snippets.

didibus / UNLICENSE
Last active Feb 16, 2020
A Clojure macro which gives you a let that does not allow shadowing of symbols already declared.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
didibus / core.clj
Created Sep 10, 2019
Clojure datafy/nav example
View core.clj
(ns datafy_test.core
(:require [clojure.datafy :as d]
[clojure.core.protocols :as p]))
(defprotocol PName
(getFirst [this])
(getLast [this]))
(deftype Name
[^String first
^String last]
didibus / defnk.clj
Last active Nov 3, 2018
Clojure macro to define strict keyword argument functions
View defnk.clj
(defmacro defnk
[name & fdecl]
(let [doc-string? (when (string? (first fdecl))
(first fdecl))
fdecl (if (string? (first fdecl))
(next fdecl)
attr-map? (when (map? (first fdecl))
(first fdecl))
fdecl (if (map? (first fdecl))
didibus / reagent-counter.cljs
Last active Jul 16, 2018
A simple counter implemented in ClojureScript using reagent as the only dependency.
View reagent-counter.cljs
(ns counter.core
(:require [reagent.core :as r]))
;;;; Utils
(defn ratom? [a]
(= reagent.ratom/RAtom (type a)))
(defn make-state [state]
didibus / core.cljs
Last active Jul 15, 2018
Example of a simple ClojureScript implementation of a counter, using no dependencies.
View core.cljs
(ns counter.core
(:require [cljs.pprint :refer [cl-format]]))
;;;; Model
(def model (atom 0))
;;;; Update
didibus / abstract-factory.clj
Created Apr 13, 2017
My attempt at what the abstract factory pattern would look like in Clojure
View abstract-factory.clj
(defn draw-ui [{:keys [label casing content]}]
(let [pad (Math/floor (/ (- (Math/max (count label) (count (or (:label content) "")))
(+ 2 (Math/min (count label) (count (or (:label content) "")))))
(println (str "|" (if (= :upper casing)
(.toUpperCase label)
(.toLowerCase label)) "|" \newline
"|" (reduce (fn [a b] (str a " ")) "" label) "|" \newline
(when content
(str "|" (apply str (repeat pad \space))
didibus / virtual-time.clj
Created Apr 11, 2017
My deftype based take on the google group question found here:!topic/clojure/oe1Ch1oSlLk
View virtual-time.clj
(ns spec-test.virtual-time
(:require [clojure.spec :as s]
[clojure.spec.test :as st]
[clojure.spec.gen :as sgen]))
(deftype VirtualTime [time]
(hashCode [_]
(hash time))
(equals [this that]
View virtual-time.clj
(ns spec-test.virtual-time
(:require [clojure.spec :as s]
[clojure.spec.test :as st]))
(s/def ::virtual-time
:positive-infinity #{:positive-infinity}
:negative-infinity #{:negative-infinity}
:number number?))
(s/fdef vt-lt
View gist:1fd4c00b69d927745fbce3dcd7ca461a
(ns hash-set-bench
"A Benchmark I modified to Clojure from:")
(defn iterNeighbors [f [i j]]
(f [(dec i) j])
(f [(inc i) j])
(f [i (dec j)])
(f [i (inc j)]))
You can’t perform that action at this time.