Fork me on GitHub
#beginners
<
2017-06-21
>
jlmr09:06:39

I think I'm close to completing my first "microservice" in clojure. It works fine when using lein run: a small server using ring-jetty starts and accepts requests and gives back the responses I expect. However when I try to compile using lein uberjar it seems to start up the service but then hangs and never finishes the compilation. I have a feeling it might have something to do with core.async channels that I use. Could that indeed be the case?

noisesmith16:06:14

jlmr: the typical cause of this behavior is top level side effects, including side effects inside def

noisesmith16:06:44

clojure doesn’t have a “compile only mode” - when it aot compiles to make your uberjar, the namespace is run exactly the way it would be if you require it

noisesmith16:06:22

which means that to use uberjar correctly, especially with aot, you need to ensure that any stateful top level objects are initialized inside your -main or something it calls

jlmr06:06:34

@U051SS2EU, ok this gives me somehting to work on then. Will look at it tomorrow. Thanks!

sb10:06:59

Hello, I try ask to others again about how convert URL content -> image with clojure? I tried with io/input-stream but in this case I get the source code. How can I get the pic of the website like a screenshot?

sb10:06:47

I saw solution what can work with Electron app (desktop screenshot), but I can’t modify to linux server use for other urls. Any idea? Without PhantomJS?

sb10:06:40

@dominicm Thanks for the links! I think, that is a little bit harder than I thought without PhantomJS.

novel17:06:31

Hi, I have "almost" no idea about Java and I try to get the Java Classes get running via Interop: https://github.com/CogComp/cogcomp-nlp/blob/master/chunker/src/main/java/edu/illinois/cs/cogcomp/chunker/main/ChunkerDemo.java so far I tried the following, but I'am doing something stupidly wrong

novel17:06:15

I'd appreciate any help

carly17:06:23

@novel have you tried removing the spaces between the . and the function? (def annotator (.CuratorFactory buildCuratorClient))

novel17:06:27

yes, without the space it gives me "Unable to resolve symbol: createBasicTextAnnotation in this context"

novel17:06:39

and with the space I get a timeout

noisesmith17:06:55

the idiomatic translation of (. CuratorFactory buildCuratorClient) is (CuratorFactory/buildCuratorClient) but they both do the same thing https://clojure.org/reference/java_interop

manu17:06:36

Hi! I need to import

CardStackStyleInterpolator
from
'react-navigation/src/views/CardStackStyleInterpolator'
as described in this issue https://github.com/react-community/react-navigation/issues/1400. How I can do? Thanks 🙂

noisesmith17:06:18

@novel is it definitely hanging on the definition of annotator?

noisesmith17:06:34

I could suggest more if I could find an actual javadoc for this project

novel17:06:46

ah sorry, this is the right pointer to the javadoc

noisesmith17:06:10

that first call that defines annotator should just work if the docs are correct

novel17:06:06

so changing to (ClusterFactory/buildCuratorClient) with (def ta (. annotator createBasicTextAnnotation "corpus", "id", "text")) call to method createBasicTextAnnotation can't be resolved (target class is unknown) and (def ta (.annotator createBasicTextAnnotation "corpus", "id", "text")) times out with "Unable to resolve symbol: createBasicTextAnnotation in this context"

noisesmith17:06:01

well that’s not a time out, but OK

noisesmith17:06:20

it’s not .annotator

noisesmith17:06:22

you can either use (. annotator createBasicTextAnnotation ...) or (.createBasicTextAnnotation annotator …), they both mean the same thing but the latter is preferred

noisesmith17:06:29

removing the space there changes the meaning

novel17:06:54

ah but with the space it cannot call the method createBasicTextAnnotation

noisesmith18:06:16

are you doing this in a repl? if not I suggest working that way, checking what the class of annotator is

novel18:06:26

so bean annotator gives this

noisesmith18:06:49

what does (.createBasicTextAnnotation annotator "corpus" "id" "text") do?

novel18:06:58

it should annotate the string "text" with part-of-speeches

noisesmith18:06:37

I meant, what happens when you try to make that call after defining annotator

noisesmith18:06:42

same result?

novel18:06:53

same result 😞

noisesmith19:06:36

there are many ways to do it, I kind of like #(reduce (comp inc first list) 0 %) if just using count isn’t allowed

noisesmith19:06:11

with (fn [x y] (inc x)) maybe being a better way to write (comp inc first list)

vitruvia19:06:54

thanks, I was actually trying to do something with reduce but I hadn't much success

eriktjacobsen20:06:24

(reduce (fn [cnt _] (inc cnt)) 0 sequence)

ysgard20:06:15

Hey all, I'm a newbie and just trying to find my footing. I was playing around with the repl, and read about find-doc and apropos. Seems pretty cool… but maybe I'm just using this wrong.

user=> (find-doc "sin")
...
<massive wall of text>
...
user=> (find-doc "Math/sin")
nil
user=> (apropos "sin")
(clj-antlr.interpreted/singlethreaded-parser
 instaparse.cfg/single-quoted-regexp
 instaparse.cfg/single-quoted-string
 instaparse.reduction/singleton?)
user=> (apropos "Math/sin")
()
user=> (Math/sin 90)
0.8939966636005579
Does sin have a docstring? Why isn't it showing up in apropos?

aengelberg20:06:57

@ysgard: sin is a static method on the Java class java.lang.Math. I think the function apropos only searches Clojure namespaces and their docstrings, not Java classes and their Javadocs.

ysgard20:06:21

Ah, I see - thank you @aengelberg! Seeing as how Clojure leans on Java's std lib a lot, is there any way to access the associated java doc from the repl?

ysgard20:06:53

I dimly remember a note about this in the Joy of Clojure, but I'm having difficulty finding it now

ysgard20:06:03

Should have taken notes on that damnit

aengelberg20:06:20

That’s a good question. I don’t know of an easy way to do that. Clojure docs are generally represented as strings, stored as metadata on the functions, and they’re accessible from Clojure at runtime, which is what enables helpful functions like apropos and doc. Javadocs are just comments in the source code, that get produced into HTML as a compile-time step, but I think that documentation gets compiled away and isn’t stored the actual JVM.

ysgard20:06:51

The note I saw in Joy of Clojure mentioned a function that would return a URL to the javadoc page.

aengelberg20:06:03

That said, one could probably use reflection to search all of the classes and do a search based on just method-names.

aengelberg20:06:24

But this is probably an overly complex theoretical discussion for the #beginners channel. 😛

ysgard20:06:40

Oh I was mistaken, it wasn't in Joy of Clojure, but CIDER: cider-javadoc

alexmiller21:06:29

you can also access javadocs from the repl using clojure.java.javadoc/javadoc

alexmiller21:06:50

(use 'clojure.java.javadoc)
(javadoc Math)

guy21:06:19

nice tip!

ysgard21:06:29

Thank you Alex! 🙌

noisesmith21:06:24

for style points you could suggest > check out the output of (apropos “javadoc”)