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 ensure-ns [ns-name] | |
(when-not (find-ns (symbol ns-name)) | |
(.setDynamic | |
(intern (create-ns (symbol ns-name)) '*me* "never-seen"))) | |
(the-ns (symbol ns-name))) | |
(defn eval-w-bindings [user-code ns-name user] | |
(let [my-ns (ensure-ns ns-name)] | |
(with-bindings {#'*ns* my-ns | |
(ns-resolve my-ns '*me*) user} |
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
(when (not (find-ns 'mattermost)) | |
(.setDynamic ;; <- This horrific interop into Var.java to counter | |
(intern (create-ns 'mattermost) ;; CLJ-951, which is a closed/wishlist bug reporting that | |
(with-meta '*me* {:dynamic true}) ;; <- this is actually not propagated fully (is, in fact, useless) :( | |
"foo"))) | |
(defn eval-w-bindings [str user] | |
(binding [*ns* (create-ns 'mattermost) | |
mattermost/*me* user] | |
(clojure.core/refer 'clojure.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
(def jquery (js* "$")) | |
(defn show [msg] | |
(let [data-as-json ((js* "JSON.stringify") msg nil 4)] | |
((js* "alert") data-as-json))) | |
(defn make-js-map | |
"makes a javascript map from a clojure one" | |
[cljmap] | |
(let [out (js-obj)] |
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
(def size 6) | |
(def rules {:be-born? #(contains? #{3} %) ;; high-life has this as #{3 6} | |
:stay-alive? #(contains? #{2 3} %)}) | |
(def glider #{[2 0] [0 1] [2 1] [1 2] [2 2]}) | |
(defn live? [xy gen] | |
(contains? gen xy)) |
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
(def r' (comp r r r)) | |
(def r2 (comp r r)) |
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
(def moves {:r r :r' r' :r2 r2 | |
:l l :l' l' :l2 l2 | |
:u u :u' u' :u2 u2 | |
:d d :d' d' :d2 d2 | |
:f f :f' f' :f2 f2 | |
:b b :b' b' :b2 b2}) | |
(def move-names (keys moves)) | |
(defn create-scramble [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
(get-in solved-cube [:f3 0]) | |
;; => :g | |
(assoc-in solved-cube [:f3 0] :w) | |
;; => a value identical to solved-cube except one sticker | |
;; changed from green to white (it's not a valid cube | |
;; layout any more). solved-cube is unaltered. | |
;; using the -> macro to 'thread' these together | |
(-> solved-cube |
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
(let [moves (create-scramble 14) | |
scrambled-cube (reduce apply-named-move solved-cube moves)] | |
;; do something with the scrambled cube | |
) |
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 face-cycle [c [q1 q2 q3 q4]] | |
(-> c | |
(assoc-in q2 (get-in c q1)) | |
(assoc-in q3 (get-in c q2)) | |
(assoc-in q4 (get-in c q3)) | |
(assoc-in q1 (get-in c q4)))) | |
(defn r [c] | |
(-> c | |
(face-cycle [[:f1 1] [:f6 1] [:f5 1] [:f3 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
;; f1 | |
;; f2 f3 f4 | |
;; f5 | |
;; f6 | |
(def solved-cube | |
{:f1 [:w :w | |
:w :w] | |
:f2 [:o :o | |
:o :o] |