Skip to content

Instantly share code, notes, and snippets.

dadair-ca / mock-ring-request.clj
Last active August 29, 2015 14:25
Ring-mock BufferedInputStream coersion
View mock-ring-request.clj
(testing "Access should be granted on valid credentials."
(is (= (app (mock/header (mock/request :get "/api/echo" {:m "hi"})
"authorization" "Basic Zm9vOmJhcg=="))
{:status 200 :body "hi"}))))
View clojure-closure-help.clj
;; handlers
(defn- login
"Verifies that the user credentials are valid and returns a token
that can be used for future requests to secure resources."
[{{username :username} :body}]
(let [auth (authenticate username)]
(response/ok auth)))
dadair-ca / register.clj
Created September 5, 2015 21:54
View register.clj
(defn- register
[db mailer email password]
(if (users/valid? email password)
(if (users/taken? db email)
(response/bad-request {:errors [{:message "That email is taken."}]})
(do (users/do-create! db email password)
(users/notify mailer email activate-subject activate-text)
(response/ok (auth/authenticate email))))
(response/bad-request {:errors [{:message errors/invalid-creds}]})))
dadair-ca / gist:1491661
Created December 17, 2011 22:42
Current User Task
View gist:1491661
had: @tasks = Task.all
should be: @tasks = current_user.tasks
so when I was displaying @tasks in the view, it had the entire table >.<
dadair-ca / SDL-CMakeLists.txt
Created November 25, 2012 03:14
Minimal SDL CMakeLists.txt
View SDL-CMakeLists.txt
project (PROJECT_NAME)
find_package (SDL REQUIRED)
set (SRC file1.cpp file2.cpp)
add_executable (EXECUTABLE_NAME ${SRC})
target_link_libraries(EXECUTABLE_NAME ${SDL_LIBRARY})
View gist:e897748bca5e264f5298
I'm trying to build a very simple clojurescript app using re-frame (& reagent, secretary),
and I am getting the following error in the console, that I can't seem to debug:
Error: No protocol method IDeref.-deref defined for type cljs.core/PersistentArrayMap: {:name "Black Temple", :snippet "25-man raid"}
(ns raid-commander.core
(:require [reagent.core :as reagent :refer [atom]]
[reagent.session :as session]
View Dockerfile-dev
FROM clojure
RUN mkdir -p /app
COPY ./dev /app/dev
COPY ./profiles.clj /app/profiles.clj
COPY ./project.clj /app/project.clj
COPY ./resources /app/resources
COPY ./src /app/src
View console output
--- jwt ---
Starting HTTP server on port nil
{:hide-errors duct.middleware.errors/wrap-hide-errors,
:not-found duct.middleware.not-found/wrap-not-found,
:ring-json-response ring.middleware.json/wrap-json-response,
:ring-json-body ring.middleware.json/wrap-json-body},
dadair-ca /
Created September 27, 2016 01:55
Clojure postgresql enum type conversion

Given an enum type e_role, being represented in clojure-land as a string, use the enum in a query and typecast inside it.

Note the ?::e_role:

INSERT INTO accounts (account_id, email, password, account_role)
       VALUES (DEFAULT, :email, :password, ?::e_role);

Use positional arguments for the enum(s) (note the :? [..]):

dadair-ca / example.clj
Last active October 2, 2016 19:52
core async processing improvements
View example.clj
;; Forecast generation
(defn inst->forecasts [inst]
(for [r (range 1 25)]
[(c/to-sql-time (t/plus (without-minutes inst) (t/hours r))) (rand-int 50)]))
;; Async