This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-03
Channels
- # bangalore-clj (2)
- # beginners (29)
- # boot (52)
- # cider (4)
- # clara (3)
- # cljs-dev (34)
- # cljsjs (7)
- # cljsrn (3)
- # clojure (71)
- # clojure-austin (1)
- # clojure-dev (5)
- # clojure-france (20)
- # clojure-russia (51)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (131)
- # core-async (56)
- # core-logic (6)
- # cursive (50)
- # datascript (19)
- # datomic (16)
- # dirac (118)
- # emacs (100)
- # events (4)
- # hoplon (14)
- # incanter (1)
- # jobs (7)
- # jobs-discuss (96)
- # jobs-rus (21)
- # lein-figwheel (5)
- # leiningen (21)
- # off-topic (11)
- # om (45)
- # onyx (42)
- # pamela (1)
- # pedestal (22)
- # portland-or (3)
- # re-frame (8)
- # reagent (5)
- # ring (9)
- # robots (1)
- # spacemacs (14)
- # specter (28)
- # sql (2)
- # untangled (165)
I forgot that I could just use predicates
And I was trying to think of a way of doing it with the provided functions
Thanks
Why not implements rseq
in reverse
? eg:
(defn reverse [xs]
(if (instance? clojure.lang.Reversible xs)
(.rseq xs)
(reduce conj () xs)))
I want '+ as a multi method. I can not have '+ as a multi method. The next best thing is to use unicode. Anyone have nice unicode bindings to clojure for math funtions?
@isaac can you state your question in a different way? not sure what you're asking.
what’s a good way to select all the content between h3 tags? (using enlive or otherwise) sample source: https://docs.google.com/document/d/1v7uDPHlxmDkqjmmVfgoHGnP4jCtXjPIqPHb860kKrso/export?format=html
(->
"<section><h3>a</h3><p>p1<p>p2<p>p3
<h3>b</h3><p>p4<p>p5<p>p6
<h3>c</h3><p>p7<p>p8<p>p9</section>"
e/html-snippet
(e/select {[:h3] [#{(e/right :h3) e/last-child}]}))
(({:tag :h3,
:attrs nil,
:content ("a")}
{:tag :p,
:attrs nil,
:content ("p1")}
{:tag :p,
:attrs nil,
:content ("p2")}
{:tag :p,
:attrs nil,
:content ("p3\n ")})
({:tag :h3,
:attrs nil,
:content ("b")}
{:tag :p,
:attrs nil,
:content ("p4")}
{:tag :p,
:attrs nil,
:content ("p5")}
{:tag :p,
:attrs nil,
:content ("p6\n ")})
({:tag :h3,
:attrs nil,
:content ("c")}
{:tag :p,
:attrs nil,
:content ("p7")}
{:tag :p,
:attrs nil,
:content ("p8")}
{:tag :p,
:attrs nil,
:content ("p9")}))
When using nippy
is it “by design” that once I redef a record or restart a the JVM the thaw process will yield a different record instance than the one I defined?
(defrecord Thing [a b])
(def x (nippy/freeze (->Thing 1 2)))
(defrecord Thing [a b])
(instance? Thing (nippy/thaw x)) ;=> false
@moxaj right that makes sense, I just assumed nippy would “retrofit” to existing class/record definitions where applicable
@martinklepsch I'm not sure if there's a way for nippy to know about the new Foo class
Weirdly though even this returns false:
(defrecord Thing [a b])
(instance? Thing (nippy/thaw (nippy/freeze (->Thing 1 2)))) ;=> false
hm, seems this is caused by my REPL state
but every time it seems the macro does not work when an expression does not throw an exception
maybe I’m wrong, but is
is not needed
@residentsummer it works. thanks!
well, it may work not as expected...
because of now we’re missing the is
logic completely
@residentsummer indeed. it doesn't work when an exception is actually thrown
@b06 hmm.. checking the sources, this might not be possible, because the multimethod dispatches on the first symbol in the expression after is
just checked the source as well
@moxaj I don’t get how the solution from the article supposed to work
@residentsummer no idea
@b06 @moxaj @residentsummer
Look at the source for thrown? that is linked to in the article. Just reverse :pass
and :fail
, put this in your code::
(defmethod assert-expr 'not-thrown? [msg form]
(let [klass (second form)
body (nthnext form 2)]
`(try ~@body
(do-report {:type :pass, :message ~msg,
:expected '~form, :actual nil})
(catch ~klass e#
(do-report {:type :fail, :message ~msg,
:expected '~form, :actual e#})
e#))))
(deftest thrown-tests
(testing "should throw an exception"
(is (thrown? Exception (/ 1 0))))
(testing "should not throw an exception"
(is (not-thrown? Exception (/ 1 1))))
)
Ran 1 tests containing 2 assertions.
0 failures, 0 errors.
The clojure.test/is
macro is baroque, not a good example to follow. (citation: I wrote it.) The good news is that all you need to do to integrate with clojure.test's output reporting is call do-report
with one of those maps. You don't even need to use is
or implement assert-expr
.
@stuartsierra - Do you have a recommendation for what to use for testing, if not clojure.test/is
?
I didn't say do not use is
.
Use is
where it is appropriate. If you want to add your own custom testing predicates, with custom reporting, write a function or macro that calls clojure.test/do-report
@stuartsierra - Great, because I'm still using is
all the time. :-)
Expectations now supports all the clojure.test
tooling if you want a different style of tests...
Can someone provide me guidance about adding a DOS filter to a ring project using the jetty adapter? Has anyone done this? Can you send me a link to your blog post or maybe a DM? The DOS filter I am currently vetting is: https://wiki.eclipse.org/Jetty/Reference/DoSFilter
so for a jetty filter, you would likely attach that at the level of jetty, before ring has anything to do with it
filters, I think, are a java servlet thing, and would sit under the layer that is mapping between servlets and ring (which for jetty would be the servlet adapter)
Hi please can you help me?? I create this spec (s/def :channel #(re-matches #"(?i)KUSHKIPAGOS" %))
and when I execute (s/gen model-keyword)
to generate a data of the spec I’m receiving the error Unable to construct gen at: [:channel] for: :channel {:clojure.spec/path [:channel]
I saw the overrides parameter on the gen function but I don’t understand how to use it
I think if you use (s/and string? #re-matches ...)
it may work
s/and
will use the first predicate to select the generator
hello folks, is it possible while using clojure.match pattern match against empty list? ()
@mike706574 now I’m getting the error Couldn't satisfy such-that predicate after 100 tries.
@zerocooljs isn't #(re-matches #"(?i)KUSHKIPAGOS" %)
only going to match the string "KUSHKIPAGOS" (with varying case); it doesn't seem terribly surprising that the random string generator that spec is using isn't likely to generate that particular combination of characters within 100 tries with no other information than, "it's a string"
Hello guys, are there any open-source Clojure(script) projects out there suitable for a newbie to open-source but familiar with Clojure(script) to contribute to?
@tanzoniteblack here's a way to create a generator from a regex: https://github.com/gfredericks/test.chuck#string-from-regex
@tanzoniteblack yes is only to check KUSHKIPAGOS with case insensitive
@zerocooljs you might benefit from that thing that @gfredericks just sent me then
although come to think of it it doesn't support (?i)
so you'd have to do something dumb like "[kK][uU]..."
😕
oh well
@alanspringfield: Take a look at http://open-source.braveclojure.com/ - there's a "beginner friendly" checkbox that should get you some good options.