Fork me on GitHub
#beginners
<
2021-06-15
>
quan xing05:06:48

Which open source Clojure project for beginner ?

quan xing09:06:24

thanks didibus

quan xing09:06:50

why are you call didibus?

practicalli-johnny11:06:27

Or some more involved web applications (but still very simple) here https://practical.li/clojure-webapps/

dgb2309:06:34

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.

practicalli-johnny11:06:46

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/

🙏 2
popeye13:06:25

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}

borkdude13:06:38

(fn [the-map] (assoc the-map :hash (hash (:color the-map)))) + map(v)?

Aviv Kotek14:06:49

what's the common way to skip a specific test? (using clojure.test) something like @skip (deftest.....)

delaguardo14:06:48

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

Darin Douglass14:06:58

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
  ...)

borkdude15:06:04

or just comment the test with #_ if you want to skip it ?

👍 4
delaguardo07:06:39

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 😉

stagmoose14:06:04

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?

MatElGran15:06:27

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

MatElGran15:06:21

So you’re right (I think) saying it does not cause side effect, but it relies on one

stagmoose15:06:20

Ok, thanks!!

MatElGran15:06:55

you’re welcome

❤️ 2
Endre Bakken Stovner16:06:05

I'd like to communicate with my webserver by sending JSON-data. Never done that before. Never really needed to understand csrf-tokens 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?

MatElGran16:06:04

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

Lance Erickson17:06:39

(Which has security implications but if it is just an experiment is totally cool) https://owasp.org/www-community/attacks/csrf

👍 2
Apple22:06:30

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

Apple22:06:47

the token can be embedded in http header of post request or as a parameter in the post body

Endre Bakken Stovner13:06:04

I've read all your replies, thanks!

Endre Bakken Stovner13:06:05

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

Apple13:06:59

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.

Endre Bakken Stovner14:06:42

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.

Joel19:06:33

is there a corollary of cond-> that will pass the piped value to a condition function?

seancorfield19:06:21

Do you mean like condp-> described here https://github.com/worldsingles/commons ?

Joel19:06:57

I guess you would know as you wrote it. 🙂 Looks like it.

seancorfield19:06:15

Well, I wasn’t sure if that was actually the functionality you were looking for 🙂 but, yeah, we use it occasionally at work.

Joel21:06:44

i was realizing i can't do this without a macro, or at least not as far as I can tell.

Joel21:06:53

actually, partial might do it i guess.

borkdude21:06:37

usually I don't bother with fancy constructs like these (anymore) if they are not in core and will just write a let instead

seancorfield21:06:53

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.

seancorfield21:06:25

(we don’t use condp->> at all now and we only use condp-> in ten files out of nearly 800)

Joel21:06:02

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.