This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
@kardan bidi guards are for filtering routes based on method, if no route matches you get a 404. 405 is a property of the resource, so if you want 405/406 you should use Liberator - yada will fully support 405/406 too
Is there a better way of converting a hasmap into a sequence of pairs than (map vector (keys the-map) (vals the-map)) ?
@ul: thanks.
What should I do if I want to push a modified version of a library to clojars to use it in one of my projects before my changes are accepted upstream and released?
@pupeno push it under your own namespace, e.g. pupeno/cool-project
There are instructions on clojars for doing that.
Cool. THanks.
Anyone got a version of load-string/eval that works with a provided context? Like a map as a second argument
@alqvist: well, you could wrap it in a let form maybe? like read the string, wrap it in a let, then eval
@val_waeselynck: like (let [c "text" e (read-string "c")] (eval e)
no, more like (eval (list 'let '[c "text"] (read-string "c")))
this may not be the most elegant way, but you get the idea
@alqvist: more elgant imo:
(let [context-bindings '[c "text"]]
(eval
`(let context-bindings (read-string "c"))))
@val_waeselynck thanks, I ended up with this (defn eval2 [context s]
(let [context-bindings `['c context]]
(eval
`(let context-bindings (read-string s)))))
@alqvist: how do you call it? I don't see what ['c context] is for
okay got it.
Still got a problem though, if I have a list or a range in the context map I get an exception: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn
@alqvist: you'll want to quote context
when calling eval2
. E.g (eval2 '{:numbers (range 10)} "(count (:numbers c))")
instead of (eval2 {:numbers (range 10)} "(count (:numbers c))")
Does anyone have a simple configuration templating function lying around? E.g. given a template like "window.my_endpoint = "${API_ENDPOINT}"
, to replace the $ vars with data from a map or local environment vars?
@val_waeselynck: thanks for your help
@alqvist: you're welcome note that for your use case, dynamic vars may offer an advantage over let
bindings:
(def ^:dynamic c)
(binding [c {:id "woot"}]
(eval (read-string"(:id c)")))
in clojure JVM, what's the difference when I do (go (println (.getId (Thread/currentThread))))
, or (thread (println (.getId (Thread/currentThread))))
I notice that the go expression uses a new thread every time I evaluate it, and the thread expression re-uses the same thread
@borkdude: There’s no functional difference. The difference is how the two are executed. The go
expression is executed on a thread pre-allocated for go blocks. The thread
expression is executed on a thread in an infinite threadpool.
@potetm: yeah, I was wondering about the 'how'. the thread pre-allocated for go-blocks, it seems to be different every time
@borkdude: http://stackoverflow.com/questions/949355/newcachedthreadpool-v-s-newfixedthreadpool