Skip to content

Instantly share code, notes, and snippets.

View joshkh's full-sized avatar

Joshua Heimbach joshkh

View GitHub Profile
@joshkh
joshkh / deploy.clj
Created October 15, 2020 13:17
Deploy Ions to AWS
(ns app.deploy
(:require
[datomic.ion.dev :as dev]
[taoensso.timbre :refer [infof]]))
(defn check-status-loop [{arn :execution-arn :as args}]
(let [{:keys [deploy-status code-deploy-status] :as status}
(dev/deploy-status {:op :deploy-status
:execution-arn arn})]
(if (contains? (set [deploy-status code-deploy-status]) "RUNNING")
@joshkh
joshkh / cloudfront-s3-sig.clj
Created July 22, 2020 18:22
cloudfront / s3 signature
(ns signit
(:require [buddy.core.dsa :as dsa]
[buddy.core.codecs.base64 :as b64]
[clojure.string :as str])
(:import [java.security Signature]))
(defn access-policy
"Create a stringified JSON policy to grant access to a URL until a given Epoch time"
[url exp]
(str "{\"Statement\":[{\"Resource\":\""
@joshkh
joshkh / guess.clj
Last active May 5, 2020 19:08
Number guessing game
(defonce secret-number (atom 0))
(defn reset-game
"Reset the secret-number atom to an integer between 0 and the highest-number"
[highest-number]
(when (reset! secret-number (rand-int (inc highest-number)))
(println (str "I am thinking of a number between 0 and " highest-number ))))
(defn guess
"Make a guess at the secret number."
@joshkh
joshkh / indentation.clj
Last active April 22, 2020 10:32
Clojure Indentation
(defn some-generic-function
"Demonstrate Clojure indentation and styles.
This doc string spans multiple lines, and the beginning of each line
is inline with the opening quotation mark"
[]
; ns :require values are aligned
; ns :import values are aligned
; but :require values do not align with :import values
(ns project.namespace
@joshkh
joshkh / code.md
Created January 18, 2019 16:48
blog-API-Gateway-Authorizer
(ns superapi.ions.auth
  [:require [clojure.data.json :as json]
            [datomic.ion :as ion]
            [buddy.sign.jwt :as jwt]])

(defn gateway-authorizer
  "Validate that a user's JWT signature and expiration date"
  [{:keys [input] :as ion}]
  (let [
@joshkh
joshkh / code.md
Created January 18, 2019 02:53
blog-API-Gateway-Routing
(defn get-proxy-uri
  "Parse the proxied uri forwarded by the ions api-gateway data"
  [req]
  (try
    (let [path (-> req :datomic.ion.edn.api-gateway/json (json/read-str :key-fn keyword) :pathParameters :proxy)]
      (str "/" path))
    (catch Exception e nil)))

(defn wrap-proxy-uri
# Hitting the proxy resource endpoint /datomic returns the query results from the Ionized handler
curl https://$(obfuscated-name).execute-api.us-east-1.amazonaws.com/dev/datomic -d :hat
#{["SKU-19" 28499341391953988 23934169113428033 false] 
   ... 
  ["SKU-55" 46139905947992133 32330039903125571 false]}
```bash
# Hitting the proxy resource endpoint returns the query results from the Ionized handler
curl https://$(obfuscated-name).execute-api.us-east-1.amazonaws.com/dev/datomic -d :hat
#{["SKU-19" 28499341391953988 23934169113428033 false]
...
["SKU-55" 46139905947992133 32330039903125571 false]}
# Hitting a sub-resource returns the same thinng
@joshkh
joshkh / pst.clj
Created August 8, 2018 16:22
pst
=> #'testapp.core/client
(def conn (d/connect client {:db-name "my-db"}))
CompilerException clojure.lang.ExceptionInfo: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter #:cognitect.anomalies{:category :cognitect.anomalies/fault, :message "java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter"}, compiling:(form-init692047429040487558.clj:1:11)
(pst)
CompilerException clojure.lang.ExceptionInfo: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter #:cognitect.anomalies{:category :cognitect.anomalies/fault, :message "java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter"}, compiling:(form-init692047429040487558.clj:1:11)
clojure.lang.Compiler$InvokeExpr.eval (Compiler.java:3700)
clojure.lang.Compiler$DefExpr.eval (Compiler.java:457)
clojure.lang.Compiler.eval (Compiler.java:7067)
clojure.lang.Compiler.eval (Compiler.java:7025)
clojure.core/eval (core.clj:3206)
@joshkh
joshkh / repl.clj
Created August 8, 2018 15:42
datomic cloud client error
; [com.datomic/client-cloud "0.8.56"]
(require '[datomic.client.api :as d])
; => nil
(def client (d/client {:server-type :cloud
:region "..."
:system "..."
:query-group "..."
:endpoint "http://....datomic.net:8182/"