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: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html"
[db-spec]
(.getAuthToken (.build (doto (RdsIamAuthTokenGenerator/builder)
(defn ->eql
[?schema]
(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)))
k->joins)))]
(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]}]
(iteration
(fn [next-token]
(invoke-fn
(cond-> op-map
next-token (assoc-in [:request request-key] next-token))))
@kennyjwilli
kennyjwilli / api-gateway.clj
Created June 15, 2020 16:26
Code to call API Gateway using utilities copied from Cognitect's aws-api
(ns cs.aws-api.api-gateway
(:require
[cognitect.aws.credentials :as aws.credentials]
[cognitect.aws.client.shared :as aws.shared]
[cs.aws-api.signers :as signers]
[java-http-clj.core :as http])
(:import (java.net URI)
(java.util Date)
(java.text SimpleDateFormat)))
@kennyjwilli
kennyjwilli / README.md
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.

Prerequisites

@kennyjwilli
kennyjwilli / maven-to-deps.clj
Created June 22, 2018 23:08
Maven to deps.edn converter
(defn transform-deps
[deps]
(binding [*print-namespace-maps* false]
(clojure.pprint/pprint
(reduce (fn [deps-edn [id version & opts]]
(let [opts (apply hash-map opts)]
(if (= "test" (:scope opts))
deps-edn
(assoc deps-edn
id (merge {:mvn/version version}
@kennyjwilli
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
kennyjwilli / patch.cljs
Created November 17, 2016 20:57
Optimized js->clj implementation by Darrick Wiebe
; Optimized js->clj implementation by Darrick Wiebe (http://dev.clojure.org/jira/browse/CLJS-844)
; https://github.com/asciinema/asciinema-player/blob/master/src/asciinema/player/patch.cljs
(defn js->clj
([x] (js->clj x :keywordize-keys false))
([x & opts]
(cond
(satisfies? IEncodeClojure x)
(-js->clj x (apply array-map opts))
(seq opts)
(let [{:keys [keywordize-keys]} opts