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
(deftype DbUserService [] | |
PEntityService | |
(find-entity [_ id auth] | |
(services-util/authorize-service-call | |
(authorize-find-call user-authorizator id auth) | |
(services-util/get-service-result | |
(validate-find-entity user-validator id) | |
(services-util/get-success-response | |
(handle-find-entity user-handler id))))) | |
(delete-entity [_ id auth] |
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
(->> data | |
(filter (comp #(re-find #"^([0-9.]+)\s%$" %) #(get % 5))) | |
(sort-by (comp #(read-string (second (re-find #"^([0-9.]+)\s%$" %))) #(get % 5)) >) | |
(into [])) |
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
(def url-sequence (map #(str "http://www.mysite.com/list.php?pageID=" %) (range))) | |
(def download | |
(loop [urls url-sequence lst []] | |
(let [u (first urls) | |
r (rest urls) | |
resp (client/get u) | |
next (re-find #"(s?)title=\"next page\">Next >>" (:body resp)) | |
segments ((html2data (:body resp)) :segment) | |
data (map segment2data segments)] |
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
(def data {:b--name "B", :a--id 1, :b--id 2, :a--name "A"}) | |
(defn transform [data delimiter] | |
(reduce (fn [acc [k v]] | |
(let [[f-k s-k] (-> k (name) (str/split delimiter))] | |
(assoc-in acc [(keyword f-k) (keyword s-k)] v))) {} data)) | |
(transform data #"--") ;; {:a {:name "A", :id 1}, :b {:id 2, :name "B"}} | |
(defn transform [data delimiter] |
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
(require '[clojure.set :as set]) | |
(require '[clojure.java.jdbc :as j]) | |
(def mysql-db {:subprotocol "mysql" | |
:subname "//127.0.0.1:3306/clojure_test" | |
:user "clojure_test" | |
:password "clojure_test"}) | |
(defn product-service [key] | |
(println (str "Finding product with key: " key)) |
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 create-cancel-channel | |
[channel-to-notify timeout-ms] | |
(let [cancel-channel (async/chan) | |
timeout-channel (async/timeout timeout-ms)] | |
(async/go | |
(let [[_ c] (async/alts! [cancel-channel timeout-channel])] | |
(when (= c timeout-channel) | |
(async/close! cancel-channel) | |
(async/close! channel-to-notify)))) | |
cancel-channel)) |
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 async-util.input-pipe | |
(:require [clojure.core.async.impl.protocols :as impl] | |
[clojure.core.async :refer [<! >! close! go-loop]])) | |
(defprotocol InputPipe | |
(detach* [p])) | |
(defn input-pipe | |
"Creates and return input pipe of supplied channel with attached input channel." | |
[ch ch-i] |
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 db-util | |
(:require [clojure.string :as str])) | |
(def ^:private placeholders-for (comp (partial str/join ",") #(repeat % '?) count)) | |
(defn in-statement | |
"Takes a prepared SQL statement and variable number of arguments, which may be | |
also collection values. Replace all occurences of IN (?) with spliced out values | |
such as IN (?,?,?) where number of placeholder characters is the same as count | |
of elements in corresponding argument which is assumed to be a collection. |
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
;; common points of confusion for people new to Clojure | |
;; why core functions apparently change the type of given collection ? | |
(map inc [1 2 3 4]) ;; when evaluated, prints (2 3 4 5), not [2 3 4 5] | |
(take 2 {:a 1 :b 2 :c 3}) ;; when evaluated, prints ([:a 1] [:b 2]), not {:a 1 :b 2} |
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
[{ | |
"id" : 392, | |
"title" : "Solved R&D - Internal Project", | |
"description" : "Developing the Solved Platform & Processes", | |
"topics" : { | |
"DISCIPLINE" : [ { | |
"id" : 1, | |
"name" : "General", | |
"avatar" : "", | |
"topicGroup" : "DISCIPLINE", |
OlderNewer