Skip to content

Instantly share code, notes, and snippets.

@taylorSando
taylorSando / datomic-function-binding.clj
Created December 25, 2012 07:38
You can't use map or vector binding in the params of a datomic function map. It will cause a 'clojure.lang.PersistentVector cannot be cast to java.lang.Stringclojure.lang.PersistentVector cannot be cast to java.lang.String
;; You can't use map or vector binding in the params of a datomic function map. It will cause a
;; 'clojure.lang.PersistentVector cannot be cast to java.lang.Stringclojure.lang.PersistentVector cannot be cast to java.lang.String
;; For example, I was attempting ot create a function so that I could pass the following to the transactor function:
;; (d/transact *conn* [ [:node/add {:node/description "Hello" :node/uri "http://www.example.com" :node/tags ["tag1", "tag2"]]])
;; This causes an error, because params isn't being treated like it can be bound to. You can only specify symbols to bind to
(def add-node {:db/doc "A function for adding a node to the database"
:db/ident :node/add
:db/fn (d/function '{:lang :clojure
:params [db [{:keys [uri description tags prerequisites]}]]
;; The ->> threading macro will normally place the previous form into the last argument position of the next form
;; However, there are times when you are working with functions that don't take the required parameter in the last spot
;; In this example, I'm extracting all path locations before /v
;; re-seq first and second all work with the threading macro
;; However, when it comes time to split the string result, clojure.string/split takes two arguments
;; The first is the string, and the second is the regular expression to split on.
;; For the threading macro to work as is, these arguments need to be reversed
;; One way of doing this is creating an anonymous function that does this
;; #(clojure.string/split % #"/") This is the function
;; Then you actually evaluate by wrapping it in paranthesis
@taylorSando
taylorSando / shoppers-locs
Created December 2, 2012 21:33
Shoppers Stores
http://www1.shoppersdrugmart.ca/en/store-locator/store-58.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-6.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-18.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-50.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-54.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-105.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-27.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-7.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-156.aspx
http://www1.shoppersdrugmart.ca/en/store-locator/store-2.aspx
@taylorSando
taylorSando / session Override
Created October 23, 2012 13:07
Altering backbone to go to /login and /logout
sync: function(method, model, options) {
if (method == "update" || method == "create") {
var params = {type: "POST", dataType: "json", "url": ___ROOT_URL___ + "/login",
contentType: 'application/json', data: JSON.stringify(model.toJSON()),
processData: false
};
return $.ajax(_.extend(params, options));
} else {
@taylorSando
taylorSando / project.clj
Created September 17, 2012 18:54
project.clj settings for updated clojurescript one project
(defproject one "1.0.0-SNAPSHOT"
:description "Getting Started with ClojureScript."
:dependencies [[org.clojure/clojure "1.4.0"]
[ring "1.1.5"]
[compojure "1.1.3"]
[enlive "1.0.0"]
[domina "1.0.0"]
[org.mozilla/rhino "1.7R3"]
[com.google.javascript/closure-compiler "r1918"]
[org.clojure/google-closure-library "0.0-1376-2"]]
@taylorSando
taylorSando / project.clj
Created September 17, 2012 00:13
The intended settings for a lein 2 compatible clojurescript one project
(defproject one "1.0.0-SNAPSHOT"
:description "Getting Started with ClojureScript."
:dependencies [[org.clojure/clojure "1.4.0"]
[ring "1.1.5"]
[compojure "1.1.3"]
[org.clojure/clojurescript "0.0-1450"]
[enlive "1.0.1"]
[domina "1.0.1-SNAPSHOT"]
[org.mozilla/rhino "1.7R3"]
[com.google.javascript/closure-compiler "r2079"]