Skip to content

Instantly share code, notes, and snippets.

@thheller
thheller / login.html.tpl
Created February 18, 2012 15:33
example template
{% export layout="simple" %}
{% export content do %}
<div class="content">
<div class="page-header">
<h1>Login</h1>
</div>
<div class="row">
<div class="span16">
{% form@tag id="login_form" do %}
@thheller
thheller / better-fn-printing.cljs
Last active December 13, 2015 20:48
A name for every CLJS fn
(ns dummy
(:require [clojure.string :as str]))
(.log js/console (pr-str name))
(defn unmunge [s]
(-> s
(str/replace #"_DOT_" ".")
(str/replace #"_" "-")
))
@thheller
thheller / test.clj
Created February 20, 2013 14:08
Split a vector into a map of vectors
(defn split-into-map [items key-fn]
(when-not (key-fn (first items))
(throw (ex-info "first item is not a key" {:items items})))
(loop [result {}
current-parts []
items items]
(let [item (first items)]
(cond
(and (nil? item) (empty? items))
@thheller
thheller / better-trace.txt
Last active December 14, 2015 14:49
unhelpful cljs compiler exception
clojure.lang.ExceptionInfo: failed compiling file:src/cljs-admin/cms/admin/app.cljs
core.clj:4327 clojure.core/ex-info
compiler.clj:848 cljs.compiler/compile-file
compiler.clj:908 cljs.compiler/compile-root
closure.clj:374 cljs.closure/compile-dir
closure.clj:406 cljs.closure/eval1542[fn]
closure.clj:276 cljs.closure/eval1467[fn]
closure.clj:420 cljs.closure/eval1529[fn]
closure.clj:276 cljs.closure/eval1467[fn]
compiler.clj:43 cljsbuild.compiler.SourcePaths/fn
@thheller
thheller / after.txt
Created May 11, 2013 09:11
clojure.test error reporting
ERROR in (cms-created-object) (core.clj:4327)
Uncaught exception, not in assertion.
expected: nil
ex-data[:sql]: "INSERT INTO cms_objects (owner,name,type,created_at) VALUES (?,?,?,?)"
ex-data[:values]: (1 "foo bar obj" :device #inst "2013-05-11T09:09:30.948000000-00:00")
actual: clojure.lang.ExceptionInfo: insert failed
at clojure.core$ex_info.invoke (core.clj:4327)
... stacktrace
(defn filter-file [filename]
(with-open [rdr (io/reader filename)]
(reduce (fn [words line]
(->> (str/split line #"\s+")
(filter #(and (<= (count %) 9)
(>= (count %) 4)))
(set)
(set/union words)))
#{}
(line-seq rdr))))
{:optimizations :advanced
:output-dir "target/cljs"
:module-dir "public/assets/js"
:modules [{:id :sub1 :include ["myapp.sub1"]}
{:id :admin :include ["myapp.admin"]}
{:id :sub2 :include ["myapp.sub2"
"myapp.something-else"]}
{:id :sub3 :include ["myapp.sub3"]}
]}
@thheller
thheller / match.clj
Created June 24, 2013 15:01
core.match bug
(use '[clojure.core.match :only (match)])
(use clojure.pprint)
(def form
'(match [(do-something)]
[[:ok value]] value
[[:error :not-found]] (do-something-else)))
(pprint (macroexpand-1 form))
(ns thheller.async-test
(:use clojure.test)
(:require [clojure.core.async :as async :refer (go >! <! >!! <!!)]))
(def c (async/chan))
(defn do-some-work [work]
(throw (ex-info "no way" {:work work})))
(go (loop [work-done 0]
(defn cond-transform [x & pairs]
(reduce (fn [x [test-fn transform-fn]]
(if (test-fn x)
(transform-fn x)
x))
x
pairs))
;; example