Fork me on GitHub
#clojure
<
2015-10-06
>
fdserr09:10:08

@mpenet It'd be sensible, yes. Meanwhile (get (atom {}) :foo (throw (Exception. "no :foo here")))

jreedmoore12:10:31

Are there good/tolerable ways to roundtrip a java object exposing a bean interface in/out of Clojure?

jreedmoore12:10:56

I'm trying to write comprehensible tests of some javabean heavy code in clojure so I can express everything as maps

djljr13:10:45

are others here seeing a timeout error when going to https://clojuredocs.org/ ?

roberto13:10:12

hi, is clojuredocs down for everyone?

samueldev13:10:23

damnit I am trying to read up on defn-!

roberto13:10:15

nice, thank you. Was using Dash in the absence of clojuredocs.

andrea.crotti13:10:20

is there a way to know if a library supports clojurescript as well when installing it?

akiva13:10:26

Not that I’m aware of. You have to look at the documentation and/or source.

andrea.crotti13:10:00

@akiva: but where would I look in the code?

akiva13:10:15

Most everything’s on GitHub.

akiva13:10:13

Well, ClojureScript stuff is going to be in cljs or intermixed with Clojure in cljx files.

akiva13:10:44

Sorry not cljx. cljc.

andrea.crotti13:10:12

ah ok yes good point

andrea.crotti13:10:22

easy to find out then

andrea.crotti13:10:57

and to try to contribute and see if it works I just have to convert it to cljc, change a few things and see if the tests are still passing right?

andrea.crotti13:10:08

I guess many libraries would work straight away

akiva13:10:33

Actually, it’s a bit more of a challenge than that. Java and JavaScript although similar in syntax are wildly different beasts.

akiva13:10:46

There are things JavaScript simply doesn’t support. But it’s made much easier to coerce existing Clojure libraries to ClojureScript through the Reader Conditionals.

andrea.crotti13:10:07

I mean if at least there is no Java interop it's already a good start I supopse

danmidwood14:10:09

Hey group, if I have a structure like this:

[{:some-keys 1, :plans [{:id "asdds1"} {:id "asdfa2"}]}
 {:some-keys 2, :plans [{:id "asdf3"} {:id "2313124"}]}]
Is there a better way to get a flat list of the :id values than running (flatten (map (comp (partial map :id) :plans) structure))?

akiva14:10:59

(mapcat (comp (partial map :id) :plans) structure)

kvlt14:10:33

Hey all. I am currently using futures to handle fns that only need to be done and not within the context of the fn that is spawning them. Recently the need to handle exceptions in those threads has risen. Is there a reason I would want to use core.async to do these jobs. The alternative is to write my own future macro and wrap the body in a try catch. Any insight is appreciated.

akiva14:10:27

I’ve handled exceptions in a future before. As far as I understand it, it’s required when you want to cancel a future that’s currently in Thread/sleep.

akiva14:10:44

But handling it through core.async seems reasonable.

kvlt14:10:16

akiva: is there a reason why you would favour one over the other?

akiva14:10:34

If the exception has to be handled outside of the future, then I’d go with core.async. In my case, the exception is handled within the future itself and doesn’t bubble up at all.

kvlt15:10:03

is there a limit to the number of futures you can spawn? Are futures spawned from a thread-pool?

nberger15:10:59

@andrea.crotti: you'll have to refactor the assert-with-message macro, because it tries to create an AssertionError which doesn't exist in cljs. I mean refactor and not just introduce a reader conditional because that doesn't work as you would expect inside of a macro (because macro is compiled in clj, not cljs). https://github.com/clojure/math.combinatorics/blob/master/src/main/clojure/clojure/math/combinatorics.clj#L91-L96

nberger15:10:31

Extracting a fn to introduce the reader conditional there would make it work. Or better yet, remove it altogether... it's there for compatibility with Clojure 1.2, but if you are going for reader conditionals, you'll be in 1.7 at the very least simple_smile

donaldball15:10:18

@petr IIRC future uses a single cached thread pool, so will ask the jvm for new threads as needed

kvlt15:10:14

@donaldball: can you think of a reason why I would use core.async to catch unexpected exceptions in asynchronous processes rather than just doing this? https://www.refheap.com/110334

donaldball15:10:59

Not really. core.async is a useful tool when you need back pressure or efficient selection across queues, it doesn’t seem germane to this use case.

dviramontes15:10:42

Hello! any example tutorials of how to setup a clojure / clojurescript in the same Leiningen project ? ~ Full stack clojure i found this: http://www.clojured.com/ but not sure how relevant it is / isn't ... Thanks!

nberger15:10:43

@dviramontes: I think it's not the best idea to post on both #C03S1KBA2 & #C03S1L9DN at the same time. If you think you are not getting attention in one channel, you could post on the other but pointing to the first one... just to consolidate efforts of ppl trying to help

cddr16:10:47

Has anyone installed yeller recently? When I add it as a dependency to an existing figwheel project (without adding any more code to actually integrate it), I get this stacktrace: https://gist.github.com/cddr/860fb9872f7847dffce7

agile_geek16:10:50

@cddr: Might be worth asking @tcrayford

shaun-mahood17:10:13

Has anyone used Auth0 with Clojure? Looking for some hints as far as the best way to get started.

cddr17:10:59

We use auth0. We use ha-proxy to route all requests through an app called "auth-proxy" that gets user info from auth-0 and passes the request along to the destination app

shaun-mahood17:10:02

@cddr: Is all the communication with Auth0 done from Clojure?

shaun-mahood17:10:06

@cddr: Any hints as to a good way to get started with it? I want to get it integrated into a compojure app, so am taking a look at ring-gatekeeper, buddy, and friend right now to see what makes the most sense.

