beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
sova-soars-the-sora 2021-01-24T04:52:31.197300Z

Hi, my ring anti forgery token is invalid... even though I am including it in the page. I think it might have to do with the slashes in the aft.

seancorfield 2021-01-24T05:04:55.198400Z

@sova Have you verified in the browser dev tools that the token really is embedded in your form?

seancorfield 2021-01-24T05:06:32.199200Z

(it's very easy to get the middleware stack wrong and "lose" the token between it being generated and the page actually being rendered)

seancorfield 2021-01-24T05:08:06.199900Z

(it's also easy to get the stack wrong so that the token is "lost" before it gets back to the piece of code that checks for it)

sova-soars-the-sora 2021-01-24T05:08:59.200100Z

oh it's definitely in there

sova-soars-the-sora 2021-01-24T05:09:31.200200Z

sova-soars-the-sora 2021-01-24T05:10:34.201500Z

but then I hit the button, and I get an anti-forgery-token invalid x_X

seancorfield 2021-01-24T05:10:35.201600Z

OK, that's good. So then either it's being lost on the return path or you have something that is causing "two requests" which was a problem I ran into.

sova-soars-the-sora 2021-01-24T05:10:47.201800Z

Oh interesting. 2 requests?

seancorfield 2021-01-24T05:11:14.202400Z

Yeah, can't remember what caused it. I found a SO post about it I think.

sova-soars-the-sora 2021-01-24T05:11:39.202600Z

Right on...

sova-soars-the-sora 2021-01-24T05:11:48.203Z

Yeah it's weird, I tested it earlier and it worked fine... once

sova-soars-the-sora 2021-01-24T05:13:34.204Z

but then I must have changed something and it's not doing anything useful x_x

seancorfield 2021-01-24T05:14:00.204400Z

In the past, I've always turned it off because it seems so fragile. But recently I've managed to get it to working, but I haven't used it in anger...

seancorfield 2021-01-24T05:14:16.204800Z

If you changed anything, you have a trail in Git, right? πŸ™‚

sova-soars-the-sora 2021-01-24T05:17:02.205Z

haha

sova-soars-the-sora 2021-01-24T05:17:06.205200Z

yes that is true

sova-soars-the-sora 2021-01-24T05:17:10.205400Z

i think this is what you mentioneD? https://stackoverflow.com/questions/30172569/how-can-i-use-ring-anti-forgery-csrf-token-with-latest-version-ring-compojure

sova-soars-the-sora 2021-01-24T05:20:55.205900Z

i just moved it to a set of routes that are not wrapped in anti-forgery for now.

sova-soars-the-sora 2021-01-24T05:21:05.206200Z

too late in the day to go bug hunting

πŸ‘ 1
sova-soars-the-sora 2021-01-24T05:21:38.206800Z

it's weird though none of my other anti-forgery-token paths have a problem... will check it again with fresh eyes... mark it a wontfix xD

sova-soars-the-sora 2021-01-24T05:21:46.207Z

thanks for your help + words of encouragement

seancorfield 2021-01-24T05:38:22.208Z

Hmm, I don't think it was that -- which was caused by a switch from explicit generation to implicit generation -- as I ran into it without even knowing about manual generation.

seancorfield 2021-01-24T05:39:17.208800Z

I think it's a bit like the CORS middleware: it is just really fussy as to how you use it and how you place it in the middleware stack.

dpsutton 2021-01-24T05:59:29.209500Z

Was the token put into the html by the running server?

sova-soars-the-sora 2021-01-25T05:02:02.233600Z

yep

Oded Hassidi 2021-01-24T12:45:43.212500Z

Hello all, wondering about ^:const and ^:static are they efficient? should I use them? what more like these exists and where can I find it? Thanks

bronsa 2021-01-24T13:31:09.214300Z

^:static is not a thing

bronsa 2021-01-24T13:31:39.214900Z

^:const instructs the compiler to inline the value of the var, it should only be used for numbers/strings

Christian 2021-01-24T13:40:41.215600Z

Is this macro workshop up-to-date and has anyone done it / can recommend it? https://github.com/dcolthorp/lj-macro-workspace

Christian 2021-01-24T13:42:15.216200Z

Is @dcolthorp call-able when is not part of the channel?

Christian 2021-01-24T13:55:37.216300Z

Hm. Sounds like a little more traction than I thought with VS Code and Calva. Not sure if I want to spend a lot of time fixing this, to see that it's not up-to-date in the end.

Warning: cider-nrepl requires Clojure 1.8 or greater.
Warning: cider-nrepl will not be included in your project.
As of 2.8.2, the repl task is incompatible with Clojure versions older than 1.7.0. 
You can downgrade to 2.8.1 or use `lein trampoline run -m clojure.main` for a simpler fallback repl.
Subprocess failed (exit code: 1)

roelof 2021-01-24T17:34:58.216900Z

What is here wrong

#(map (interleave [0] %) [1 2 3])

caumond 2021-01-24T17:36:38.217600Z

hi, can you provide an example of the expected behavior?

caumond 2021-01-24T17:37:23.218400Z

because I don't understand what you want to achieve

jaihindhreddy 2021-01-24T17:42:52.219100Z

interleave takes sequences as arguments. In this case, interleave is called thrice, with 1, 2 and 3 as the second arguments respectively. And they aren't sequences. Can you give us an example of an input and expected output, so that we can help you better?

roelof 2021-01-24T17:42:57.219400Z

I try to re-implement interpose. For a 4clojure challenge I have to do this

roelof 2021-01-24T17:44:17.219500Z

the 4clojure challenge has this test

(= (__ 0 [1 2 3]) [1 0 2 0 3])
I have to implement interpose

jaihindhreddy 2021-01-24T17:44:48.219700Z

I see, if you're trying to re-implement interpose, you could interleave the input sequence with (repeat 0), and then getting rid of the last element, with butlast.

jaihindhreddy 2021-01-24T17:45:56.219900Z

On your example, (interleave [1 2 3] (repeat 0)) would evaluate to (1 0 2 0 3 0).

roelof 2021-01-24T17:46:02.220100Z

??

#(map (interleave (repeat 0) %) [1 2 3])

roelof 2021-01-24T17:46:12.220300Z

does stil not work

caumond 2021-01-24T17:46:26.220500Z

try this: (#(rest (interleave (repeat 0) %)) [1 2 3])

jaihindhreddy 2021-01-24T17:46:41.220700Z

You want to start with the input data, because you want the 0 to be in the even positions

jaihindhreddy 2021-01-24T17:47:27.220900Z

map is not something you want here. We're not interleaving each number, but the whole sequence itself...

roelof 2021-01-24T17:48:22.221100Z

thanks

caumond 2021-01-24T17:48:23.221300Z

exactly, with map, all you can do is to replace one element with two, but at the end you have a list of pairs ...

caumond 2021-01-24T17:49:33.221500Z

something like (#(map (fn [x] [0 x]) %) [1 2 3]) but this is definitly not the best way

roelof 2021-01-24T17:50:37.221700Z

yep, and I want to learn the best way

jaihindhreddy 2021-01-24T17:56:23.222100Z

An equivalent to (interleave [1 2 3] (repeat 0)) is (mapcat #(vector % 0) [1 2 3]). But interleave and repeat express it better IMHO.

roelof 2021-01-24T18:14:09.222300Z

Thanks

roelof 2021-01-24T18:14:30.222500Z

learned some more clojure

caumond 2021-01-24T18:26:02.224100Z

@roelof, it's not that I'm happy to help ! but you can have a look to other candidates solutions in 4clojure. By selecting high score guys, I used to check the quality of my solution.

πŸ™‚ 1
roelof 2021-01-24T18:36:44.225200Z

I know but do not wanto cheat and not think about how to solve things

roelof 2021-01-24T18:36:53.225400Z

@caumond

yiorgos 2021-01-24T19:03:50.227200Z

I have a small toy project and I would like to try this Java lib https://github.com/trystan/AsciiPanel I am using deps.edn for my deps and I have added this line net.trystan/ascii-panel {:mvn/version "1.1"} When I run clj thought I am getting the following error: Error building classpath. Could not find artifact net.trystan:ascii-panel:jar:1.1 in central (<https://repo1.maven.org/maven2>

yiorgos 2021-01-24T19:04:32.228200Z

In the Readme, it’s mentioned that I can add <https://jitpack.io> repo, but I am not sure how to do that with deps.edn

alexmiller 2021-01-24T19:45:24.228700Z

You can add a :mvn/repos key for that

alexmiller 2021-01-24T19:46:11.228900Z

https://clojure.org/reference/deps_and_cli

yiorgos 2021-01-24T20:37:26.229600Z

Thanks! That did work.

yiorgos 2021-01-24T20:39:50.230200Z

When I pull a dep from a different repo do I need to alter the :path alias?

alexmiller 2021-01-24T21:33:10.230700Z

probably not, pull it how?

lepistane 2021-01-24T21:57:19.231800Z

Hello, i was wondering if we can pass clojure data structures as arguments to basic cli program? Currently i am sending string and doing clojure.end/read-string but that feels awkward

George Gatuma 2021-01-25T08:17:22.238700Z

Try macros

lepistane 2021-01-25T09:23:56.241200Z

oh ok I thought there is cli specific option that i might've missed thanks

πŸ‘ 1
lepistane 2021-01-25T12:18:05.261900Z

btw there is new option -X which does function invocation and u can pass it single hashmap as argument so check it out

dpsutton 2021-01-24T22:21:24.232400Z

Have you seen the new -X invocation of the clojure cli?

lepistane 2021-01-25T09:23:39.240600Z

yes i did but i am always getting

Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-X (No such file or directory)

Full report at:
i have deps.edn , src/data.clj that has fn foo, and when i do clj -X data/foo i get this error did i do anything wrong? (clojure version 1.10.1)

lepistane 2021-01-25T12:18:40.262500Z

SOLUTION cli version was old i repeated steps from https://www.clojure.org/guides/getting_started and -X worked