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 wrap-exception [f] | |
| (fn [request] | |
| (try (f request) | |
| (catch Exception e | |
| {:status 500 | |
| :body "Exception caught"})))) |
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
| (ns example.core | |
| (:require-macros [cljs.core.async.macros :refer [go go-loop]]) | |
| (:require [om.core :as om :include-macros true] | |
| [om.dom :as dom :include-macros true] | |
| [clojure.string :as string])) | |
| (def app-state (atom {:options {:a 1 :b 2 :c 3}})) | |
| (defmulti changed-option (fn [k _] 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
| (ns scanview.core | |
| (:require [clojure.string :as string] | |
| [clojure.data.csv :as csv] | |
| [clojure.pprint :refer [pprint]] | |
| [clojure.java.io :as io])) | |
| (def regex #"[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?") | |
| (defn trim-line? [s] | |
| (when-let [extra-alpha-chars (re-seq #"[A-DF-df-z]" s)] |
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
| user=> (time (first (reduce concat (repeat 2000 [1])))) | |
| "Elapsed time: 3.369 msecs" | |
| 1 | |
| user=> (time (first (reduce into (repeat 2000 [1])))) | |
| "Elapsed time: 9.901 msecs" | |
| 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
| (ns queue-test | |
| (:require [clojure.core.async :as async :refer [>! <! chan go go-loop put!]])) | |
| (defn process! [item] | |
| {:pre [item]} | |
| (println "processing:" item)) | |
| (defn init! [] | |
| (let [q (chan)] | |
| (go-loop [] |
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
| ;; wrap-action should be called for all the defined cases, but not for the default case | |
| (case v | |
| 1 (wrap-action (foo)) | |
| 2 (wrap-action (bar)) | |
| 3 (wrap-action (baz)) | |
| (qux)) |
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
| (ns oauth.digest | |
| (:import (javax.crypto Mac) | |
| (javax.crypto.spec SecretKeySpec))) | |
| (defn hmac | |
| "Calculate HMAC signature for given data." | |
| [^String key ^String data] | |
| (let [hmac-sha1 "HmacSHA1" | |
| signing-key (SecretKeySpec. (.getBytes key) hmac-sha1) | |
| mac (doto (Mac/getInstance hmac-sha1) (.init signing-key))] |
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
| Algorithm HmacSHA1 not available | |
| [Thrown class java.security.NoSuchAlgorithmException] | |
| Restarts: | |
| 0: [QUIT] Quit to the SLIME top level | |
| Backtrace: | |
| 0: javax.crypto.Mac.getInstance(DashoA13*..) | |
| 1: user$eval2253.invoke(NO_SOURCE_FILE:1) | |
| 2: clojure.lang.Compiler.eval(Compiler.java:5424) |
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
| phrygian:tracker wei$ cake repl | |
| user=> (javax.crypto.Mac/getInstance "HmacSHA1") | |
| java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available (NO_SOURCE_FILE:0) | |
| phrygian:tracker wei$ lein repl | |
| "REPL started; server listening on localhost:35455." | |
| user=> (javax.crypto.Mac/getInstance "HmacSHA1") | |
| #<Mac javax.crypto.Mac@5759780d> |
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 map-keys [m f] | |
| (into {} (for [[k v] m] [k (f v)]))) | |
| ;; recursive group-by | |
| (defn group-by-> [starting-target starting-fns] | |
| (loop [target starting-target fns starting-fns] | |
| (if (nil? fns) target | |
| (map-keys (group-by (first fns) target) #(recur % (rest fns)))))) | |
| ;; usage |
OlderNewer