Skip to content

Instantly share code, notes, and snippets.

@shaunxcode
shaunxcode / gist:6646155
Created Sep 21, 2013
idiomatic way to apply a function with various arities
View gist:6646155
;;say you have something that looks like
(fnx a b)
(fnx a b2)
(fnx a b c)
(fnx a1 b2 c)
(fnx a2 b2 c2 d)
;;my goal is to avoid the repetition of fnx
@shaunxcode
shaunxcode / datomic-query-util.clj
Last active Dec 20, 2015
utilities for going between vector and map form of datomic query
View datomic-query-util.clj
(def query '[:find ?e ?fname ?lname
:in $ ?fname ?lname
:where [?e :user/firstname ?fname]
[?e :user/lastName ?lname]])
(defn group-by-kw [v]
(map (fn [[[f] l]] (conj [f] l))
(partition 2 (partition-by keyword? v))))
(defn query-vec-as-map [vquery]
@shaunxcode
shaunxcode / gist:5833985
Created Jun 21, 2013
datomic excise ns
View gist:5833985
[:find ?e ?ident
:where [?e :db/ident ?ident]
[(namespace ?ident) ?ns]
[(= ?ns "db.excise")]]
@shaunxcode
shaunxcode / gist:5811307
Created Jun 19, 2013
sweet use of jquery promises
View gist:5811307
$.when.apply(null, (ajaxRequest p for p in items)).done ->
console.log "all ajaxRequests complete"
View gist:5766780
CodeMirror.extendMode("clojure", {
newlineAfterToken: function(type, content, textAfter) {
console.log(type, content, textAfter);
return /[\(\{\[].+\s/.test(content);
}
});
// Applies automatic mode-aware indentation to the specified range
CodeMirror.defineExtension("autoIndentRange", function (from, to) {
var cmInstance = this;
View reduce-example.clj
(require '[clojure.core.async :as ca])
(def some-ch (ca/chan))
(def result-ch (ca/reduce
(fn [xs msg]
(if (= msg :done)
(reduced xs)
(conj xs msg)))
[]
some-ch))
@shaunxcode
shaunxcode / gist:3869104
Created Oct 10, 2012
fetch all attributes for a namespace in datomic
View gist:3869104
[:find ?id ?name ?attr
:in $ ?in-ns
:where [?id :db/ident ?name]
[(name ?name) ?attr]
[(namespace ?name) ?ns]
[(= ?ns ?in-ns)]]
@shaunxcode
shaunxcode / gist:3795605
Created Sep 27, 2012
query info for datomic
View gist:3795605
;;takes datomic query and turns it into map so it may be interrogated
(defn query-info [query]
(let [parts (partition-by keyword? query)
is-kw #(keyword? (first %))]
(zipmap
(map first (filter is-kw parts))
(remove is-kw parts))))
;;eg
((query-info '[:find ?x ?y ?z :in $ ?d :where [?x :some/thing ?y] [?x :some/otherthing ?z]]) :find)
@shaunxcode
shaunxcode / gist:2929101
Created Jun 14, 2012
quick coffeescript jquery dsl
View gist:2929101
String.prototype.$tag = (args...) ->
args.unshift "<#{@toString()}/>"
$.apply window, args
("ul".$tag
class: "someUL"
html: "li".$tag
text: "some text in an li"
class: "some class"
click: ->
@shaunxcode
shaunxcode / gist:2887304
Created Jun 7, 2012
keyword dispatch/doesNotUnderstand in coffeescript
View gist:2887304
#this is absolutely just for fun
keyWordDispatcher = (obj, msg) ->
selectorName = ""
args = []
for k, v of msg
selectorName += k + "_"
args.push v
if obj[selectorName]?