Skip to content

Instantly share code, notes, and snippets.

@hozumi
hozumi / meisuu.clj
Created December 13, 2010 06:23 — forked from kencoba/meisuu.clj
(use 'clojure.contrib.str-utils)
(def digits {"零" 0 "一" 1 "二" 2 "三" 3 "四" 4 "五" 5 "六" 6 "七" 7 "八" 8 "九" 9})
(defn- str-first [s]
(str (.charAt s 0)))
(defn- trans-ichi [s]
(let [n (re-find #"[一二三四五六七八九]$" s)]
(if (nil? n) 0 (digits n))))
(use '[clojure.test])
(defn powerset
([ls] (lazy-seq (cons () (powerset '(()) ls))))
([acc ls]
(if (empty? ls)
()
(let [fs (first ls)
added (map #(conj % fs) acc)]
(lazy-cat added
(powerset (concat acc added) (rest ls)))))))
@hozumi
hozumi / custom_client.clj
Created February 13, 2011 18:12
aleph composable http client
(ns custom-client
(:require [lamina.core :as lamina]
[aleph.http.client :as client]))
(defn make-connection [request] ;;http-connection is actually private.
(assoc request :connection (client/http-connection request)))
(defn enqueue-request [{:keys [connection] :as request}]
(lamina/run-pipeline connection
@hozumi
hozumi / dotrace_magic.clj
Created February 14, 2011 14:57
for debugging
prover> (eval `(trace/dotrace ~(keys (ns-interns 'prover)) (test-prove)))
TRACE t8307: (test-prove)
TRACE t8308: | (prove #<prover$eval8191$fn__8262 prover$eval8191$fn__8262@aaf5002> (((X = (((N - 1) * N) DIV 2)) and ((1 <= N) and (N <= M))) implies ((X + N) = ((((N + 1) - 1) * (N + 1)) DIV 2))))
TRACE t8309: | | (repeat-apply #<prover$prove$fn__4032 prover$prove$fn__4032@7badb8c8> (((X = (((N - 1) * N) DIV 2)) and ((1 <= N) and (N <= M))) implies ((X + N) = ((((N + 1) - 1) * (N + 1)) DIV 2))))
TRACE t8310: | | | (depth-imp-simp (((X = (((N - 1) * N) DIV 2)) and ((1 <= N) and (N <= M))) implies ((X + N) = ((((N + 1) - 1) * (N + 1)) DIV 2))))
TRACE t8311: | | | | (imp-simp X)
TRACE t8312: | | | | | (imp-subst-simp X)
TRACE t8312: | | | | | => X
TRACE t8313: | | | | | (imp-and-simp X)
TRACE t8313: | | | | | => X
@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)))))
(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 / equal_cookie.js
Created April 14, 2011 09:29
Titanium setHeader failed
@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 / 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 / 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