Fork me on GitHub
#clojure
<
2019-01-26
>
devn04:01:52

@noisesmith thanks for your answer earlier.

Mikko Nylén09:01:28

I'm building a Clojure wrapper for a Java library and I'm wondering how I should add a dependency on that library from my wrapper. The thing is the Java library depends on a Java Agent JAR of the same version to provide the implementation through instrumentation. The library's public api is likely to stay the same, so my wrapper should work with any version of the library, but a specific library version can work with only specific version of the java agent. What are the possible approaches here? Adding direct dependency to the Java library from my wrapper would work as long as the user goes with the same Java Agent version, but would likely break in the future when new agent versions are released. Of course, then users could exclude the library dependency and provide their own. Or I could release a new version of the wrapper for every library/agent version, but this might prove to be too much maintenance work. Currently I'm thinking of going with adding the library dependency as 'provided', i.e. when including a dependency to my wrapper, users would also need to download the Java Agent (anyway required) and then add another dependency to the library. Any other ideas - preferably ones that don't require a ton of maintenance?

seancorfield10:01:10

@mikko273 Sounds like New Relic?

seancorfield10:01:10

We have a wrapper for that internally, and we assume the caller provides both the library and the agent and keeps them in sync. I think that's really the only sane approach here.

Mikko Nylén10:01:10

It's actually Elastic APM. Yeah, I guess it's the sanest approach to have the user provide both.

Mikko Nylén10:01:25

Btw, have you noticed this New Relic Clojure wrapper: https://github.com/Yleisradio/new-reliquary

seancorfield22:01:59

I had not. Thank you. It doesn't look as sophisticated as to what we're already doing (we have tracing via annotations, a bunch of metrics stuff, support for the New Relic Agent and periodic probe/reporting, middleware, and transactions).

seancorfield22:01:47

Maybe at some point I'll extract ours as an open source project...

Mikko Nylén14:01:13

That'd be cool 🙂 Yeah, it's not very sophisticated, but works for basic needs.

Marc O'Morain10:01:50

Can someone help me find the docs for sorted maps please? The docs at https://clojure.org/reference/data_structures mention them, and say that they “are, well, sorted”. I want to know how they are sorted - by key, value, insertion order, etc.

Marc O'Morain10:01:16

I think the flatland ordered meal does what I need (I want to maintain insertion order). But my question is about the docs - I don’t see any mention of how a map is sorted if no comparator is supplied.

Marc O'Morain10:01:53

Nor mention of what the comparator should return. Or what args are passed to the comparator.

Mikko Nylén11:01:35

I think it's ascending order by key by default. The args are a and b - i.e. the objects to compare.

souenzzo11:01:08

@marc-omorain comparator is a java concept. It returns -1, 0 or 1. To keep insertion order, you should use a specific lib called "orders"

Marc O'Morain11:01:05

Thanks for the help. To be clear though, I’m wondering if there are docs on this.

andy.fingerhut18:01:47

Clojure's default comparator, if you do not supply one explicitly, is clojure.core/compare

andy.fingerhut18:01:06

There is the output of (doc compare) that describes it briefly.

andy.fingerhut18:01:17

I haven't yet found any explicit lines in doc strings saying that, but in brief checking of source code it appears to be true.

andy.fingerhut19:01:27

I have written something a few years back, but not published in a well-known place, necessarily: https://github.com/jafingerhut/thalia/blob/master/doc/project-docs/en_US/clojure.core/1.6.0/clojure.core/compare.md

andy.fingerhut19:01:45

I am considering copying that to http://ClojureDocs.org page on the behavior of clojure.core/compare

andy.fingerhut09:01:00

I should have pointed you here first -- it does explicitly document that compare is the default comparator, and has some notes on its behavior: https://clojure.org/guides/comparators

andy.fingerhut19:01:16

Continuing with my hopefully brief obsession, I have just updated the sorted-map entry on http://ClojureDocs.org to make the answers to some of your questions hopefully quick to answer: http://clojuredocs.org/clojure.core/sorted-map

Mikko Nylén11:01:27

I can't find anything comprehensive. 😞 There's this: https://clojure.org/guides/learn/hashed_colls#_sorted_maps which gives tiny bit insight on the default comparator at least.

Dormo13:01:09

Anyone have any examples of idiomatic Clojure libraries that wrap external APIs?

Marc O'Morain13:01:32

The new cognitect AWS wrapper?

danielstockton17:01:40

Can anyone suggest a way to take screenshots of a webpage in clojure/java? I'm looking for the simplest solution possible, preferably with no extra dependencies.

joshkh17:01:25

not exactly what you're asking for, but is clojurescript a possibility? https://github.com/niklasvh/html2canvas

danielstockton17:01:11

I've tried that with poor results (compared to how things actually look in a real browser).

mpenet20:01:53

If you're open to using an external service http://urlbox.io is quite good. We've snapshoted pages with some crazy js/svg and all sorts of constraints (timers etc) with it

victorb17:01:31

@danielstockton I think the JavaFX WebView has a takeSnapshot or snapshot function you can use

danielstockton17:01:29

Thanks, I'll take a look at that 👍

Mikko Nylén19:01:21

@danielstockton If you're open to using external paid service, I would recommend url2png. It works pretty well and has some nice features, such as it allowing you to include custom css file just for screenshotting purposes. For a DIY solution, I'd probably go with something like headless chrome to get as close to desktop/mobile rendering as possible.