Fork me on GitHub
#clojure
<
2016-02-16
>
oli05:02:47

anyone up?

ericlavigne05:02:01

Yes, last minute packing for a trip. simple_smile

oli05:02:25

know anything about prismatic schema?

ericlavigne05:02:47

I know the idea but no experience with it.

oli05:02:03

oh well...

robert-stuttaford05:02:24

i think it’s better to just ask your question, oli simple_smile

oli05:02:21

ok. i'm writing something to query a datomic schema and generate a map which i'm passing to def schema

oli05:02:44

adding a snippet...

oli05:02:25

seems to give the right output...

oli05:02:43

{:contacts [s/Any], :name s/Str, :type s/Any, :id s/Str, :aliases [s/Str], :relationships [s/Any]}

oli05:02:00

but when I do

oli05:02:38

(s/defschema Party {:party t}) ;;where t is the output

oli05:02:44

it renders in swagger-ui as an empty map

robert-stuttaford05:02:03

what if you inspect Party at the repl? what do you see then?

oli05:02:26

looks ok

robert-stuttaford05:02:39

might help for you to be aware that you shouldn’t do things with your database connection during the compilation phase of your app

robert-stuttaford05:02:47

as it’ll try to connect when e.g. building a jar

oli05:02:52

{:party {:contacts [s/Any], :name s/Str, :type s/Any, :id s/Str, :aliases [s/Str], :relationships [s/Any]}}

ericlavigne05:02:25

Have you been able to use Party to validate anything? If so, datomic->prismatic may not be at fault for the failure in swagger-ui.

oli05:02:21

if I set this with a literal everything seems to work as expected

oli05:02:34

but rechecking now

ericlavigne05:02:48

It's possible that defschema as a macro does not do what you expect when computing its body. Prismatic might have an equivalent function version.

oli06:02:34

it is possible...

ericlavigne06:02:39

It's a very simple macro, thin wrapper around def, so that isn't likely to be the problem. https://github.com/plumatic/schema/blob/master/src/cljx/schema/core.cljx#L1088

ericlavigne06:02:11

Another possibility is that datomic->prismatic returns something that looks the same as your literal, but is not the same. For example, quoted symbols vs the evaluated equivalent of those symbols.

ericlavigne06:02:39

Try using "=" to compare the literal that works, with the computed value that doesn't work.

ericlavigne06:02:09

You can also try calling "eval" on the result from datomic->prismatic to see if that makes the difference.

oli06:02:21

i think that might be it...

oli06:02:56

pretty printing toggle...

ericlavigne06:02:23

Yes, that looks like it. Try throwing "eval" around "my code".

oli06:02:52

winner winner chicken dinner!

oli06:02:14

thanks brother!

lmergen06:02:44

guys, i'm quite new to clojure (but not FP). i'm writing test cases for a REST server i'm developing using luminus. now, this REST server is sending JSON responses, with a correct Content-Type -- but how do I make ring parse the request body as JSON? for example, i have this:

(let [response (app (request 
                         :post "/company" 
                         {:name "Big Blue"}))]
 ...)
at that point, (:body response) is just a plain string. i tried wrapping app in a wrap-json-body and wrap-json-response, but that doesn't seem to work. any pointers on some example code or things i should search for? google isn't very useful

ericlavigne06:02:32

There are some (very simple) examples on the ring-json github page. https://github.com/ring-clojure/ring-json

lmergen06:02:11

let me check that out

lmergen07:02:36

well, i'm not getting it. look at this: https://github.com/ring-clojure/ring-json/blob/master/src/ring/middleware/json.clj#L7 why is the ring-json middleware checking for the request content-type to determine whether to parse the response body?!

lmergen07:02:12

it appears as if all these utilities are written from a server perspective, rather than a client perspective?

ericlavigne07:02:38

Yes, ring is used for writing HTTP servers only. What are you trying to do?

lmergen07:02:22

wel, i'm trying to actually test my ring REST server

lmergen07:02:08

i'm using ring-mock-request to mock the requests, i'm getting a response back (which is just a "regular" object that my app would hand off to the actual ring server), and now i want my response body to be parsed

lmergen07:02:21

i'm thinking that i perhaps should give up and write my own wrapper for this

lmergen07:02:42

but i figured there would be a library to properly test REST servers?

ericlavigne07:02:26

I expect there is, but it's not something I have experience with.

lmergen07:02:28

ok, then i'll just give up and wrap this myself

marianoguerra07:02:07

hi! I'm using component and I need to delay the initialization of a part of a component until the system in initialized

