This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hash-set-bench | |
"A Benchmark I modified to Clojure from: | |
https://github.com/c-cube/hashset_benchs") | |
(defn iterNeighbors [f [i j]] | |
(f [(dec i) j]) | |
(f [(inc i) j]) | |
(f [i (dec j)]) | |
(f [i (inc j)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns spec-test.virtual-time | |
(:require [clojure.spec :as s] | |
[clojure.spec.test :as st])) | |
(s/def ::virtual-time | |
(s/or | |
:positive-infinity #{:positive-infinity} | |
:negative-infinity #{:negative-infinity} | |
:number number?)) | |
(s/fdef vt-lt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns spec-test.virtual-time | |
(:require [clojure.spec :as s] | |
[clojure.spec.test :as st] | |
[clojure.spec.gen :as sgen])) | |
(deftype VirtualTime [time] | |
Object | |
(hashCode [_] | |
(hash time)) | |
(equals [this that] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) ""))))) | |
2))] | |
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns counter.core | |
(:require [reagent.core :as r])) | |
;;;; Utils | |
(defn ratom? [a] | |
(= reagent.ratom/RAtom (type a))) | |
(defn make-state [state] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro defnk | |
[name & fdecl] | |
(let [doc-string? (when (string? (first fdecl)) | |
(first fdecl)) | |
fdecl (if (string? (first fdecl)) | |
(next fdecl) | |
fdecl) | |
attr-map? (when (map? (first fdecl)) | |
(first fdecl)) | |
fdecl (if (map? (first fdecl)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#letnoshadow.clj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#clojurescript-counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn api-pred [e] | |
(Thread/sleep 100) | |
(even? e)) | |
(let [coll-to-process (range 1000) | |
concurrency 100 | |
agents (repeatedly concurrency #(agent []))] | |
(doseq [[i agnt] (map vector coll-to-process (cycle agents))] | |
(send-off agnt | |
#(if (api-pred i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; From: https://clojuredocs.org/clojure.core/chunk#example-5c9cebc3e4b0ca44402ef6ec | |
(defn re-chunk [n xs] | |
(lazy-seq | |
(when-let [s (seq (take n xs))] | |
(let [cb (chunk-buffer n)] | |
(doseq [x s] (chunk-append cb x)) | |
(chunk-cons (chunk cb) (re-chunk n (drop n xs))))))) | |
;; Simply wrap the collection or seq/lazy-seq with re-chunk and the configured chunk size will make pmap's concurrency level grow to the size of the chunk. | |
(time (dorun (pmap (fn[e] (Thread/sleep 100) (inc e)) (re-chunk 100 (range 1000))))) |
OlderNewer