Skip to content

Instantly share code, notes, and snippets.

; 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)))
@hozumi
hozumi / multi.clj
Created January 18, 2012 07:06
Multimethods bug
(defmulti foo (fn [x] x))
;=> #<[object Object]>
(defmethod foo ::a [x] "a!")
;=> #<[object Object]>
; Hierarchy setting
(derive ::a1 ::a)
;=> nil
; works well
@hozumi
hozumi / file0.css
Created January 4, 2012 15:14
text-shadowやbox-shadowにalphaなグラデーションかけるとかなりかっこ良くなる ref: http://qiita.com/items/1569
text-shadow: 0 1px 0 rgba(255,255,255,0.4),0 0 5px rgba(0,0,0,0.1);
@hozumi
hozumi / foo.cljs
Created December 26, 2011 12:17
[ClojureScript] Wrapping all def into a load event handler
(defn init []
(def main (goog.dom/getElement "main"))
(def mydiv (goog.dom/createDom "div"))
(goog.dom/appendChild main mydiv)
(defn change-color-mydiv []
(... mydiv)))
@hozumi
hozumi / core.clj
Created December 16, 2011 08:30
Moustache
;; 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
@hozumi
hozumi / sha1-hash.clj
Created December 13, 2011 16:46 — forked from prasincs/sha1-hash.clj
clojure sha1 hash
(defn sha1-str [s]
(->> (-> "sha1"
java.security.MessageDigest/getInstance
(.digest (.getBytes s)))
(map #(.substring
(Integer/toString
(+ (bit-and % 0xff) 0x100) 16) 1))
(apply str)))
@hozumi
hozumi / error.txt
Created December 9, 2011 04:42
aleph 0.2.1-SNAPSHOT
% 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)
@hozumi
hozumi / equal_cookie.js
Created April 14, 2011 09:29
Titanium setHeader failed
(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.
@hozumi
hozumi / naname.clj
Created March 19, 2011 19:49
rotate 45
(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)))))