cddr17:10:30

Yeah we use ring-gatekeeper.

cddr17:10:30

Not sure it has the best design though. If I was to start again, I'd probably try to integrate with friend

shaun-mahood17:10:29

Ok thanks - I've been looking at gatekeeper a bit and I'm glad it at least works for you, probably going to see about getting it to work with friend or buddy if I can figure it out.

shaun-mahood17:10:46

Nice to have a good basic thing to start with though.

cddr17:10:27

Cool. Ping me when you have something. I'd be interested in checking it out

shaun-mahood17:10:37

Will do, thanks

meikemertsch17:10:41

@danmidwood: I just tried out specter. I use it to parse a deeply nested data structure that I get while testing our API. It proved useful so far although I know it's controversal. You call would look something like (select [:plans ALL :id] structure)

danmidwood17:10:59

Oh, that looks like just what I was looking for. Why is it controversial? Too opaque?

meikemertsch17:10:52

I'm still green behind the ears. What I understood is that it's really about building and handling big deeply nested data structures. So Specter eases a pain that maybe shouldn't be eased. On the other hand it's pretty useful. Also it's claims to be 'Clojure's missing piece' isn't received only well. I guess it depends on ehat you're trying to do. I suggest you look into it and judge for your own case :)

meikemertsch17:10:27

Sorry 'its claims' of course

meikemertsch17:10:05

I heard that it's not sufficient for everyone to only have the readme. Additional explanations can be helpful

hlship17:10:36

@tel Uberjarring will not cause a problem with Rook, since it's just about packaging things up in one jar that would normally be multiple jars.

hlship17:10:18

On the other hand, there's an AOT issue wherein namespace metadata is lost during an AOT compile; so if you are combining AOT with Uberjar, just make sure your Rook endpoint namespaces are left as source, not AOT compiled.

hlship18:10:04

That usually isn't a problem, as those namespaces are referenced by symbol name only (in the call to io.aviso.rook/namespace-handler) and so there's no reason for the AOT compiler to normally visit and compile those namespaces.

tel18:10:16

@hlship gotcha, thanks! I fixed the problem but I’m worried it’s a heisenbug 😕

hlship18:10:22

I hope to be doing more work on documentation & examples for Rook & etc. if and when we start using them here at WalmartLabs.

ajmagnifico20:10:41

What is the "right" way to create a helper function that returns a lazy seq from a parser that consumes an input stream"

ajmagnifico20:10:22

The problem with this function is that it closes the streams as soon as it has handed off the iterator.

ajmagnifico20:10:30

It makes sense.

ajmagnifico20:10:57

But is there a way to create a small utility function to create the Lazy Seq

ajmagnifico20:10:07

AND guarantee that the streams get closed at an appropriate time?

ghadi20:10:23

ajmagnifico: that sort of resource handling is dynamically scoped.

ghadi20:10:00

you must use the stream while it's open

ghadi20:10:11

you can always do (with-open [...] (do-whatever-processing (line-seq rdr)) and have the function consume eagerly

ghadi20:10:51

Note, if you have something Iterable (like the parser), you can just call seq on it, and let clojure protocols do the heavy lifting. (no need to call .iterator/iterator-seq)

Ivan Fedorov22:10:40

Can anybody check me on base64 decoding in Clojure? I have an XML file with inline base64 resources (Evernote's ".enex"), and I fail to decode them. So I copied and pasted one of the resources into separate file (https://gist.github.com/ognivo/e3a20dee52b5abb70830), and tried to decode it using clojure.data.base64/decoding-transfer. It does create a new file (smaller in size), but it won't open in image viewer. I tried to check the base64 string itself using the link http://www.askapache.com/online-tools/base64-image-converter/, and it converted the file fine -- a jellyfish displayed.

Ivan Fedorov22:10:08

BEWARE: the base64 source is 10+ k lines long.

ghadi22:10:55

ognivo: you on JDK 1.8?

ghadi22:10:13

you can use java.util.Base64

ghadi22:10:22

(let [decoder (java.util.Base64/getDecoder)] (-> (.wrap decoder your-input-stream) slurp))

ghadi22:10:29

something like that, didn't try it

ajmagnifico22:10:05

@ghadi: thanks for the (seq parser) tip!

ajmagnifico22:10:14

Here's what I ended up with:

ajmagnifico22:10:10

I used lazy-seq. It closes the resources when it gets to the end of the sequence

ghadi22:10:24

Honest feedback: that will be brittle

ghadi22:10:40

If some part of your program doesn't use the whole seq, it doesn't get closed

ghadi22:10:56

(There is another way I've not mentioned, yet)

ghadi22:10:41

If you have just one file that your processing, the simplest thing to do is to pass a function into something that will open, then call the function on the line-seq, and then close, all using with-open

ajmagnifico22:10:15

right, that makes sense

ajmagnifico22:10:26

I need to think about my use case a little bit more

ghadi22:10:35

A more advanced way to do it, is to make a "reducer"

ghadi22:10:49

Kevin downey has a great post on that somewhere

ghadi22:10:46

Here is an example of a reducer for file lines https://gist.github.com/ghadishayban/94ba17c2c177007f62ad

Ivan Fedorov22:10:00

ghadi: thanks a lot, that worked. I used java.util.Base64/getMimeDecoder, because standard getDecoder finds restricted symbol d and dies.

ghadi22:10:52

ajmagnifico: But with-open should do the trick, you just have to be conscious about using the whole sequence eagerly. (Add (into []) at the end of your pipeline, or use reduce)

ajmagnifico22:10:44

@ghadi: I think you're right. I'm going to have to just wrap everything in with-open and consume eagerly. Thanks for your help!