This file contains hidden or 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
; http://d.hatena.ne.jp/anton0825/20101229/1293213099 | |
; 大体そのまま移植しただけ | |
; dfs なのにstackを用意していないように見えるのは | |
; 言語のstackをstackとして利用しているため。 | |
(defn dfs [k [fs & res] sum] | |
(println sum fs res) | |
(if fs | |
(or (dfs k res (+ fs sum)) | |
(dfs k res sum)) | |
(= sum k))) |
This file contains hidden or 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
(defmulti foo (fn [x] x)) | |
;=> #<[object Object]> | |
(defmethod foo ::a [x] "a!") | |
;=> #<[object Object]> | |
; Hierarchy setting | |
(derive ::a1 ::a) | |
;=> nil | |
; works well |
This file contains hidden or 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
text-shadow: 0 1px 0 rgba(255,255,255,0.4),0 0 5px rgba(0,0,0,0.1); |
This file contains hidden or 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 init [] | |
(def main (goog.dom/getElement "main")) | |
(def mydiv (goog.dom/createDom "div")) | |
(goog.dom/appendChild main mydiv) | |
(defn change-color-mydiv [] | |
(... mydiv))) |
This file contains hidden or 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
;; moustache style | |
(defn update-thread [thread-id req] | |
...) | |
(def api-app | |
(mous/app | |
["threads" thread-id] {:put (partial update-thread thread-id)})) | |
;; path bind into request-map |
This file contains hidden or 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 sha1-str [s] | |
(->> (-> "sha1" | |
java.security.MessageDigest/getInstance | |
(.digest (.getBytes s))) | |
(map #(.substring | |
(Integer/toString | |
(+ (bit-and % 0xff) 0x100) 16) 1)) | |
(apply str))) |
This file contains hidden or 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
% lein run -m myexample.core | |
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: t in this context, compiling:(lamina/executors.clj:21) | |
at clojure.lang.Compiler.analyze(Compiler.java:6235) | |
at clojure.lang.Compiler.analyze(Compiler.java:6177) | |
at clojure.lang.Compiler$VectorExpr.parse(Compiler.java:2909) | |
at clojure.lang.Compiler.analyze(Compiler.java:6218) | |
at clojure.lang.Compiler.analyze(Compiler.java:6177) | |
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3452) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6411) | |
at clojure.lang.Compiler.analyze(Compiler.java:6216) |
This file contains hidden or 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 _-> | |
([x] x) | |
([x form] (if (seq? form) | |
(if (seq-utils/includes? form '_) | |
(with-meta `(~@(replace {'_ x} form)) (meta form)) | |
(with-meta `(~(first form) ~x ~@(next form)) (meta form))) | |
(list form x))) | |
([x form & more] `(_-> (_-> ~x ~form) ~@more))) | |
;-> and _-> are almost the same behavior until _ is specified. |
This file contains hidden or 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 rotate-90 [arr] | |
(reverse (apply map vector arr))) | |
(defn rotate [arr n] | |
(reduce (fn [x _] (rotate-90 x)) arr (range n))) | |
(defn slide [arr] | |
(let [width (dec (count (first arr)))] | |
(for [[i row] (seq-utils/indexed arr)] | |
(concat (repeat i ::empty) row (repeat (- width i) ::empty))))) |