This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-16
Channels
- # atlanta-clojurians (1)
- # aws (1)
- # beginners (65)
- # boot (4)
- # cider (81)
- # cljs-dev (25)
- # cljsrn (27)
- # clojure (129)
- # clojure-dusseldorf (12)
- # clojure-italy (68)
- # clojure-norway (5)
- # clojure-poland (4)
- # clojure-spec (14)
- # clojure-uk (72)
- # clojurescript (144)
- # code-reviews (19)
- # copenhagen-clojurians (5)
- # cursive (16)
- # datomic (21)
- # editors (1)
- # emacs (15)
- # events (1)
- # figwheel (6)
- # fulcro (54)
- # graphql (1)
- # hoplon (24)
- # jobs (6)
- # jobs-discuss (2)
- # keechma (4)
- # leiningen (6)
- # luminus (17)
- # lumo (2)
- # off-topic (43)
- # onyx (6)
- # pedestal (2)
- # perun (2)
- # portkey (3)
- # re-frame (22)
- # reagent (11)
- # ring-swagger (5)
- # shadow-cljs (46)
- # specter (8)
- # test-check (2)
- # testing (3)
- # vim (16)
- # yada (1)
hmm, this change in Transit CLJ seems to be causing a NPE for me https://github.com/cognitect/transit-clj/blame/5fcd8e421ef7cd2e6240ab39c693ec1b8a34b3d3/src/cognitect/transit.clj#L160 with following code that previously worked just fine:
(let [stream (ByteArrayOutputStream.)]
(t/write (t/writer stream :json) {:wow "such doge"})
(.toString stream (.toString StandardCharsets/UTF_8)))
right, there is an issue about this already https://github.com/cognitect/transit-clj/issues/41
Hello!
Is there a tool to extract a list of environment variables that are being read from our code through calls to @weavejester's environ's env
function? Or maybe even a similar library that allows to specify a documentation string and default values and generates --help
output and possibly *roff / mandoc / CommonMark / MarkDown?
You should check out https://github.com/amperity/envoy
Thanks, @U051TMSBY! That perfectly fits our requirements! 🙂
I am trying to list the doc string with spec for all the functions in a namespace using (map doc (keys (ns-publics 'foo.core)))
. It fails with CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.repl/doc
. Any idea how to list the docstring of all the public functions ?
try something like (doseq [x xs] (doc x))
although not sure that actually works... better to look at the implementation of doc
(`source doc`) and do what it does
Thanks. What is the recommended tool to generate docs like http://clojure.org docs ?
The http://clojure.org docs are made with autodoc
I'm having quite some difficulty figuring out how to combine java.util.zip.GZIPInputStream
with java.io.PushbackReader.
so I can read compressed edn right into a clojure data structure. I'm trying various variations of this:
(defn from-zip-file
[file]
(with-open [in (java.util.zip.GZIPInputStream.
(java.io.PushbackReader.
(
file)))]
(clojure.edn/read in)))
reading directly from (java.io.PushbackReader. (io/reader file))
on non-zipped edn is fine, but I have some gzipped stuff
In Java, Readers are for character data and Streams are for binary data so generally something like the above won’t work.
I know it's something simple but i've been looking at countless examples and none quite do this basic thing
Usually you want to wrap the reader around the stream
isn't my pushbackreader wrapping the input-stream? or do you mean the gzipinputstream? I tried swapping the placement of the gzipinputstream and the pushbackreader also
I think you definitely want a reader on the outside
But I haven’t used the gzip stuff enough to know exactly what you need there
how would I cast/move data from an input stream into a reader? I've tried this also:
(java.io.PushbackReader.
(java.util.zip.GZIPInputStream.
(
file)))
I could throw away the gzip stuff entirely if there is a more clojure-native way of compressing edn. I have half a gig of edn and reading and writing is fine but storage is a problem.
The gzipped write is a 90% reduction in the size of the edn on disk, but I just can't read it back in
I think you’re on the right track
i found this, lol, the comment >Boy, I'm absolutely in love with Java, but this question comes up so often you'd think they'd just figure out that the chaining of streams is somewhat difficult and either make helpers to create various combinations or rethink the whole thing. https://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
looks like this doing it:
(defn gzipped-input-stream->str [input-stream ]
(with-open [out (StringWriter.)]
(IOUtils/copy input-stream out Charsets/UTF_8)
(.toString out)))
(defn from-zip-file
[file]
(with-open [in (java.util.zip.GZIPInputStream.
(
file))]
(clojure.edn/read-string (gzipped-input-stream->str in))))
StandardCharsets/UTF_8 is the standard way
Charsets is probably some kind of apache commons class probably, or guava
StandardCharsets is pure java
secondly
the typical way to resolve byte stream into a charset is to convert input stream to a reader
new InputStreamReader(in, StandardCharsets.UTF_8)
and then use a stream reading variant of the function which is clojure.edn/read
@roklenarcic thanks trying this now. Having trouble resolving StandardCharsets. I'm importing [java.nio.charset.StandardCharsets]
and then using java.nio.charset.StandardCharsets.UTF_8
or also trying StandardCharsets/UTF_8
but it is a class not found
that's core java api
java.nio.charset.StandardCharsets/UTF_8
of course you should move package into import statement
I think you want (:import [java.nio.charset StandardCharsets])
and StandardCharsets/UTF_8
note the missing . in the first one
got it now, was using wrong syntax java.nio.charset.StandardCharsets.UTF_8
my java interop is terrible thanks to no java background
@roklenarcic this is my interpretation of your suggestion
(defn from-zip-file2
[file]
(with-open [in (java.util.zip.GZIPInputStream.
(
file))]
(clojure.edn/read (java.io.InputStreamReader. in java.nio.charset.StandardCharsets/UTF_8))))
right.. I wrote a lot of java, because I assume everyone knows java I guess
that works
at least it should
i'm getting same error as many other variations: java.io.InputStreamReader cannot be cast to java.io.PushbackReader
right... edn expects a pushback readers
just wrap it
(java.io.PushbackReader. (java.io.InputStreamReader. .... ))
you should add class imports
here's an example from a project
(ns myns
(:import ( PushbackReader InputStreamReader)
(java.util.zip GZIPInputStream)
(java.nio.charset StandardCharsets)))
then you can just use the class names
it appears my original implementation using read-string
and the IOUtils/copy
is about 20% faster than this new version
compare, the second one is slower for me:
(defn gzipped-input-stream->str [input-stream]
(with-open [out (java.io.StringWriter.)]
(IOUtils/copy input-stream out Charsets/UTF_8)
(.toString out)))
(defn from-zip-file
[file]
(with-open [in (java.util.zip.GZIPInputStream.
(
file))]
(clojure.edn/read-string (gzipped-input-stream->str in))))
;; --------- alternate read technique ---------
(defn from-zip-file2
[file]
(with-open [in (java.util.zip.GZIPInputStream.
(
file))]
(clojure.edn/read (java.io.PushbackReader. (java.io.InputStreamReader. in java.nio.charset.StandardCharsets/UTF_8)))))
yes the difference is
that first one loads whole string first
also, read-string will read first object
read will read next object in stream
which means you can call read multiple times and read multiple objects
provided you do it inside with-open
of course
if you leave that macro it will close the stream
same goes if you return a lazy sequence
if I'm reading a single form that is gigantic, should the second one be better for memory use?
hi everyone. is there a code review -like channel here to get some suggestions / recommendations of what I should / should not do in clj?
Maybe it’s an off-topic question, but it’s still written in clojure and developed for clojure as well, so the question basically is, why did LightTable die?
how do I change the value of a single property of a mutable object?
e.g.:`velocity.y = -1;`
using set!
doesn't work here the way I want it to, because y is just an int.
so (-> velocity .y (set! -1)
isn't doing the trick, because at that point it's just trying to mutate an integer
(set! (. instance-expr instanceFieldName-symbol) expr) (set! (. Classname-symbol staticFieldName-symbol) expr)
I just tried doing (def p (java.awt.Point.))
(set! (. p x) 4)
which seems to have worked
Sorry I missed your response. Thanks... I guess this is an artifact of the CLR stuff I'm doing. :thinking_face:
Hey guys, can’t find the answer online: I have this:
(with-open [in (io/input-stream uri)
out (io/output-stream file)]
(io/copy in out))
this all works except if the uri is redirected, in my case it is from http://…
to https://...
.Is there a way to first let the redirection happen (if any) and then “slurp” the data with io/input-stream
Thanks!
slurp doesn't handle any of that stuff, because the underlying default java URL readers don't
@ghadi Thanks, where should I look for code example of the equivalent to io/input-stream with http-kit?
dunno about http-kit, but with clj-http
you can do (http/get ... {:as :stream})
and get the :body as an InputStream (don't forget to close it)
@ghadi And how would I close it? (sorry for rocky question here) Much thanks
(defn copy-file
[uri file]
(with-open [in (-> uri (client/get {:as :stream}) :body)
out (io/output-stream file)]
(io/copy in out)))
ok thanks!
hey guys, I'm looking for a stream implementation beside manifold.streams, any suggestion ?
not sure what that question means, manifold.stream is an abstraction, not a concrete implementation. the manifold library comes with a number of implementations of that abstraction as a bunch of namespaces like manifold.stream.async
the reason I ask is my build-tool environment can’t seem to find clj if it’s installed as a lein dep 😕
yes that’s what i’m asking. how can i go get clojure 1.9, for example, from a build tool where I don’t have scripting if something like lein doesn’t do an install for me?
the clj
command line tool is entirely different beast from any lein dependency. https://clojure.org/guides/getting_started
it is going to depend on your os, there are different packagers and installers people have created for install the clj tool
has windows been finished? i know @alexmiller has been focusing on that recently
if you are using lein fine with 1.8, I would suggest continuing to do so with 1.9. the clj tool has basically spawned a new ecosystem of tooling which is all brand new
I have java projects where gradle is the build tool and the dependencies are specified in gradle files. what would be the simplest way for me to spin up repls in those projects (with the same dependencies and the local source trees available) for dev time exploration?
clojure has the ability to spin up a socket repl when the clojure runtime is initialize
so if you pass -Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
and reference clojure.lang.RT somewhere that causes the class to be loaded, you'll get a socket repl
that's right one of the main options is a socket repl. I should be able to work with that, thanks
so... what is the interop equivelant of bracket notation, i.e. anim["walk"].speed = 2.0f;