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
(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)))) |
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
(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))))))) |
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
(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 |
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
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 |
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 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))))) |
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
(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 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 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 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 |
OlderNewer