beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
solf 2021-06-15T00:45:00.167500Z

it means "approximately", as it can be logarithmic time

solf 2021-06-15T00:46:26.167800Z

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

quan xing 2021-06-15T05:49:48.169700Z

Which open source Clojure project for beginner ?

2021-06-15T07:01:33.169900Z

This is a good one https://github.com/prestancedesign/pingcrm-clojure

2021-06-15T07:02:13.170200Z

This one too: https://github.com/seancorfield/usermanager-example

quan xing 2021-06-15T09:12:24.170600Z

thanks didibus

quan xing 2021-06-15T09:12:50.170800Z

why are you call didibus?

practicalli-john 2021-06-15T11:16:32.171800Z

@imxingquan Absolute beginner projects here https://practical.li/clojure/simple-projects/

practicalli-john 2021-06-15T11:17:27.172Z

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

2021-06-15T07:01:33.169900Z

This is a good one https://github.com/prestancedesign/pingcrm-clojure

2021-06-15T07:02:13.170200Z

This one too: https://github.com/seancorfield/usermanager-example

quan xing 2021-06-15T09:12:24.170600Z

thanks didibus

quan xing 2021-06-15T09:12:50.170800Z

why are you call didibus?

dgb23 2021-06-15T09:31:34.171100Z

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.

2021-06-15T09:38:43.171200Z

Ok, thanks.

practicalli-john 2021-06-15T11:14:46.171400Z

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/

1🙏
practicalli-john 2021-06-15T11:16:32.171800Z

@imxingquan Absolute beginner projects here https://practical.li/clojure/simple-projects/

practicalli-john 2021-06-15T11:17:27.172Z

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

popeye 2021-06-15T13:11:25.174400Z

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}

borkdude 2021-06-15T13:25:38.175100Z

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

Aviv Kotek 2021-06-15T14:40:49.176Z

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

2021-06-16T07:53:39.207Z

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 😉

2021-06-15T14:43:48.177700Z

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

Aviv Kotek 2021-06-15T14:44:07.177900Z

💪 ty

Darin Douglass 2021-06-15T14:44:58.178200Z

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

stagmoose 2021-06-15T14:55:04.182Z

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?

MatElGran 2021-06-15T15:01:27.182100Z

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

MatElGran 2021-06-15T15:05:21.182500Z

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

stagmoose 2021-06-15T15:06:20.182700Z

Ok, thanks!!

MatElGran 2021-06-15T15:07:55.182900Z

you’re welcome

1❤️
borkdude 2021-06-15T15:57:04.183200Z

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

2👍
Endre Bakken Stovner 2021-06-15T16:20:05.183600Z

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?

Endre Bakken Stovner 2021-06-16T13:06:04.229100Z

I've read all your replies, thanks!

Endre Bakken Stovner 2021-06-16T13:11:05.229300Z

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

Apple 2021-06-16T13:59:59.229600Z

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 Stovner 2021-06-16T14:05:42.230200Z

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.

Aviv Kotek 2021-06-15T16:32:09.184100Z

heh yea

Aviv Kotek 2021-06-15T16:32:14.184300Z

👍

MatElGran 2021-06-15T16:58:04.184500Z

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

Stas Makarov 2021-06-15T17:01:11.185500Z

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.

Lance Erickson 2021-06-15T17:04:39.185800Z

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

1👍
Joel 2021-06-15T19:06:33.187800Z

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

seancorfield 2021-06-15T19:11:21.188Z

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

Joel 2021-06-15T19:15:57.188300Z

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

Joel 2021-06-15T19:16:04.188500Z

thanks

seancorfield 2021-06-15T19:29:15.188700Z

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

Joel 2021-06-15T21:36:44.189Z

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

Joel 2021-06-15T21:37:53.189200Z

actually, partial might do it i guess.

borkdude 2021-06-15T21:38:37.189400Z

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

seancorfield 2021-06-15T21:39:53.189700Z

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.

seancorfield 2021-06-15T21:41:25.189900Z

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

Joel 2021-06-15T21:52:02.190100Z

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.

Apple 2021-06-15T22:10:06.190400Z

Try this https://luminusweb.com/docs/security.html

Apple 2021-06-15T22:11:30.190600Z

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

Apple 2021-06-15T22:12:47.190800Z

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