Fork me on GitHub

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

馃憤 3

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


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


You validate on input but you also escape on output


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


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


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


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.


Another Java interop question, in, 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


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.


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


@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

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


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


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


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.


@robert-stuttaford quotes aren't part of EDN

thanks3 2

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


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


yeah, seems that way. thanks for responding!


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


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


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


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


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


the first code block on this page shows what needs quoting; the :params value


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"})))


Interesting, I'll give that a go!

Karol W贸jcik11:07:37

How to get String.class in Clojure?


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;


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


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


No problem 馃檪


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)


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?


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


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


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


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. which is being DDOS-ed now :-S Some people use tools for this but I find this usually sufficient to capture values.


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


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


Tracing is also pretty neat


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


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


The DDOS to my site seems to be over ;)


There is also 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)


Enlighten mode:


Both are just one command away 馃槢


The cider debugger is extraordinarily nifty

Drew Verlee21:07:17

Does the clojure starting page always list the latest version of CLI tools? e > curl -O

馃檶 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