Skip to content

Instantly share code, notes, and snippets.

shaunxcode /
Created May 7, 2012 — forked from jimtla/
Add CoffeeScript friendly kv args to Underscore.js
#names of functions to create KV versions of and arg lists (in order)
to_kv = throttle: ['func', 'wait'], delay: ['func', 'wait'], defer: ['func'], bind: ['func', 'context']
mixin = {}
for name, arglist of to_kv
do (name, arglist) ->
mixin["#{name}KV"] = (kvargs) ->
args = (kvargs[arg] for arg in arglist when kvargs[arg]?)
if arglist.length isnt args.length then throw new Error "missing args"
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]?
shaunxcode / gist:2929101
Created Jun 14, 2012
quick coffeescript jquery dsl
View gist:2929101
String.prototype.$tag = (args...) ->
args.unshift "<#{@toString()}/>"
$.apply window, args
class: "someUL"
html: "li".$tag
text: "some text in an li"
class: "some class"
click: ->
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 %))]
(map first (filter is-kw parts))
(remove is-kw parts))))
((query-info '[:find ?x ?y ?z :in $ ?d :where [?x :some/thing ?y] [?x :some/otherthing ?z]]) :find)
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)]]
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;
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"
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 / 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 / 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