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 routes | |
["items" {:GET [items/all :as :list-items] | |
:POST [items/create :as :create-item | |
:some-metadata-key true]} | |
;; OR, skip the ":as" key and set the ID as the first value in the vector, followed by handler metadata: | |
[":id" {:GET [:show-item items/show] | |
:PUT [:update-item items/update | |
:some-metadata-key true] |
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
function offset(page, itemsPerPage){ | |
return (page - 1) * itemsPerPage; | |
} | |
function maxPages(perPage, totalItems){ | |
return Math.ceil(totalItems / perPage); | |
} | |
function isValidPage(page, itemsPerPage, totalItems){ | |
return ((page > 0) && (page <= maxPages(itemsPerPage, totalItems))); |
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 feature-preds | |
{:VTM (fn [request] false)}) | |
(defn filter-features [request features] | |
(filter #((get feature-preds % (constantly true)) request) features)) | |
(let [fake-request {:server-name "www.roomkey.com"}] | |
(filter-features fake-request #{:VTM})) |
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
(import '[com.github.fge.jsonschema.main JsonSchemaFactory]) | |
(import '[com.github.fge.jackson JsonLoader]) | |
(import '[com.github.fge.jsonschema.load.configuration LoadingConfiguration]) | |
(import '[com.github.fge.jsonschema.load Dereferencing]) | |
(import '[com.fasterxml.jackson.databind.node ObjectNode]) | |
(let [cfg (.dereferencing | |
(.setNamespace | |
(LoadingConfiguration/newBuilder) | |
"resource:///schema-file-dir-on-classpath/") |
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) | |
(defn rename-and-select-keys [m new-names] | |
(-> m (clojure.set/rename-keys new-names) | |
(select-keys (vals new-names)))) |
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 fetcher | |
(:require [clojure.tools.logging :as log])) | |
(def completed? (promise)) | |
(def status (atom 0)) | |
(defmacro make-worker [& forms] | |
`(do | |
(swap! status inc) |
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
(do | |
(def doit (promise)) | |
(def status (atom 0)) | |
(defmacro dowork [& forms] | |
`(do | |
(swap! status inc) | |
~@forms | |
(swap! status dec))) |
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
(import '(java.util.concurrent Executors TimeUnit)) | |
(defn schedule-at-fixed-rate [se f init-delay period] | |
(.scheduleAtFixedRate | |
se | |
(fn [] (try (f) (catch Throwable e (.printStackTrace e)))) | |
init-delay | |
period | |
TimeUnit/SECONDS)) |
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 find-by-kv [coll k v] | |
(some #(and (= v (k %)) %) coll)) |
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 select-int-keys [r m] | |
(reduce-kv | |
(fn [a k v] | |
(let [[_ n] (re-find r k)] | |
(if n (assoc a k [(int (read-string n)) v]) | |
a))) | |
{} | |
m)) | |
(select-int-keys #"bSearchable_([0-9]+)" |