This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-03
Channels
- # aws (1)
- # bangalore-clj (3)
- # beginners (3)
- # boot (9)
- # business (1)
- # cljs-dev (72)
- # cljsjs (7)
- # clojure (86)
- # clojure-austin (1)
- # clojure-belgium (4)
- # clojure-brasil (14)
- # clojure-conj (3)
- # clojure-dev (10)
- # clojure-italy (4)
- # clojure-poland (14)
- # clojure-russia (36)
- # clojure-spec (144)
- # clojure-uk (50)
- # clojurebridge (1)
- # clojurescript (160)
- # clr (2)
- # core-async (8)
- # cursive (56)
- # datomic (34)
- # devcards (3)
- # emacs (2)
- # ethereum (1)
- # events (3)
- # hoplon (21)
- # jobs (2)
- # leiningen (9)
- # luminus (3)
- # off-topic (1)
- # om (26)
- # onyx (42)
- # pedestal (29)
- # protorepl (1)
- # re-frame (43)
- # reagent (26)
- # rethinkdb (4)
- # ring-swagger (4)
- # spacemacs (5)
- # specter (4)
- # untangled (102)
- # vim (43)
- # yada (10)
any idea how i can mock a call to (System/getProperty …)
in a clojure test:
tried:
(deftest test-api
(testing "get-flag correct when mac os x"
(with-redefs-fn {#'System/getProperty (fn [_] "Mac O X")}
#(is (= (api/get-flag) "-x")))))
errors with:
Error refreshing environment: java.lang.RuntimeException: Unable to resolve var: System/getProperty in this context, compiling:(…)
api/get-flag looks like
(defn get-flag
"depending on OS"
[]
(let [os (System/getProperty "os.name")]
(case os
"Linux" "-w"
"Mac OS X" "-t"
:default "-w")))
@dviramontes with-redefs
etc operate on vars, System.getProperty is a java class with a static method. afaik there's no way to runtime stub it out. I would hide System.getProperty behind another clojure function, or a component, which can be stubbed out
@bfaber umm ok, that makes sense. I’ll wrap it in a function and give that a shot, thanks!!!
@bfaber that totally worked!! thanks again!!
Is it of any benefit to use java.jdbc/insert-multi! vs insert! for performance reasons, when you need the returned keys? It doesn’t seem so, because it does multiple inserts anyway
@dviramontes you could also just set the flag 🙂 in pseudocode:
deftest:
try
set flag
test your function
finally
set flag to original value
How do I check the version of a dependency from within my Clojure program?
I'm receiving (in cljs) --- Don't know how to create ISeq from: clojure.lang.Symbol
I just can't figure out how to do this one properly: transform (map)
{"a.b.c" 1
"a.b.d" 2
"e.f" 3}
to
{"a" {"b" {"c" 1
"d" 2}}
"e" {"f" 3}}
(defn nested [m]
(let [f (fn [res [k v]]
(assoc-in res (clojure.string/split k \.) v))]
(reduce f {} m)))
(nested {"a.b.c" 1 "a.b.d" 2 "e.f" 3})
=> {"e" {"f" 3}, "a" {"b" {"d" 2, "c" 1}}}
ouch, that's nice... and definitaly shorter than what I was doing
never thought on using reduce...
yeah, I was at merge-with merge
and stuff, didn't like it
thanks, by the way!
I have a weird problem with transit-clj: when writing data from time to time it died with an exception Not supported: java.lang.String
, but today it started to happen really often. Any ideas what the problem is? I use custom write handlers (which handle org.joda.DateTime), but it doesn't seem to have any effect.
@asolovyov post full exception.
I have a problem with nrepl and cider, for which I can't find an answer with google. I can't jump to the source of a something, I get "No source location"/ I run leiningen and my nrepl on a vagrant virtual machine. How can I fix this?
@rvanlaar The problem is that the file doesn't exist for you on your local machine, in a way that makes sense to the nrepl.
I'm not sure I understand. nrepl is always on the network - it's just when you run it in the same host, cider-nrepl can enable additional features like find-source
You might be able to get round it if the files were in the same location on guest and host OS. But that's a long shot really.
@rvanlaar the way it works is by searching the nrepl classpath. If that's on another machine, it won't be able to find the relevant files. Not sure on a proper fix for this really.
is there an off-the-shelf memoize (maybe even backed by core.cache/core.memoize) that can ignore the first N args of my function for purposes of testing whether or not the invocations are the same?
not to my knowledge
@rvanlaar ask around in #cider as well. its actually pretty active and the core maintainers are often responsive
How to realize a lazy sequence? At the time when it is unknown what it actually is. I know that I can do (into [] (lazy-seq [1]))
for every collection but the problem is that I don't know what is the real type of a sequence.
there's clojure.algo.generic
(although not in core) can maintain the collection type while performing operations like map/filter
I would recommend using transducers/`into` over that (or mapv
/ filterv
)
@pupeno On finding dependency versions — I wrote a fn to read project.clj
from the classpath and then apply regex to extract the version from a pattern. No clean alternative unless build tools put in project info as an EDN file in the JAR. Might be worth pinging on #leiningen and #boot channels.
Anybody using clojure.spec?
@tokenshift a lot of people seem to be playing with it at least, and it seems like @seancorfield is using it for reals
Ooh, shiny
Thanks!
with-out-str does not seem to be capturing messages printed to standard out by a Java method. Is this to be expected? And if so, is there a workaround to capture output made by a Java call?
with-out-str redefines the dynamic var out, it doesn't redirect the java output stream, so it's expected
this SO seems to have reasonable instructions for setting System.out http://stackoverflow.com/questions/8708342/redirect-console-output-to-string-in-java
(string/replace
"replace (me)"
(re-pattern
(format "(\\s|\\t|\\(|\\[)(%s)(\\s+|\\t+|\\)|\\])" "me"))
(str "$1" "here"))
This regex returns replace (here
but I looking to get replace (here)
I thought $1
would ensure me to target only whats inside the second paren group?For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.
All the years of programming and not needing regexp is embarrasing for my regex knowledge.
If you want to replace me
with here
, but only if it appears within the context you provided in your regex, you will need positive lookahead/lookbehind—not sure if Clojure (i.e. Java) regex supports this.
that said, using those features in a regex is basically the same as writing a big comment that says "HAHA, NOW YOU HAVE TO LOOK AT A REGEX MANUAL" above the line
Anyone know off-hand if there’s a way to insert a string that I want to treat as raw HTML, inside Hiccup datastructures? I need one of those gross <!--[if IE]>
statements in a page.
@mathiasx Yes, you can use hiccup.util/raw-string
for that I believe.
Either I missed it in the docs or it didn’t seem very clear — if so, I may send a docs PR to make sure others find it 🙂
Or maybe escape-html
depending on exactly what you need...
Since it is script tags and such that conditionally get added to a page, it’ll need to stay unescaped. Standard IE polyfill junk 😞
Hmm, hiccup.core/h
exists as an alias for hiccup.core/escape-html
— TIL.
Yeah, raw-string
is probably what you need for that.