Fork me on GitHub
#clojure
<
2016-02-19
>
samlinncon08:02:16

how do i include a java gateway class into my clojure project?

hans10:02:07

@samlinncon: look for leiningen's :java-source-path option

hans10:02:08

@samlinncon: :javac-options may also be useful. just decide where you put your java sources, define the source path (and jvm options, if needed) in your project.clj, done.

samlinncon11:02:39

okay,i need to include an external java file in my project

jbaiter12:02:32

do the threading macros produce lazy seqs?

jbaiter12:02:46

somehow my google-fu fails me

jbaiter12:02:01

ouch, nevermind, that question is nonsense simple_smile

marcosmatos12:02:22

hi folks! I am asking this before doing any research, so sorry for being lazy. Do you know if there is any http client lib that respects the http cache headers like a browser would?

jbaiter12:02:35

I don't know i f there is a clojure library that wraps it, but apache httpcomponents has this: https://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html

jbaiter12:02:49

should be fairly straightforward to call into that from clojure

george.w.singer12:02:42

Random question: does a call to (om.next/class->any reconciler SomeClass) generate a n anonymous instance of a component SomeClass on the fly, or does it return an actual, matching instance in your application?

george.w.singer12:02:16

Woops wrong room simple_smile

george.w.singer12:02:23

Meant for #C06DT2YSY

jonahbenton14:02:07

hey @marcosmatos @jbaiter the excellent https://github.com/dakrone/clj-http is clojure's wrapper for the apache http components project

marcosmatos14:02:25

Ha, I am looking right now at the clj-http code, it doesn't say anything about cache on the docs

marcosmatos14:02:26

thanks for the tip =D

jonahbenton14:02:58

yeah- you have to setup your own cache, but incorporating that cache should not be difficult. see https://github.com/dakrone/clj-http/issues/129

jonahbenton14:02:22

see core.cache for a suitable in-memory cache https://github.com/clojure/core.cache

marcosmatos14:02:42

clojure core.* libs are full of surprises, I didn't know about core.cache

roberto14:02:06

is there a way to tell prismatic schema that I only want clojure not clojurescript? We are using it on a non cljs script app, but it schema downloads google closure and we don’t want that in prod.

jonahbenton14:02:11

hey @roberto schema seems to be packaged in part as cljx files, a clj/cljs solution that preceded the reader conditionals approach introduced in 1.7. you may be able to produce a clj-only artifact for inclusion in your app by examining the https://github.com/lynaghk/cljx workflow

jbaiter14:02:39

on a related note, is there a way to make one field in a schema depend on another? say I have a field that is a set of strings, and another field that is a string. I would like to verify at runtime that the string-field has a value that is in the set-field

jonahbenton14:02:01

treat the set as an enum?

bjr15:02:10

Does anyone know how to create test fixtures which selectively apply to test vars in a namespace? Ideally something like (use-fixtures :each :functional test-system-fixture) to only run that fixture on tests with :functional true in the test var metadata. This is to avoid creating separate namespaces for separate fixtures. I know leiningen retains fixtures when it does test filtering by selectors — but i’m actually looking for something like the inverse where all tests are run, but the fixture only applies to a subset. Selectively applying fixtures instead of selectively executing tests which have fixtures.

Lambda/Sierra15:02:21

@bjr Fixtures can't do that, but you can make a macro or function and call it in each test that needs it.

bjr15:02:08

@stuartsierra: Right, but that reintroduces the repetition fixtures are so good at removing.

Lambda/Sierra15:02:24

Is it really that different from repeating the metadata on each test?

bjr15:02:42

No, it’s really not a big deal.

triss15:02:02

hey all... is there a good free platform for hosting clojure on that provides a database backend?

triss15:02:11

should I be looking at heroku or something?

bjr15:02:15

I just feel it would complement test selectors very well if fixtures could do that.

bjr15:02:05

and I see monkey patching clojure.test to add this goes deeper into refactoring test discovery and execution than i’d like to go

Lambda/Sierra15:02:12

I wrote clojure.test, but in retrospect I think "fixtures" were a mistake.

bjr15:02:35

That’s interesting. How so?

codefinger15:02:55

@triss Heroku has a free offering and a free database plan. Here's a guide https://devcenter.heroku.com/articles/getting-started-with-clojure#introduction

Lambda/Sierra15:02:29

"Fixtures" don't do anything you can't do with functions/macros. And they can lead to implicitly shared state across tests.

Lambda/Sierra15:02:29

Tying fixtures to namespaces was a mistake, too. The boundaries don't line up well. E.g. sometimes you want a "fixture" in many namespaces, sometimes only on some tests in a namespace, as in your case @bjr.

bjr15:02:26

Yeah. I suppose there is this rabbit hole of functionality that could be added, but in the end, it can never be more expressive or as simple as writing your own functions or macros to do the exact same thing.

bjr15:02:16

Well then. I guess it’s time to write some ‘fixture’ macros — they’re probably even going to be the same amount of code as the fixture fns I already have. Thanks @stuartsierra .

Lambda/Sierra15:02:26

You're welcome simple_smile

martinklepsch16:02:43

so I'm using a core.async using database client (https://github.com/apa512/clj-rethinkdb/blob/44d4023937d5944a8a454b173204943aa20f6227/src/rethinkdb/net.clj) and as soon as I create as many connections as the core.async excutor has threads closing any connection just blocks forever on a <!! line (https://github.com/apa512/clj-rethinkdb/blob/44d4023937d5944a8a454b173204943aa20f6227/src/rethinkdb/net.clj#L95)

