Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Heimbach joshkh

View GitHub Profile
@joshkh
joshkh / deploy.clj
Created Oct 15, 2020
Deploy Ions to AWS
View deploy.clj
(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 Jul 22, 2020
cloudfront / s3 signature
View cloudfront-s3-sig.clj
(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
Number guessing game
View guess.clj
(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 Apr 22, 2020
Clojure Indentation
View indentation.clj
(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 Jan 18, 2019
blog-API-Gateway-Authorizer
View code.md
(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 Jan 18, 2019
blog-API-Gateway-Routing
View code.md
(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
View greedy-proxy-resource.md
# 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]}
View gist:17f818bf02452fc0cf261ba99620501e
```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
View pst.clj
=> #'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 Aug 8, 2018
datomic cloud client error
View repl.clj
; [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/"