Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
jebberjeb / foozle.clj
Last active December 19, 2015 12:29
This is that example from yesterday's TDD that was tripping me up. Looks easy here -- think I just need to do more apply (partial map foo) coll of colls.
(def ->num {[" "
" |"
" |"
" "] 1
[" _ "
" _|"
"|_ "
" "] 2
[" _ "
" _|"
@jebberjeb
jebberjeb / wrap-java.clj
Last active December 20, 2015 22:49
Wrap a java method call for easy use w/ map, filter, etc using a macro. memfn obviates this mess.
(defmacro ->j-fn [j-fn]
(let [args (gensym "args")]
`(fn [~args]
(eval (cons '~j-fn (if (coll? ~args) ~args (list ~args)))))))
;trivial
((->j-fn .length) "foo")
;useful, since you can't do (map .length ["foo" "bar"])
(map (->j-fn .length) ["foo" "bar"])
@jebberjeb
jebberjeb / condp-get-in.clj
Created August 14, 2013 04:02
condp w/ get-in
(let [foo {:Error "an error"}
baz {:Info {:RowsUpdated "some info"}}]
(condp #(get-in %2 %1) baz
[:Info :RowsUpdated] :>> (fn [msg] {:msg msg})
[:Error] :>> (fn [msg] {:msg msg})))
#_(pred test-expr expr)
@jebberjeb
jebberjeb / flip.clj
Created August 14, 2013 04:34
Reverse a functions argument order.
(defn flip [f]
"Create a function of f, with the argument order reversed"
(fn [& args]
(apply f (reverse args))))
((flip get-in) [:foo :bar] {:foo {:bar "foo bar"}})
;=> "foo bar"
@jebberjeb
jebberjeb / prof-partial.clj
Last active December 21, 2015 11:58
Profile partial, fn, #()
(ns timbre-test.core
(:require [taoensso.timbre.profiling :as profiling :refer (p profile)]))
;; Profile partial vs #/fn
(let [padd (partial + 5)
fadd (fn [n] (+ 5 n))
aadd #(+ % 5)]
(defn add-them-all [num]
(p :partial (padd num))
@jebberjeb
jebberjeb / run.sh
Created September 10, 2013 05:10
start/stop CR3 services
!/bin/bash
# paths
CONFUSION_ROOT=~/primedia/confusion
RANDR_ROOT=~/primedia/randr
RNRUI_ROOT=~/primedia/rnr_ui
PORTAL_ROOT=~/primedia/portal
PROXY_ROOT=~
PROXY_APP=ngrok
@jebberjeb
jebberjeb / notes.md
Last active December 22, 2015 17:19
notes

START CR3

  • Start/Stop of all (7) CR3 Servies:

    • confusion (vagrant & rackup)
    • randr
    • rnr_ui w/ tunnel
    • portal w/ tunnel
  • Also layout w/in console

@jebberjeb
jebberjeb / enfocus2-1.md
Last active December 24, 2015 23:59
First day w/ Enfocus

Enfocus

Why

What is Enfocus2

  • Client-side presentation (templating) library -- more about DOM transforms
@jebberjeb
jebberjeb / core.clj
Last active December 25, 2015 04:49
future-cancelled?
(ns test-app.core)
(defn do-it-slow!
[sleep-time]
(Thread/sleep sleep-time))
(defn mk-future
[sleep-time]
(future (do-it-slow! sleep-time)))
(*' Long/MAX_VALUE 2)
(* Long/MAX_VALUE 2)