marianoguerra07:02:34

this is because on some big projects it can take over a minute to initialize and makes the web api take a minute to be available

marianoguerra07:02:45

do you have any recomendation on how to do this?

dm308:02:11

hide that part in a (delay ...)?

jethroksy08:02:05

have you tried component/system-using?

jethroksy08:02:37

not sure if the dependency graph will help you with that though

marianoguerra08:02:44

@dm3: yes, my first approach would be that

marianoguerra08:02:16

the second would be to have some channel or similar component that can be injected in other components and will receive a message when the system is running so the component can start the initialization

jethroksy08:02:38

I'm trying to write a multimethod that dispatches based on the value of a string

jethroksy08:02:48

(defmulti process-cmd (fn [cmd params] cmd))

jethroksy08:02:37

I can't figure out how to match multiple values of cmd to the same dispatch function

ordnungswidrig08:02:06

jethroksy: you would need to map them to a single value in your defmulti

jethroksy08:02:31

oh so define them in the function itself

ordnungswidrig08:02:48

e.g. (defmulti process-cmd (fn [cmd params] (if (#{:a :b} cmd) :a-or-b cmd)))

jethroksy08:02:03

that makes perfect sense

ordnungswidrig08:02:38

In this case I usually write a dispatch-function which can be tested easier: (defmulti process-cmd process-cmd-dispatch)

oli08:02:34

ok - just in case this helps anyone - swagger-ui / compojure-api really doesn't like s/Any much

joachim08:02:53

Hi all. I’m looking for some advice on best practices porting a java lib to clojure. I need to port a class that implements two different Interfaces each having a variable argument method with the same name, and I’m not sure how to do that?

joachim08:02:38

i.e.: Interface A has methods m(x), m(x,y), ... Interface B has methods m(u), m(u,v), ... Class C implements both interfaces A and B The question is how to expose all this in clojure?

marianoguerra08:02:43

@joachim: I think it's not documented, but I used this and it worked https://groups.google.com/forum/#!topic/clojure/TVRsy4Gnf70

jan.zy08:02:55

I’d create two separate functions

ikitommi08:02:55

@oli: s/Any -support should be better (despite would not be supported by the current swagger-ui) and there is an issue for it https://github.com/metosin/ring-swagger/issues/85#issuecomment-175228136. Hoperfully will get a patch for it soon.

joachim08:02:24

Thanks @marianoguerra .So if I understand you’re suggesting that I implement a gen-class for extending class C and implementing all methods in both interfaces? I was hoping to not have to use gen-class though (it requires AOT-compilation). And I still wouldn’t have a clojure-way of calling the methods (i.e. I’d have to do (.m x) instead of (m x), right?)

marianoguerra09:02:21

@joachim: yes, I used gen-class, do you want to use proxy?

joachim09:02:02

@jan.zy: y thanks, makes sense. It’s just a petty that the clojure functions then wouldn’t have the same name as the java methods

joachim09:02:46

@marianoguerra: possibly simple_smile I was hoping to be able to use multimethods, but I can’t use two different multimethods with the same name at once … maybe I should just give up trying to keep the java class structure etc ...

curtis.summers14:02:49

https://clojurians.slack.com/archives/clojure/p1455485849000012 I'm just circling back to @jbaiter's comment yesterday since I was offline. Your frustration with Yesql almost exactly mirrors mine, and it was for this reason that I created HugSQL. The library is still just a few months old, but its feature set is significantly larger than Yesql right now. I've tried hard to have good docs (http://www.hugsql.org) and be responsive to any issues encountered. Yesterday was the 0.4.0 release of HugSQL, which features Clojure expressions and Snippets support. So, that said, if you like the idea of Yesql but have hit some pain points, give HugSQL a try. I welcome all feedback in making HugSQL a better product.

slotkenov14:02:20

Is clojure-liberator the goto library to setup a rest service, or are there other libraries as well?

mpenet14:02:56

anyone using spark: flambo/sparkling? if yes, why did you choose one over the other?

clusterhog15:02:27

Tried sparkling. Seemed like flambo was a predecessor.

intey15:02:41

@slotkenov https://github.com/metosin/compojure-api . It not for pure for rest, but looks nice.

intey15:02:11

Also has channel there: ring-swagger

pbaille15:02:33

Hello everyone, I’m trying to read a json string containing several objects, but clojure.data.json/read-str only read the first one, how can I do?

intey15:02:22

If you can add dependence, look at https://github.com/dakrone/cheshire

akiva15:02:59

I second that motion.

pbaille15:02:03

yes i’m doing so but the parse-string function seems to do the same as clj.data.json/read-str

akiva15:02:35

I haven’t used JSON in a bit but doesn’t it present a lazy sequence?

maio15:02:50

I believe that you can't have multiple object in one JSON file.

pbaille15:02:52

I think I will simply insert brackets at the begining and end of my str

zilvinasu15:02:14

It’s not valid json simple_smile unless they are wrapped in array

maio15:02:18

that's not valid json

pbaille15:02:32

ok good to know

akiva15:02:40

@pbaille, yeah, you need the containing brackets.

akiva15:02:28

But you can have many sub-objects. Brackets within brackets.

intey15:02:35

Also maybe present it as an array? [{}, {}]

pbaille15:02:47

yes I will do so

jcromartie15:02:58

I wonder if Clojure 1.8 could help w/ performance on Raspberry Pi

slotkenov15:02:51

@intey: Looks good the compojure-api. Thanks

jcromartie15:02:15

initial benchmark of Clojure on Raspberry Pi is 1/20 the speed of my laptop

mj_langford15:02:16

Any recommendations here?

pbostrom16:02:49

there is some advice on JVM tuning in there. Here is the JVM manual also: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/toc.html

jonahbenton16:02:52

hey @mj_langford: yeah, jvm tuning is a complex topic, and is almost always application-specific. Using Clojure itself isn't a significant factor; the requirements around and implementation of your application logic, management of data, etc, are much more salient considerations

mj_langford16:02:15

I am not a Java programmer, so @jonahbenton, the “right book”/article for JVM tuning is good to find out about as well

mj_langford16:02:27

that t-crayford presentation looks like what I want

jonahbenton16:02:22

@mj_langford: sure- this is a good high level introduction: http://blog.takipi.com/java-performance-tuning-how-to-get-the-most-out-of-your-garbage-collector/ with pointers to other resources. it's best to start simple- give the jvm an appropriate max heap size and tell it to log garbage collection events (described in that post)- and then go ahead and run your app under load and see how things go. if you run into problems that turn out to be memory management/garbage collection related, then the log gives you a starting point for tuning

jonahbenton16:02:45

this is good coverage of some common tweaks: http://blog.sokolenko.me/2014/11/javavm-options-production.html that said, as with all optimization, don't do it prematurely simple_smile

jedi17:02:26

Anybody tested running clojure on node.js on raspbery?

ghadi18:02:21

jedi: check in #C03S1L9DN

rob20:02:07

👋 Has anyone used mesomatic much?

nonrecursive21:02:30

has anyone run into an issue where Transit interprets UTC datetimes as local datetimes?

dm321:02:03

how do you figure it interprets them as local?

nonrecursive21:02:31

on the backend they’re read as midnight UTC, frontend I get 5am UTC

dm321:02:47

what do you give to transit? a java.util.Date?

dm321:02:45

if it points to the midnight instant, the serialization shouldn't be messing with that

dm321:02:04

so I suspect would check the presentation

dm321:02:45

is your local timezone UTC+5?

yogidevbear21:02:11

Are you sure you're not converting it on the front end to UTC with a JavaScript function or similar?

yogidevbear21:02:44

If so and your local time is different to UTC you'd get similar results

nonrecursive21:02:09

it looks like, for example, the date is being serialized as 1449810000000

nonrecursive21:02:34

and it looks like on the front end when transit deserializes it is defaults to the local timezone, utc+5

nonrecursive21:02:00

there might be something else messing with the date somewhere along the line that I’m not aware of I guess

nonrecursive21:02:15

just wanted to do a quick sanity check to see if anyone else had encountered the same thing simple_smile

pguillebert21:02:59

if the front end is setup as UTC+5 it should give you 5am UTC+5

pguillebert21:02:22

maybe the front says it is UTC when it is not ?

dm321:02:52

more importantly, is it 1449810000000 on the frontend? simple_smile

dm321:02:00

if so, it's just a presentation issue

nonrecursive21:02:39

cool ok so that’s the expected behavior - good to know. I’m inferring that transit does basically new Date(1449810000000), which uses the local time zone and results in the date actually being 5 hours off (not just presenting as 5 hours off)

nonrecursive21:02:42

it’s actually giving me midnight UTC+5

nonrecursive21:02:14

so like on the backend I have the value #inst "2015-12-11T00:00:00.000000000-00:00”. I send it over transit, and after it’s read, I have the value #inst "2015-12-11T05:00:00.000-00:00”

nonrecursive21:02:04

ok it looks like this can be solved by using “json-verbose” for the writer