Skip to content

Instantly share code, notes, and snippets.

@AdamFrey
AdamFrey / nested_params_to_nested_object
Created July 2, 2014 15:50
Translate an object with Rails-style nested keys into an objected with nested keys. Depends on underscore.js
function nestParams(params) {
// Translates an object that has Rails style nested keys (key1[key2][key3]: value)
// into a nested object
var nested = {};
_.each(params, function(value, key) {
createNestedObject(nested, splitKey(key), value);
});
return nested;
}
@AdamFrey
AdamFrey / co-pr.sh
Last active August 29, 2015 14:16
git co pull request
# Add these lines to your repo's .git/config file under the "[remote "origin"] header:
# fetch = +refs/heads/*:refs/remotes/origin/*
# fetch = +refs/pull/*:refs/pull/*
"git ls-remote origin | grep -E 'pull.*merge' | cut -f 2 | grep -o '[0-9]\+' | selecta | sed 's/^/refs\/pull\//; s/$/\/merge/' | xargs git checkout"
@AdamFrey
AdamFrey / gist:206bb51d45a17819aded
Last active August 29, 2015 14:24
Multi-method non-redefine
user=> (defmulti even-or-odd (fn [n] (if (even? n) :odd :even)))
#'user/even-or-odd
user=> (defmethod even-or-odd :even [n] "even")
#object[clojure.lang.MultiFn 0x7fd6a23b "clojure.lang.MultiFn@7fd6a23b"]
user=> (defmethod even-or-odd :odd [n] "odd")
#object[clojure.lang.MultiFn 0x7fd6a23b "clojure.lang.MultiFn@7fd6a23b"]
user=> (even-or-odd 1)
"even"
user=> ;; oops, let's try again
(defc x 1)
;; WORKING
(mx
'(defc= computed
(let [inner-binding "huh"]
(and x inner-binding))))
;; output
'(def computed
@AdamFrey
AdamFrey / Accomack.geo.json
Last active February 20, 2017 02:24
GeoJSON Merge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.