it means "approximately", as it can be logarithmic time
I tried looking up the exact implementation of contains? for sets, but my java-fu is very bad and I didn't find it. Maybe it becomes logarithmic if the size of the set reaches a certain point
Which open source Clojure project for beginner ?
This is a good one https://github.com/prestancedesign/pingcrm-clojure
This one too: https://github.com/seancorfield/usermanager-example
thanks didibus
why are you call didibus?
@imxingquan Absolute beginner projects here https://practical.li/clojure/simple-projects/
Or some more involved web applications (but still very simple) here https://practical.li/clojure-webapps/
Not sure where I should post this question. I’m comming from dynamic webdev languages and am not at all fluent in the JVM ecosystem. My usecase is basic image processing of web images, typically generated and uploaded by a user. I only need a small set of operations such as scale, crop, fit, common format conversions (jpeg, png, webp, base64...). This is for a side-project. My intuition from looking at github projects is that I could start with Java awt and go from there. Do you have any recommendations? I wouldn’t mind using a (preferably small) library that covers these operations or else, if you think the Java awt library is a good place to start and dig into.
https://github.com/mikera/imagez looks promising little library for some image manipulation There is also https://github.com/karls/collage which provides some nice documentation for image manipulation https://karls.github.io/collage/
I have line `
(def map3 [ {:size 7 :color "blue" } {:size 8 :color "Orange" } {:size 10 :color "yellow"} ])
how can I get the hash
value of color
of each map and do assoc
inside each map ? ex - {:size 7 :color "blue" :hash 123456}
(fn [the-map] (assoc the-map :hash (hash (:color the-map))))
+ map(v)
?
what's the common way to skip a specific test? (using clojure.test)
something like
@skip
(deftest.....)
There is at least one problem with #_
as a test-skipper — it is not possible to get a warning that the code base has such tests 😉
you could add metadata to the var
(deftest ^:skip test-name …
and then teach your test runner to skip such tests. For example kaocha can do it out from the box - https://cljdoc.org/d/lambdaisland/kaocha/1.0.861/doc/6-focusing-and-skipping
💪 ty
same for lein:
;; project.clj
(defproject foo
:test-selectors {:all (constantly true)
:integration :integration
:default #(not (:integration %)})
;; foo_test.clj
(deftest ^:integration test-something-that-needs-something-else
...)
I am reading re-frame doc (https://github.com/day8/re-frame/blob/master/docs/Coeffects.md) regarding coeffects and find the sentence highlighted below.
I think .getItem
only read value and use js->clj
to transform that data, which will not cause any change to the original data (Am I right ?), so the codeblock will not cause any side effect, right?
Yes, but it gets that value from a source external to the system/program, (that is to say that function does not only rely on its params to work) and that is a side effect
So you’re right (I think) saying it does not cause side effect, but it relies on one
Ok, thanks!!
you’re welcome
or just comment the test with #_
if you want to skip it ?
I'd like to communicate with my webserver by sending JSON-data. Never done that before. Never really needed to understand csrf-token
s either. Luminus has always taken care of that for me. But now I get Invalid anti-forgery token
when trying to send JSON-data to my server. Anyone has any fixes to suggest?
To begin I added a "/json"
route for testing:
(defn home-routes []
[""
{:middleware [middleware/wrap-csrf
middleware/wrap-formats]}
["/" {:get home-page}]
["/json" {:post #(constantly "some json")}] ;; added by me now
...
When I do
curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"id": 1}' localhost:3000/json
I get the error
<h1>Error: 403</h1>
<hr>
<h2>Invalid anti-forgery token</h2>
but I expected to see "some json"
.
How do I fix this? I could add a "x-csrf-token" token
to my header, but where would I get it from?I've read all your replies, thanks!
It seems to me that csrf-tokens should be used for POST requests, but I do not see an easy way to get the csrf-token when I am sending requests from the command line. Perhaps this is a question for #ring rather
if you have to you could expose an api over http get
to allow clients to get the token. i'm not sure one way or another if that's safe practice.
I do not know either. Or since it is one user/one server I could add a password, but then I'd need to read up on how to send/store these safely.
heh yea
👍
Not sure about this, (I know neither luminus or ring, complete clojure beginner here, so bear with me please) but having a look at the luminus guestbook example, it seems you can add it as a hidden field in your form as https://github.com/luminus-framework/guestbook/blob/master/resources/templates/home.html#L19 and then retrieve it with JS
this tag being defined there https://github.com/luminus-framework/guestbook/blob/c0e4c05cd6b1a59602c7699266d11f56adbec197/src/clj/guestbook/layout.clj#L12
also you probably can just remove csrf middleware https://luminusweb.com/docs/security.html https://github.com/luminus-framework/guestbook/blob/c0e4c05cd6b1a59602c7699266d11f56adbec197/src/clj/guestbook/handler.clj#L17 but it's not a good idea to remove it for non-api routes.
(Which has security implications but if it is just an experiment is totally cool) https://owasp.org/www-community/attacks/csrf
is there a corollary of cond-> that will pass the piped value to a condition function?
Do you mean like condp->
described here https://github.com/worldsingles/commons ?
I guess you would know as you wrote it. 🙂 Looks like it.
thanks
Well, I wasn’t sure if that was actually the functionality you were looking for 🙂 but, yeah, we use it occasionally at work.
i was realizing i can't do this without a macro, or at least not as far as I can tell.
actually, partial might do it i guess.
usually I don't bother with fancy constructs like these (anymore) if they are not in core and will just write a let
instead
We certainly don’t use the macros in ws-commons
as much now as when they were first written so, yeah, I’m mostly in @borkdude’s camp these days. I think non-core macros can often make code less readable.
(we don’t use condp->>
at all now and we only use condp->
in ten files out of nearly 800)
the code i'm writing -- the pattern will be followed for a lot of files, so trying to make it as clean/readable as possible, so i think i might try both to compare.
if you use selmer
to render a page then this is for you. basically you send the anti-forgery token along with html page so that the script can pick it up with cljs/js code in the client browser
the token
can be embedded in http header
of post request or as a parameter in the post body