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 cljs-storybook.components | |
(:require | |
[om.next :as om :refer-macros [defui]] | |
[om.dom :as dom] | |
cljsjs.react)) | |
(defn assign-ref [this ref] | |
(fn [el] | |
(aset this ref el))) |
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
(name :foo/bar) | |
(namespace :foo/bar) | |
(namespace (keyword (name :foo/bar/baz))) | |
(keyword "foo" "bar/baz") | |
(keyword "foo" (str (keyword "bar" "baz"))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(use 'criterium.core) |
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 histo-water [l] | |
(->> l | |
(map-indexed #(vector | |
%2 | |
(reduce max 0 (subvec l 0 %1)) | |
(reduce max 0 (subvec l %1)))) | |
(map #(- (min (second %) (nth % 2)) (first %))) | |
(filter pos?) | |
(reduce +))) |
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 swap [v i1 i2] | |
(assoc v i2 (v i1) i1 (v i2))) |
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 max-index [v] | |
(->> v | |
(map-indexed vector) | |
(apply max-key second) | |
(first))) |
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 Y [f] | |
((fn [x] (x x)) | |
(fn [x] | |
(f (fn [& args] | |
(apply (x x) args)))))) | |
(def fac | |
(fn [f] | |
(fn [n] | |
(if (zero? n) 1 (* n (f (dec n))))))) |
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 halve [i] | |
(bit-shift-right i 1)) | |
(defn double [i] | |
(bit-shift-left i 1)) | |
(defn mul [x y] | |
(let [x (take-while #(not= % 0) (iterate halve x))] | |
(->> y | |
(iterate double) |
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 double [i] | |
(bit-shift-left i 1)) | |
(defn to-binary-seq [^long x] | |
(map #(- (int %) (int \0)) | |
(Long/toBinaryString x))) | |
(defn addition-chain [x] | |
(reduce #(if (zero? %2) | |
(conj %1 (double (peek %1))) |
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 map-longest [f default & colls] | |
(lazy-seq | |
(when (some seq colls) | |
(cons | |
(apply f (map #(if (seq %) (first %) default) colls)) | |
(apply map-longest f default (map rest colls)))))) |
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 str-to-longs [^String s] | |
(map #(Character/codePointAt s (long %)) (range (count s)))) |
OlderNewer