Skip to content

Instantly share code, notes, and snippets.

View jebberjeb's full-sized avatar

Jeb Beich jebberjeb

View GitHub Profile

State Monad

TL;DR I'll probably just use a macro

What

A structure which allows you to represent a computation as a sequence of steps. The monad allows you to decorate each step with additional processing rules.

  • Logging
(ns test-app.foo
(:require [clojure.java.io :as io])
(:import [java.util Properties]))
;;dotenv (w/ precedence per Colin -- shell > .env.foo > .env)
(defn f->p
[f]
(let [file (io/as-file f)]
(when (.exists file) (doto (Properties.) (.load (io/input-stream file))))))
@jebberjeb
jebberjeb / .from-virmc
Last active August 29, 2015 13:56
Use vim-fireplace to run unit tests, highlight failed test fns in red!
function! RunTests()
" reload the namespace
norm cpr
" setup
call clearmatches()
highlight Red ctermbg=darkred
redir => output
" use Clojure to do the real work, run tests,
(ns classpath-test.core
(:require [clojure.java.shell :refer [sh]]
[cemerick.pomegranate :as pom]))
(defn make-java
[class-name
package]
(str "package " package ";"
"public class " class-name " {"
"public static String foo() { return \"bar\"; }"

defsproc

How it works now

(def sproc-map {:sproc "webicon.p_get_prop"
                :params [{:name :ipropid :type :string}
                         {:name :cursor :type :cursor :output true}
                         ...]})

(defsproc get-property sproc-map [:ipropid] (first cursor))

(ns iws-oracle.defsproc.generate
(:require [clojure.java.jdbc :as jdbc]
[clojure.string :as str]
[schema.core :as s]
[schema.macros :as sm]
[iws-oracle.defsproc :refer :all]
[iws-oracle.test.core-test :as ct]))
(def args-sql (str "select * from all_arguments where lower "
"(object_name) = lower (?)"))
@jebberjeb
jebberjeb / profiling.clj
Created November 17, 2014 21:39
Profiling Magrathea
(ns profiling
(:require [magrathea.server.routes :refer (app)]
[ring.mock.request :as mock]
[taoensso.timbre.profiling :as p]))
(def req (mock/request
:get
"/organization/085cafea-868b-4db2-958c-641988553c5b/my-account"))
(defn do-with-orgs
@jebberjeb
jebberjeb / 401.clj
Created November 18, 2014 22:07
Rather than 401 via ring middleware, macros
(defn request* [method route-path privilege route-params handler]
`(~method ~route-path ~route-params
(fn [req#] (let [user# (get-in req# [:session :current-user])]
(if (access/has-access? user# ~privilege)
(~handler req#)
~response-401)))))
(defmacro GET* [route-path privilege route-params handler]
(request* `GET route-path privilege route-params handler))
@jebberjeb
jebberjeb / access-logic.clj
Last active August 29, 2015 14:10
[TAKE 3] Rough cut at using core.logic to figure out user->roles->privileges access concerns.
(ns access.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]))
(def all-priv [:smart-controls :view-all-reports :admin :foo :bar])
(def all-roles [{:name :admin :privs priv}
{:name :reporting :privs [:view-all-reports]}
{:name :store :privs [:smart-controls :view-all-reports]}
{:name :foo-role :privs [:foo :bar]}])