Skip to content

Instantly share code, notes, and snippets.

View ddeaguiar's full-sized avatar

Daniel De Aguiar ddeaguiar

  • Nubank
  • Miami, Fl
View GitHub Profile
@ddeaguiar
ddeaguiar / service.clj
Created April 17, 2019 00:37
Stubbing session in Pedestal
(ns session.service
(:require [io.pedestal.http :as http]
[io.pedestal.http.route :as route]
[io.pedestal.http.body-params :as body-params]
[ring.util.response :as ring-resp]))
(defn about-page
[request]
(ring-resp/response (format "Clojure %s - served from %s"
(clojure-version)
@ddeaguiar
ddeaguiar / sample.clj
Last active July 2, 2018 22:23
Using Pedestal routers directly
(require '[io.pedestal.http.route.path :as route.path])
(require '[io.pedestal.http.route :as route])
(require '[io.pedestal.http.route.map-tree :as route.map-tree])
(require '[io.pedestal.http.route.router :as route.router])
;; handler fns and common-interceptors elided
(def routes #{["/" :get (conj common-interceptors `home-page)]
["/about" :get (conj common-interceptors `about-page)]
["/foo/:id" :get (conj common-interceptors `foo)]})
(ns foo.service
(:require [io.pedestal.http :as http]
[clojure.core.async :as async]
[io.pedestal.http.route :as route]
[io.pedestal.interceptor :as i]
[io.pedestal.http.body-params :as body-params]
[ring.util.response :as ring-resp]))
(defn about-page
[request]
@ddeaguiar
ddeaguiar / overview.md
Last active July 14, 2017 16:28
Datomic talk (Miami Scala meetup)

Datomic

Daniel will introduce the Datomic database system, discuss how it differentiates itself from other Database systems and demonstrate its usage. This will cover schema creation, entity transaction, Datalog queries and the different APIs that are available for interacting with Datomic.

About me

@ddeaguiar
ddeaguiar / route_testing.clj
Last active July 13, 2017 13:55
Various ways to test Pedestal routes
(require '[io.pedestal.http.route :as route])
;; The following examples use a contrived expanded route structure. You can test your routes
;; by using the result of `(route/expand-routes my-routes)`, where `my-routes` is your route representation
;; created using one of the supported route syntaxes. If you are using the `pedestal-service` lein template,
;; you would use `(route/expand-routes service/routes)`.
(def contrived-expanded-routes [{:path "/bar" :method :get :interceptors []}])
;; You can test route matching with `try-routing-for`
@ddeaguiar
ddeaguiar / service.clj
Last active March 24, 2017 19:52
interceptor short-circuiting
(ns terminator.service
(:require [io.pedestal.http :as http]
[io.pedestal.http.route :as route]
[io.pedestal.http.body-params :as body-params]
[io.pedestal.interceptor :as i]
[ring.util.response :as ring-resp]))
(defn about-page
[request]
(ring-resp/response (format "Clojure %s - served from %s"
@ddeaguiar
ddeaguiar / sample.edn
Last active March 23, 2017 15:20
Vase route snippet with `or`
{
...
"/user" {:get #vase/query {:name :your-first-api.v1/user-page
;; Params are required if they don't have defaults
:params [identifier]
:edn-coerce [identifier]
:query [:find (pull ?e [*])
:in $ ?identifier
:where
(or
@ddeaguiar
ddeaguiar / log_test.clj
Last active April 17, 2018 12:57
Toggle log level during testing
(ns log-test
(:import
[ch.qos.logback.classic Level]
[org.slf4j LoggerFactory Logger]))
(defn set-log-level
[logger level]
(.setLevel logger level))
(defn root-logger []
@ddeaguiar
ddeaguiar / gist:8d5da1b7a8e8f6b6f78e
Created June 8, 2015 17:34
swap! atom with update-in
(def my-state (atom {:foo {:bar [1 2 3]}}))
@my-state
;; {:foo {:bar [1 2 3]}}
(swap! my-state update-in [:foo :bar] #(conj % 4))
;; {:foo {:bar [1 2 3 4]}}
@my-state
;; {:foo {:bar [1 2 3 4]}}
@ddeaguiar
ddeaguiar / gist:d8a6485d5dd81f5bf527
Last active August 29, 2015 14:14
bidi routing sample
(ns routing.core
(:require [bidi.bidi :as b]
[bidi.ring :as r]
[ring.mock.request :refer [request] :rename {request mock-request}]))
(defn index-handler
[req]
{:status 200 :body "Index"})
(def handler-map