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
;; ## General helpers | |
(ns app.helpers.rama | |
(:require | |
[missionary.core :as m] | |
[taoensso.timbre :as timbre]) | |
(:import | |
[com.rpl.rama Depot PState Path ProxyState$Callback RamaModule] | |
[com.rpl.rama.test InProcessCluster LaunchConfig] | |
[hyperfiddle.electric Failure Pending])) |
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 example | |
(:require [com.rpl.specter :as sp])) | |
;; Find paths | |
;; ####################################### | |
(defn find-when | |
"Given a nested data structure and a predicate, return a vector of | |
paths to all locations where the predicate is true." | |
[data pred] |
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.string :as string]) | |
(def test-str "name\\=name=value\\=value;name=value;name=value\\;;name=value;") | |
(defn key-part [s] | |
(second (re-find #"(.*[^\\])=" s))) | |
(defn value-part [s] | |
(second (re-find #"[^\\]=(.*)" 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
(ns poc.util.app | |
(:require [com.fulcrologic.fulcro.algorithms.denormalize :as denormalize])) | |
(defn add-query-watch | |
"Takes at minimum an app, a registry-key, a query, a starting-entity, and a function. | |
Optionally takes an an options map as last argument. | |
Attaches a watch to the app state, using registry-key as the key for the watch. | |
When the queried state changes, triggers function f. |
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
;; DSL | |
;; ############################ | |
(ns example.lib.cloudformation | |
(:require [camel-snake-kebab.core :refer [->PascalCase]])) | |
(defmacro defresource | |
"Defines a resource. The CF name of the resource will be the same | |
as the name given to it, except Pascal-cased, since that seems | |
to be the style favoured by CF. Optionally, a literal name | |
in the form of a keyword can be given as second argument to |
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 flip-attrs [attributes] | |
(let [one (clojure.string/split attributes #"&") | |
two (map #(clojure.string/split % #"=") one) | |
three (map reverse two) | |
four (map #(interpose "=" %) three) | |
five (interpose "&" four) | |
six (flatten five)] | |
(apply str six))) | |
(flip-attrs "tool=whip&clothing=hat&sidearm=pistol") |
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 | |
"Takes a collection of maps and deep merges them. I.e... | |
[{:a {:b 1}} | |
{:a {:c 2}}] | |
... will be merged into ... | |
[{:a {:b 1 | |
:c 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
(def brackets {\{ \} | |
\[ \] | |
\( \)}) | |
(defn checker [stack char] | |
(if (some #{char} (keys brackets)) ;; Is the character an opening bracket? | |
(conj stack char) | |
(let [closing-char (get brackets (last stack))] | |
(if (= closing-char char) |
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- process-one | |
"Takes a channel and a function. Expects vectors of [index arguments] | |
on the channel. Takes from the channel, and applies the function | |
to the arguments part of the vector. Returns an output-channel, | |
on which the index and the result of the function application is returned." | |
[in-ch function] | |
(let [out-ch (chan)] | |
(go | |
(loop [item (<! in-ch)] | |
(if item |
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 safe-seq | |
[thing] | |
(if (seqable? thing) | |
(seq thing) | |
true)) | |
(defprotocol StripNil | |
(strip-nil [data] | |
"Recursively strips values that are nil from a datastructure. |
NewerOlder