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 permutations [coll] | |
(letfn [(rotations [c vs] (reduce (fn [rotations _] | |
(conj rotations | |
(let [[head & tail] (peek rotations)] | |
(conj (vec tail) head)))) | |
[(conj vs c)] | |
vs))] | |
(cond-> (reduce (fn [permutations c] (mapcat (partial rotations c) permutations)) | |
[[]] | |
coll) |
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
;; (flatten-keys {:name {:first "Rich" :last "Hickey"} :number [1 415 123 4567]}) | |
;; => {"$.number[0]" 1, "$.number[1]" 415, "$.number[2]" 123, "$.number[3]" 4567, "$.name.first" "Rich", "$.name.last" "Hickey"} | |
(defn flatten-keys [thing] | |
(letfn [(-map-key [prefix k] (str prefix "." (name k))) | |
(-seq-key [prefix i] (str prefix "[" i "]")) | |
(-flatten-entry [make-key prefix result entry] | |
(let [[k v] entry] | |
(-flatten-thing result (make-key prefix k) v))) | |
(-flatten-thing [result key thing] |
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
;; Assuming you have already installed the 'mercurial' package in | |
;; emacs, follow the steps below to enable 'ediff' support in | |
;; the *hg-log-view*: | |
;; | |
;; 1) Add the following lines to your '.hgrc' such that the *hg-log-view* | |
;; of emacs shows the files that have changed in the detailed information | |
;; of a changeset: | |
;; | |
;; [ui] | |
;; verbose = True |
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
// Imperative | |
var fizzbuzz = 15 | |
var fizz = 3 | |
var buzz = 5 | |
for(i <- 1 to 100) { | |
val s = | |
if (i == fizzbuzz) { | |
fizz = fizzbuzz + 3 | |
buzz = fizzbuzz + 5 |