Skip to content

Instantly share code, notes, and snippets.

@dadair-ca
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
dadair-ca / register.clj
Created September 5, 2015 21:54
registration
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
dadair-ca / gist:1491661
Created December 17, 2011 22:42
Current User Task
View gist:1491661
tasks_controller#index
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
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
(comment
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 ---
nil
Starting HTTP server on port nil
{:app
{:middleware
{:functions
{: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
dadair-ca / description.md
Created September 27, 2016 01:55
Clojure postgresql enum type conversion
View description.md

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
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