Fork me on GitHub
#admin-announcements
<
2015-10-14
>
sidrero12:10:41

hi I am new to clojure, and I got a question I have not being able to find a definitive answer on google I work with a big java desktop application, where I have managed to embedd jython to provide a scripting framework it works well, but I hate java scientific libraries, jython cannot use numpy and Co. I got interested in Inchanter instead. Now I am wondering if I can also embedd clojure into the java app in the same way as I did for jython. What I do with jython, is on java, I create an interpreter, set paths to different modules I need dynamically then I put a 2D matrix (a list of lists) into the interpreter and then I load the script I want and execute a function that will always be in every script by convention, and which takes that 2D matrix I put into the interpreter the function returns another 2D matrix, which then I can recover from java side and cast to java types and then some other small things like redirecting jython stdout and stderr to java so that I can print nicely on the java app, etc Would it be possible with clojure? Somehow I got the feeling it is not designed for this purpose.

mikera13:10:27

Hi @sidrero you should be able to use core.matrix for most of what you need. It supports conversions to / from various different matrix representations

mikera13:10:16

core.matrix is roughly equivalent to numpy in terms of scope, most of the same functionality is there too

nnbosko20:10:17

I have a small question regarding clj-http. How can I emulate a curl post that does this? curl -X POST 'https://website.com/endpoint' -d 'request_body={ ... }'

oliy20:10:00

@nnbosko: this should do it

(require '[cheshire.core :as json])
(require '[clj-http.client :as http])
(http/post "" {:body (json/encode {...})})
there are a lot of excellent examples in the readme on github https://github.com/dakrone/clj-http

nnbosko20:10:40

Sorry, I should have been more specific. The issue isn't that per se, I know more or less how to deal with clj-http, the issue is specifically sending 'request_body = { ... }' as data

nnbosko20:10:45

Not request body as a json parameter itself, but request_body={ "api_key" : "xxxxxx", "name" : "xxxxx" etc }

nnbosko20:10:21

hence -d 'request_body={...}'

nnbosko20:10:50

Am I clear, @oliy?

oliy20:10:49

so the body is "request_body={...}"?

nnbosko20:10:51

I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails

oliy20:10:30

then i'm afraid the finer points of what curl is doing there is lost on me!

gusbicalho20:10:32

@nnbosko: "I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails" fails how?

nnbosko20:10:58

It says request_body is empty

nnbosko20:10:54

More specifically this is the body of the request I'm getting from the server

nnbosko20:10:13

:body "{\"status\":\"ERROR\",\"status_code\":\"BP-DPAR-1\",\"status_message\":\"request_body is empty\"}"

gusbicalho21:10:50

I think it's something on your server side. I tried here and (client/post "" {:body "request_body={...}"}) works fine, the server gets the string "request_body={...}"

nullptr21:10:58

what’s the content-type header on the POST?

nullptr21:10:24

typically you need to set application/x-www-form-urlencoded to get standard parsing behaviors to work, this is often automatic

gusbicalho21:10:26

yeah, if it works with curl but doesn't work with clj-http, it's probably a matter of the default content-type being different for each one, which causes the server to misunderstand the body