This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-15
Channels
- # babashka (41)
- # beginners (47)
- # calva (7)
- # cider (5)
- # cljsrn (2)
- # clojure (38)
- # clojure-europe (74)
- # clojure-nl (2)
- # clojure-spec (1)
- # clojure-uk (38)
- # clojurescript (42)
- # component (30)
- # core-async (2)
- # cryogen (6)
- # cursive (47)
- # datahike (7)
- # datomic (18)
- # defnpodcast (1)
- # fulcro (17)
- # graalvm (8)
- # graphql (4)
- # helix (5)
- # honeysql (5)
- # introduce-yourself (1)
- # jobs (5)
- # jobs-discuss (4)
- # malli (20)
- # meander (4)
- # mental-health (1)
- # off-topic (41)
- # pathom (18)
- # podcasts-discuss (2)
- # re-frame (20)
- # react (1)
- # reagent (22)
- # reitit (2)
- # releases (2)
- # remote-jobs (1)
- # reveal (2)
- # sci (10)
- # shadow-cljs (42)
- # sql (20)
- # tools-deps (7)
- # vim (2)
- # xtdb (51)
@U025AG2H55F 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}
what's the common way to skip a specific test? (using clojure.test)
something like
@skip
(deftest.....)
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
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
...)
heh yea
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 😉
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
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?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
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
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.
Do you mean like condp->
described here https://github.com/worldsingles/commons ?
Well, I wasn’t sure if that was actually the functionality you were looking for 🙂 but, yeah, we use it occasionally at work.
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 @U04V15CAJ’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)