martinklepsch16:02:21

is there some simple way of avoiding this or is this to be considered a bug in the DB client?

Lambda/Sierra16:02:22

Without looking at the code, sounds like a bug to me.

martinklepsch17:02:27

(async/go-loop []
  (when-let [query (async/<! send-chan)]
    (log/trace "Sending raw query %s")
    (write-query out query)
    (recur))))
This is the go-loop given to the <!!send-chan is closed before the <!! call... looks reasonable to me

martinklepsch17:02:12

Also if there's some crucial mistake in core.async usage shouldn't that show up earlier (i.e. before there are as many things as executor threads?

ghadi17:02:52

Cursory look: write-query appears to be doing blocking I/O, which is a no-no

Lambda/Sierra17:02:04

And it's missing exception handling.

Lambda/Sierra17:02:19

and trace is missing an argument

ghadi17:02:05

I wouldn't use that library if I were you.

ghadi17:02:33

the core.async usage is suspicious, to say the least.

ghadi17:02:16

sometimes the most "idiomatic" clojure is wrapping the java library

ghadi17:02:52

Sorry, probably not a useful recommendation to you at the moment.

martinklepsch17:02:57

New on this project, don't want to pull the carpet under a running thing I don't yet fully understand

ghadi17:02:10

yeah, understood

martinklepsch17:02:13

But yeah, I'd equally prefer just some dull wrappers around the Java API

ghadi17:02:48

You could be a good boyscout and fix the library.

martinklepsch17:02:16

For now that's what I'll do I guess (or at least I'll try to 😉 )

ghadi17:02:33

Removing core.async isn't an entirely bad idea.

ghadi17:02:07

but again, i didn't look too closely at the lib

martinklepsch17:02:26

yeah, still in the process of understanding why it was used in the first place. Also there's an in-progress PR of exposing a core.async api as well /cc @danielcompton

martinklepsch17:02:44

@ghadi: why is the blocking-io in the go-block a no-no btw? Isn't that part of the point?

ghadi17:02:00

blocking/suspension in go-blocks is managed by the go-block mechanisms. In order to have it be visible, it has to be a channel operation #{alt! alts! <! >!}

ghadi17:02:11

those are the only things that the go-macro understands

ghadi17:02:31

it can't just see arbitrary code and know it needs to be able to suspend there.

ghadi17:02:10

So what happens is that you call some I/O, and it ties up a thread in the go-block thread pool until the I/O completes.

ghadi17:02:45

If you use only channel operations, I've tested >2M go-blocks running.

ghadi17:02:13

I/O needs to be moved and managed explicitly.

tolitius17:02:15

@martinklepsch: (not to steal @ghadi thunder) the idea is in "letting it park": i.e. free up the real OS thread while going doing something, I/O in this case. ideally, an async I/O would be used in a go block where the responses would be put on a channel once they are ready.

ghadi17:02:55

options include doing your i/o in a thread block and interacting with those operations from go-blocks using channels

martinklepsch17:02:44

so basically this (write-query out query) might be better written like this (<! (thread (write-query out query)))

martinklepsch17:02:08

Thanks for your help @ghadi and @tolitius, I guess I'll take a closer look at the Java driver thats available and see if I can get something simpler working based on that.

danielcompton18:02:41

@martinklepsch: I didn't write the core.async connection stuff and would be happy to see it ripped out. The RethinkDB Java driver has just had the first thread safe release, so I'd be happy to have that take over all of the connection handling stuff.

enyert18:02:32

Hey guys! I'm trying to build a REST API with Compojure using the compojure-app default template. My question is: Given this template, what is the best fit for the connection to the database? where to put that code? Im using Monger to manage MongoDB

enyert18:02:04

I just want to avoid the replication of the connect code

shaun-mahood18:02:48

@enyert: Not sure it's the best approach, but so far I've been happy creating a db namespace, putting my connection code into db.core and any queries into db.queries. Makes it easy enough and is easy to change if you find a way you like better in the future.

shaun-mahood18:02:10

http://www.luminusweb.net/docs/database.md has some good ideas that will apply as well

martinklepsch19:02:37

@danielcompton: ah cool. I somehow interpreted that PR as a sign that you like the current approach. If you're interested I'd be open to pairing or similar to get this into a reasonable state.

martinklepsch19:02:38

Alternatively maybe it's also reasonable to just start from scratch and taking the things that are good over (e.g. query mapping) @danielcompton

danielcompton19:02:33

I think/thought (not so sure now) that presenting a core.async interface would be good, but I'm ambivalent on it for connection handling

i3ic19:02:37

Got some free time, looking for a Clojure project to help with. Anyone want average Clojure dev, 1.5yrs exp?

val_waeselynck21:02:43

@i3ic have a look at #C05006WDW

danielcompton21:02:55

@martinklepsch: would be keen to pair on a rewrite

bitsynthesis22:02:42

hey folks. i need to convert from stream processing to batch processing. do you have any advice on clojure or java libraries to use where i can keep adding items to a queue and have a handler fire on a whole accumulated batch when the batch size is reached?

dominicm22:02:50

There is something for that.

dominicm22:02:08

I forget what it is though, sorry.