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 -inheritable* | |
[var] | |
(let [*i (doto (proxy [InheritableThreadLocal] [] | |
;; This is where the magic happens. | |
;; childValue is evaluated in the parent thread where bindings should still valid. | |
(childValue [{:keys [bindings]}] | |
(let [new-bindings (merge bindings (get-thread-bindings))] | |
{:bindings new-bindings | |
:get-val (fn [] (with-bindings new-bindings | |
(deref var)))}))) |
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 deep-merge | |
"Recursively merges maps. If vals are not maps, the last value wins." | |
[& vals] | |
(if (every? map? vals) | |
(apply merge-with deep-merge vals) | |
(last vals))) | |
(defn deep-merge-with | |
"Like merge-with, but merges maps recursively, applying the given fn | |
only when there's a non-map at a particular level." |
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
;; some speed tests of functions to access nested properties in JS objects. | |
(def test-data (->> (into {} (for [k1 (range 10)] | |
[k1 (into {} (for [k2 (range 10)] | |
[k2 (into {} (for [k3 (range 10)] | |
[k3 k3]))]))])) | |
(clj->js))) | |
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
;; some speed tests of functions to access nested properties in JS objects. | |
(def test-data (->> (into {} (for [k1 (range 10)] | |
[k1 (into {} (for [k2 (range 10)] | |
[k2 (into {} (for [k3 (range 10)] | |
[k3 k3]))]))])) | |
(clj->js))) | |
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 build-paths | |
"Given a tree (map), return all the paths leading to a value." | |
[m] | |
(->> (for [[k v] m] | |
(if (map? v) | |
(map #(cons k %) (build-paths v)) | |
[[k]])) | |
(apply concat))) |
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 cea.buddy-token | |
"The token based authentication and authorization backends." | |
(:require [buddy.auth.protocols :as proto] | |
[buddy.auth.http :as http] | |
[buddy.auth :refer [authenticated?]] | |
[buddy.sign.jws :as jws] | |
[buddy.sign.jwe :as jwe] | |
[clojure.string :as s])) | |
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 with-random | |
"Add a random geospatial queries to a fetch. Should be used with a | |
limit, otherwise default limit to 5 items." [fetch-fn coll & {:as args}] | |
(let [where (:where args) | |
new-args (vec (merge {:limit 5} ;security limit if none is provided | |
args {:where (merge where {:random_point {:$near [(rand) 0]}})}))] | |
(apply fetch-fn (concat [coll] (apply concat new-args))))) | |
(defn get-object-historic-data |
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
(defun replace-string-in-rectangle (from-string to-string &optional delimited start end) | |
(interactive | |
(let ((common | |
(query-replace-read-args | |
"Replace string in rectangle" nil))) | |
(list (nth 0 common) (nth 1 common) (nth 2 common) | |
(region-beginning) | |
(region-end)))) | |
(let ((replacement-rectangle | |
(mapcar '(lambda (arg) (replace-in-string arg from-string to-string)) |
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
;---------------------------------------------------- | |
;;;==== Open command shows a list of recent file ==== | |
;---------------------------------------------------- | |
(require 'recentf) | |
;; enable recent files mode. | |
(recentf-mode t) | |
; 200 files ought to be enough. | |
(setq recentf-max-saved-items 200) | |
(defun ido-recentf-open () |
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
(global-set-key (kbd "C-c u") | |
(lambda()(interactive) | |
(save-excursion | |
(let (pt) | |
(skip-chars-backward "-_A-Za-z0-9") | |
(setq pt (point)) | |
(skip-chars-forward "-_A-Za-z0-9") | |
(upcase-region pt (point))) | |
(message "UPPERCASE!")))) |
NewerOlder