Fork me on GitHub
#clojure
<
2021-07-14
>
Nazral02:07:35

Some more clojure interop question: Cannot cast clojure.lang.PersistentVector to [F what is [F in Java again? 馃檹 Solution is float-array, nevermind

馃憤 3
restenb06:07:58

how do you web devs handle content escaping for your ring webapps? i'm specifically thinking of the server->client direction, in case of e.g. bad html/JS content having been saved to the db bypassing input field validation on the client

p-himik08:07:12

Prevent bad data from being saved in the first place. Validate also on the server, using CLJC helps. Have reasonable DB constraints.

dgb2308:07:36

You validate on input but you also escape on output

dgb2308:07:14

client side frameworks and templating engines for example have these baked in (well except for things like PHP).

dgb2308:07:54

for example reactjs does this, when you pass a prop as a child it will get escaped by default

dgb2308:07:39

you need to pass it through a function that is marked as unsafe (i think it is called dangerouslysomething) if you want unescaped stuff

dgb2309:07:49

In other words: you defend against such things where they are used. The issue with not doing that is that you can put two things together (relational data) and pass it to the client. In isolation they might be fine, but not in combination. Not every system can know of the usage context of every other system.

Nazral10:07:26

Another Java interop question, in https://github.com/SpaiR/imgui-java/blob/master/example/src/main/java/Main.java#L81, the sliderFloat method changes the value of flt (if I understand correctly) that is declared above in the class. How can I reproduce this? I've tried using atoms, but that didn't work. Solution was a question of scope, it works

restenb11:07:43

In general, you probably want to return the ImGui object to a calling scope, for example after calling necessary functions on it in a separate fn, and pass that around. Exact code would depend on the use case.

jaju11:07:56

Are you looking for a clojure way to operate on the flt array?

Nazral11:07:09

@U06KGH6LB No I was really not sure how to even pass flt in this context, but now that I know it's a question of scope, I guess it makes sense to have a state atom and pass it to the whole UI. @U52RNHDRN I am not sure how to do that at the moment

馃憤 2
restenb11:07:21

(let [gui-obj (.sliderFloat (ImGui.) "float" flt 0 1)]...)

restenb11:07:12

now gui-obj is a ImGui object where the sliderFloatfunction has been called and probably modified it's state. now you can do other stuff with it

Nazral11:07:23

I am not sure that's feasible because when you start ImGui it has its own render loop and a process method that is called at each iteration, so I think it's mostly a question of keeping a state somewhere and have the ui read it

robert-stuttaford10:07:28

is there a way to print edn in a way that it includes ' quotes? e.g. i want to print code that has a datomic query in it, and i want the query vector to be printed with a preceding quote.

borkdude10:07:57

@robert-stuttaford quotes aren't part of EDN

thanks3 2
borkdude10:07:15

they are just a single standalone character in EDN, they don't mean anything

borkdude10:07:59

if you want to print code (which is a superset of EDN) this is a different question, I think?

robert-stuttaford10:07:57

yeah, seems that way. thanks for responding!

borkdude10:07:57

the way to represent this without quotes is (quote [foo bar])

robert-stuttaford10:07:32

yeah i tried that but it's a macro so you can't give it dynamic data to quote 馃槀

borkdude11:07:27

what's the problem you're trying to solve?

robert-stuttaford11:07:31

exporting datomic transaction functions to a clojure file for use when constructing throw-away in-memory databases for unit tests

robert-stuttaford11:07:18

would like to be able to emit evaluated code directly into the buffer (thanks CIDER) and then save it, and have tests pick it up. this is why i'm trying to print quotes

robert-stuttaford11:07:27

the first code block on this page shows what needs quoting; the :params value https://docs.datomic.com/on-prem/reference/database-functions.html

quoll12:07:02

What about if you construct it as data

(let [umap (symbol "umap")] 
  (list (symbol "if") (list (symbol "every?") umap [:name :email])
    [{:user/name (list :name umap)    
      :user/email (list :email umap)}]                                        
    (list (symbol "datomic.api" "cancel")                                     
      {:cognitect.anomalies/category :cognitect.anomalies/incorrect           
       :cognitect.anomalies/message "User map must contain :email and :name"})))

robert-stuttaford14:07:19

Interesting, I'll give that a go!

Karol W贸jcik11:07:37

How to get String.class in Clojure?

jkxyz11:07:36

Just String or java.lang.String will refer to the Java class @karol.wojcik

Karol W贸jcik11:07:34

(.getDeclaredMethod (Class/forName "java.lang.ProcessEnvironment") "getenv" java.lang.String)
throws java.lang.Class cannot be cast to [Ljava.lang.Class;

jkxyz11:07:05

Pass (into-array [String]) as the last argument to .getDeclaredMethod

jkxyz11:07:58

It鈥檚 a variable-arity method and that error means that it was expecting to see an array. To call variable-arity Java methods from Clojure, you just have to pass a Java array as the last argument

jkxyz12:07:32

No problem 馃檪

grzm17:07:10

I saw a talk @seancorfield gave a while back on his repl workflow, and he mentioned a helper that eval鈥檇 a let binding but bound the named vars in the scope of the namespace rather than just in the scope of the let. Anyone happen to know more details or a link to a gist or some such? (I鈥檓 thinking it might be an editor-specific helper: hoping to port it to Emacs if need be)

Ed21:07:34

Not sure about the talk, but Cider has C-c C-v C-b which will ask you for some bindings before evaluating the preceding form ... Does that sound like what you're talking about? Or have I got the wrong end of the stick?

seancorfield17:07:47

@grzm All of that is in my dot-clojure repo on GH. Specifically, all that key binding does is take the text from the let binding -- the symbol and the expression -- and wraps it in (def ...) and evals that.

grzm17:07:09

Cheers. I thought it might be there. I was digging around in there and must have overlooked it. I鈥檒l dig further.

seancorfield17:07:44

Because it's the VS Code stuff (and Clover).

borkdude17:07:53

This is what I use too, I call it "inline def" on my blog. I assumed everybody was doing this, but when I published this blog, for some people it was a new idea. https://blog.michielborkent.nl/2017/05/25/inline-def-debugging/ which is being DDOS-ed now :-S Some people use tools for this but I find this usually sufficient to capture values.

grzm17:07:12

Thanks, @U04V15CAJ and @seancorfield! These kinds of snippets/habits may be quotidian, but they鈥檙e oh-so-helpful when you start using them.

didibus18:07:14

Ya, that's a neat little trick, if you use Calva or Cider, you should also try out the debugger, unlike in other language, it is very simple to enter into, its all happening in the REPL. It can be useful for more complicated cases

didibus18:07:46

Tracing is also pretty neat

borkdude18:07:50

I do use CIDER but I've never really gotten into these features, I keep it very basic in my REPL :)

didibus18:07:33

I just say it, because, they take like very little to learn to use and they're great and super quick to use once you know them

borkdude18:07:22

The DDOS to my site seems to be over ;)

blak3mill3r18:07:42

There is also https://github.com/vvvvalvalval/scope-capture I like that one, it does support the simple method of turning a let into a series of defs (at least, it's equivalent to that) ... it also supports not introducing new symbols for development purposes (instead using letsc)

didibus18:07:22

Enlighten mode:

didibus18:07:40

Both are just one command away 馃槢

blak3mill3r17:07:46

The cider debugger is extraordinarily nifty

Drew Verlee21:07:17

Does the clojure starting page always list the latest version of CLI tools? e https://clojure.org/guides/getting_started > curl -O https://download.clojure.org/install/linux-install-1.10.3.855.sh

馃檶 2
Drew Verlee21:07:05

it would seem so, the docs answered my question a moment later, which was how to see the changelog.

Alex Miller (Clojure team)21:07:08

yes, it always lists the latest stable version of the tools

Alex Miller (Clojure team)21:07:21

I update it when I update the tools release page

馃憤 2