Fork me on GitHub
#clojure
<
2015-08-07
>
ballpark00:08:15

is there a simple way to create an inputstream from a string?

potetm00:08:49

(ByteArrayInputStream. (.getBytes "Testing”)) is the only one I know off the top of my head.

potetm00:08:16

Though every time I do that, I think “there’s got to be a better way”.

ballpark00:08:50

I agree. I've spent too much time looking. Thanks for the help!

potetm01:08:54

@ballpark: I would like to amend that recommendation to (ByteArrayInputStream. (.getBytes "Testing" StandardCharsets/UTF_8)). Out of the box it uses whatever your system default charset is, which is probably UTF-8, but not guaranteed.

potetm01:08:32

And, not to be too religious, but you want UTF-8: http://utf8everywhere.org/

ballpark01:08:28

got it. Thanks!

martin.hynar07:08:18

Hi, any core.cache user here? I just wanted to make use of this lib and found out that it does throw exception on the minimal example shown on github. With clojure 1.7.0 it throws exception (reported in CCACHE-41) but I found no indication that it should not work with 1.6.0. But to my disappointment, I get " Unable to convert: class clojure.core.cache.FIFOCache to Object[]".

gmorpheme09:08:33

@ballpark: I think with https://github.com/ztellman/byte-streams, (to-input-stream “Testing”) should work? utf8 is the default

cfleming11:08:43

Am I correct in thinking that local lein repos (using file:// protocol) don't check the .m2 cache?

cfleming11:08:09

Actually, I’m not even sure that makes sense. Here’s a better question: when lein (or Maven/Aether) is resolving a dep, what is the order it checks? .m2, then the repos in order as defined in project.clj/:repositories?

ragge11:08:19

@martin.hynar: we use core.cache in a few places with both 1.6 and 1.7, haven't seen that issue

ragge11:08:38

@martin.hynar: which code specifically are you running?

tcrawley12:08:13

@cfleming: howdy! I'm not positive, but I'm pretty sure it checks .m2, then the repos in order, as you said. I don't think it would make sense otherwise, since .m2 is a cache

ragge12:08:47

@martin.hynar: the example works fine for me on 1.7:

user=>  (require '[clojure.core.cache :as cache])
nil
user=>  (def C (cache/fifo-cache-factory {:a 1, :b 2}))
#'user/C
user=> C
{:a 1, :b 2}
user=> (if (cache/has? C :c)
  #_=>       (cache/hit C :c)
  #_=>       (cache/miss C :c 42))
{:a 1, :b 2, :c 42}
user=> (cache/evict C :b)
{:a 1}

martin.hynar12:08:07

@ragge: Exactly the same as you pasted in. Found out, that only 0.6.4 suffers with that, tried to downgrade to 0.6.3 and no such problem appears (no matter what version of Clojure I use). What version of core.cached are you using?

ragge12:08:26

@martin.hynar: the project I was looking at is actually using 0.6.4

bronsa12:08:37

@martin.hynar: just tried that with 0.6.4 and clj 1.8.0-alpha4, works fine

ragge12:08:20

@martin.hynar: might be worth checking if you have some aot compiled classfiles laying around...

ragge12:08:40

@martin.hynar: rm -rf target/ is a good start simple_smile

martin.hynar12:08:18

I dont want to believe that, removing target did the trick.

ragge12:08:42

often does simple_smile

ragge12:08:21

quite easy to end up with a classfile on disk that is different to what you want

ragge12:08:38

did you maybe have 0.6.3 stuff aot compiled, then upgrade to 0.6.4? that would explain why reverting to 0.6.3 worked again

martin.hynar12:08:21

no, I created lein new app and added core.cache 0.6.4 dependency. Then started repl and copied the example.

cfleming13:08:27

@tcrawley: Right, I think that’s the only thing that makes sense.

cfleming13:08:58

This is all part of my plan to put lein in a box with ShimDandy

afhammad13:08:51

Any templates out there for new projects using Component with either compojure/pedestal?

cfleming13:08:14

@tcrawley: Actually, I’m wondering if that’s right. I suspect it goes through the repos one by one, and for remote repos checks the cache and then the repo - I think for local repos it probably doesn’t check the cache.

cfleming13:08:29

I don’t know how to test that or where to find doc about it, though.

sveri13:08:50

afhammad: Actually I um using system, which is a small wrapper on component. However, the component definitions should be the same

sveri14:08:18

afhammad: you can find the handler component, which loads the compojure routes, here: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/handler.clj

afhammad14:08:54

sveri: thanks

sveri14:08:05

afhammad: np, if you have any questions, just go ahead

blueberry14:08:45

I have just released 0.2.0 version of ClojureCL, a ClojureCL library for GPU high-performance computing. http://clojurecl.uncomplicate.org

blueberry15:08:51

Aaaand, I've also released new version 0.3.0 of Neanderthal, with an GPU engine for Matrix computations

blueberry15:08:10

tutorial and discussion on the following link: https://news.ycombinator.com/item?id=10022776

ballpark15:08:01

Anyone have any experience hooking up the stuartsierra component library with the ring init hook? I would like for this to work so I can do hot deployments to a container (I'm using tomcat).

akiel16:08:43

what is a good graph lib in clojure with dijkstra?

danielpcox16:08:55

I'm getting a "GC overhead limit exceeded" error while trying to load a rather large (~500Mb) CSV file into a map. Does anyone know why this is happening, and what I might be able to do about it? Here's the offending code, which I realize is a bit naive, but I did expect it to work: (->> (:path-to-csv-file conf) (slurp) (s/trim-newline) (clojure-csv/parse-csv) (map #(vector (first %) (json/read-str (second %) :key-fn keyword))) (into {}))

bensu16:08:37

does anybody have an example of a Java library they would like to use but can't because it has an API that doesn't play along with Clojure semantics?

stuartsierra16:08:50

@danielpcox: Well, to start with, slurp is going to read the entire 500 MB file into memory. That's probably a problem right there.

alexmiller16:08:13

and then trim-newline will copy it

jeffmk16:08:34

@danielpcox: Throw more RAM at it, or use https://github.com/clojure/data.csv/ and process it lazily

jeffmk16:08:44

Anyone have any better options to parsing (simple, sane) XML into a vectors/maps, other than using zippers and xml-seq? It seems like this is on the right track, but it’d be nice to have something with a bit better “DSL”: https://github.com/thebusby/into-edn

jeffmk16:08:59

It’s decent but seems very boilerplatey when you get to 10+ XML templates, a bit tedious. It may be that a lot of the ugliness can be macro’d away.

danielpcox16:08:06

thanks @stuartsierra and @jeffmk, I do have memory to spare here, so loading 500Mb is only ugly, not damaging. it doesn't seem to be running out of RAM, but when I googled the error it said that if GC is taking 99% of the total CPU used and recovers less than 2% of the heap, then it's assumed to be making no progress and this OutOfMemoryError is thrown. Someone did suggest increasing the heap size, so perhaps that's all I need to do. This is old software of mine, and I can't actually remember why I'm using clojure-csv instead of data.csv...

danielpcox16:08:38

actually, I think the reason I didn't use data.csv was because it didn't seem to support appending to a CSV file, which I needed for this application

stuartsierra17:08:17

@danielpcox: data.csv operates in terms of a java.io.Writer, so appending to an existing file should depend only on opening the file in "append" mode.

jeffmk17:08:39

FWIW I found an obscure library that does quite a nice conversion of XML->Clojure maps/vectors. https://github.com/cpoile/x2j/tree/cpoile

jeffmk17:08:31

(x2j/xml-to-clj "<book><title>Clojure for Idiots</title><author>Me</author></book>”) => {:book {:author "Me", :title “Clojure for Idiots”}}

cddr18:08:16

Am I correct in my thinking that you can't do (map (partial recur ...) some-seq) because then recur is not in the tail position?

edw18:08:48

Is it an acknowledged poor design decision to have the value of a ring param be either a vector or a single value depending on the number of params present?

cddr18:08:53

So if you need to map across the seq and recur, you need to either rearrange the algorithm, or just settle for non-tail-recursive calls