Skip to content

Instantly share code, notes, and snippets.

(defn json-api-iteration
"Returns a reducible to iterate through a JSON API pagination compliant API.
`request!` is a function of a URI string, expected to return a JSON API response.
`uri` is the statring URI for the paginated endpoint."
[request! uri]
(pages/iteration request!
:initk uri
:vf #(get-in % [:body "data"])
:kf #(get-in % [:body "links" "next"])))
(defn generate-auth-token
"Create an authorization token used to connect to a database that uses RDS IAM
authentication. Use this token as the DB password when connecting with `user`.
To use IAM authentication, the user must be granted the rds_iam role. e.g.,
`GRANT rds_iam TO db_userx;`
See also:"
(.getAuthToken (.build (doto (RdsIamAuthTokenGenerator/builder)
(defn ->eql
(let [f (fn convert [paths]
(let [k->joins (reduce (fn [acc [k & joins]]
(update acc k (fnil #(cond-> % joins (conj joins)) [])))
{} paths)]
(into []
(map (fn [[k joins]]
(if (seq joins) {k (convert joins)} k)))
(defn iteration-op-map
"Iterates an op-map based step. Useful in aws-api and gcp-api. Returns a list
of results from each page after applying :itemsf. If an anomaly is returned
from invoke-fn, it will be included in the list."
[invoke-fn op-map {:keys [request-key response-key itemsf]}]
(fn [next-token]
(cond-> op-map
next-token (assoc-in [:request request-key] next-token))))
kennyjwilli / api-gateway.clj
Created June 15, 2020 16:26
Code to call API Gateway using utilities copied from Cognitect's aws-api
[ :as aws.credentials]
[ :as aws.shared]
[ :as signers]
[java-http-clj.core :as http])
(:import ( URI)
(java.util Date)
(java.text SimpleDateFormat)))
kennyjwilli /
Last active November 9, 2018 20:16
Delete leftover Datomic resources

Delete Leftover Datomic Cloud Resources

If you delete a Datomic Cloud system, it will leave some resources in AWS. To entirely delete all resources created by Datomic Cloud, you must follow these steps. Because we love automation, this script performs all these steps for you so you don't need to navigate the AWS Console UI.


kennyjwilli / maven-to-deps.clj
Created June 22, 2018 23:08
Maven to deps.edn converter
(defn transform-deps
(binding [*print-namespace-maps* false]
(reduce (fn [deps-edn [id version & opts]]
(let [opts (apply hash-map opts)]
(if (= "test" (:scope opts))
(assoc deps-edn
id (merge {:mvn/version version}
kennyjwilli / nodejs_cljs_repl.clj
Created September 1, 2017 23:06
Start a NodeJS REPL in Boot after running boot watch cljs-repl
(require 'cemerick.piggieback)
=> nil
(require '[cljs.repl.node])
=> nil
(cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env))
ClojureScript Node.js REPL server listening on 56999
To quit, type: :cljs/quit
=> nil
(+ 1 1)
=> 2
(rules/rule logging-in
[[_ :logging-in? true]]
[[_ :email ?email]]
[[_ :password ?password]]
(do-login ?email ?password
(fn [[ok? response]]
(println "login response" (pr-str response))
(precept/then (into
[[:global :logged-in? true]
kennyjwilli / patch.cljs
Created November 17, 2016 20:57
Optimized js->clj implementation by Darrick Wiebe
; Optimized js->clj implementation by Darrick Wiebe (
(defn js->clj
([x] (js->clj x :keywordize-keys false))
([x & opts]
(satisfies? IEncodeClojure x)
(-js->clj x (apply array-map opts))
(seq opts)
(let [{:keys [keywordize-keys]} opts