Skip to content

Instantly share code, notes, and snippets.

View eneroth's full-sized avatar

Henrik Eneroth eneroth

View GitHub Profile
@eneroth
eneroth / flip_attrs.clj
Last active February 27, 2019 18:32
Flips attributes around
(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")
@eneroth
eneroth / cf_dsl.clj
Last active March 15, 2022 03:48
Minimal DSL for CloudFormation templates
;; 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
@eneroth
eneroth / poc_util_app.clj
Last active October 16, 2019 17:23
Custom add-watch function for Fulcro 3. Triggers a function based on a query.
(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.
@eneroth
eneroth / args-parse.clj
Last active November 19, 2019 14:27
Trivial K/V parser for a string of args
(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)))
(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]
@eneroth
eneroth / rama_electric.clj
Last active September 8, 2023 15:39
Rama + Electric
;; ## 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]))