Fork me on GitHub
#clojure
<
2017-03-16
>
hiredman00:03:41

I haven't experienced that, but I could easily see boot having issues with data readers, because it starts its "main" pod or whatever before it knows what the classpath should be, and clojure sets up data readers by looking for stuff on the classpath when clojure.core is loaded

qqq07:03:14

is there any performance hits of returning a lazy-seq instead of a regular seq ?

qqq07:03:31

I feel like in exxchange for the "easily be constant stack space", we must be losing something somewhere

rauh07:03:18

@qqq Yes, but be aware that many "lazy" functions aren't truly lazy if you give them a chunked sequence, and compute the output for chunks (which is faster).

qqq07:03:04

@rauh: chunking, right, remember running into that issue earlier;;; so basicaly I need o make functions pure-ish where it doesn't matter when it gets evaled

rauh07:03:49

@qqq Well if you have side effecting functions, you should never use a lazy seq, that's just asking for trouble. And chunking is only unwanted, if your computation is expensive and might not be needed, in that case people unchunk (exists in many libs)

rauh07:03:44

If you don't need laziness, then start with a vector and work with those. 90% of my code uses vectors instead of lazy sequences.

cmal08:03:40

Hi! How to get the content of an incoming POST httpRequest in :body #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x42c3599b "HttpInputOverHTTP@42c3599b"] ? I know that the body is composed of a part named data whose MIME-type is text-plain and another part named excel whose MIME-type is application/excel.

thomas09:03:16

morning. I am having a rather weird problem. I am getting a java.lang.AbstractMethodError exception in a function that uses postwalk, but when I leave a certain key/value pair in my map it works fine.

thomas09:03:29

Any ideas what could be causing this?

thomas09:03:36

or how to get to the root cause?

thomas09:03:11

@cmal have you tried slurping it? (that is what I had to do). No idea though how that would work with the two MIME types though

cmal09:03:36

@thomas Hi! slurp seems not work with this kind of :body, but it do works when :body's content is string.

thomas09:03:31

@cmal shame... have a look at the documentation of org.eclipse.jetty.server.HttpInputOverHTTP and I suspect there is something of a .read you can do on it for a certain length.

thomas09:03:54

I assume you know the length of the two parts somehow?

cmal09:03:37

@thomas they may be 1k~5M files.

cmal09:03:15

slurp returns this kind of things. (.read (:body req)) returns 45. Is this the length of the incomming req?

cmal09:03:30

@thomas or should I write the string slurp from (:body req) to a file to get the excel file?

thomas09:03:03

I don't know how two the different parts are differentiated. Maybe start with one first? Assuming you have control over the client that is

cmal09:03:58

the content get from slurp, is this filename a tmp filename?

cmal09:03:43

can this string be convert to a map so I can get the name and filename from it?

noisesmith09:03:02

slurp is for things that form text

noisesmith09:03:14

I don't think it's the right thing for an excel document at all

noisesmith09:03:36

you can use filename and a java.io.File to create an excel file on disk

noisesmith09:03:12

or you can put the HttpInputOverHTTP stream into a byte-array, if you like that better and have some plan for it

cmal09:03:39

Thanks. Can you help me with how to put the HttpInputOverHTTP stream into a byte-array?

cmal09:03:10

Is this 75c65ba8-57e4-4b4a-99fa-28a837e4e263 filename some tmp file name of jetty? If so, maybe I can get the file by this name.

quan09:03:18

@cmal do you use ring with wrap-multipart-params middware, it may handle your data (not quite sure)

cmal09:03:24

@quan I've tried that. but it seems the client did not send the data in a multipart form. So the :params key's value is {}.

cmal09:03:15

data are all in :body of req. I do not know how to get the files from the :body #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x42c3599b "HttpInputOverHTTP@42c3599b"] object in java.

cmal10:03:30

@quan How can I use this nextContent? I am not familiar with java and only know basic java-interops. I do (.nextContent (:body req)) but it failed: No matching field found: nextContent for class org.eclipse.jetty.server.HttpInputOverHTTP

quan10:03:11

or try this lib https://github.com/ztellman/byte-streams, it handle most java stream data

cmal10:03:10

Thanks. - -

dominicm10:03:06

@cmack The HttpInputOverHTTP implements java.io.InputStream, byte-streams should work with it.

yonatanel11:03:44

Is it possible to protect a private project from accidental deployment to public repository, for example when not choosing the correct private repository on lein deploy?

urbank11:03:24

Surprisingly, I can't find a function in clojure to insert into a vector at an index without overwriting what was there. Is the zipper library supposed to be used for this?

thheller11:03:40

@cmal it sounds like you are working with a multipart request? ie. 2 different files in one upload?

cmal11:03:28

@thheller You can say that. Actually the first part is only some text, the second part is an excel file

thheller11:03:16

no I meant the encoding? is that a <form enctype="multipart/form-data">?

cmal11:03:21

My boss won't let me use byte-streams in the project. So I must use HttpInputOverHTTP to read the content and get the file. But I still know how.

cmal11:03:03

@thheller. No, it is data send by some client.

thheller11:03:42

it must be some kind of encoding if its http

cmal11:03:58

Actually, it is a POST request generated by Mathematica.

cmal11:03:26

yes, I can get the content as string, but I don't know how to get the file

cmal11:03:19

The content got by server is something like this:

thheller11:03:39

ah right. that's multipart encoding

dominicm11:03:34

Copy/paste that bit of code then? That's the interesting part.

cmal11:03:23

Last time I added a package in my project, my boss got fury. He won't let any new package to be introduced in this project. 😄

thheller11:03:53

you can try request.getPart("data")

thheller11:03:15

where request is the jetty request (not the :body but the actual request)

cmal11:03:59

@dominicm This is some Mathematica code. 😄 @thheller OK, I'll try that. Thank you.

thheller11:03:49

jetty should support that interface

thheller11:03:03

each part has a getInputStream that you can slurp

cmal11:03:48

(.getParts (:body req)) this way?

cmal11:03:22

IllegalArgumentException No matching field found: getParts for class org.eclipse.jetty.server.HttpInputOverHTTP

cmal11:03:00

Oh, the request I got was a map

thheller11:03:04

no you need the actual jetty request not the ring request map

cmal11:03:05

not an object

thheller11:03:25

not sure if you can get that, look at the keys of the ring request map

cmal11:03:03

clj 
(def svc-app
  (wrap-routes main-routes
               #(-> %
                    wrap-reload
                    keyword-params/wrap-keyword-params
                    cookies/wrap-cookies
                    params/wrap-params)))

cmal11:03:20

Does this code makes the request a map?

cmal11:03:50

Not sure how to get the jetty request

thheller11:03:52

(-> req :servlet-request (.getPart "data") (.getInputStream) (slurp))

thheller11:03:42

the adapter makes the map, the middleware just modifies it

noisesmith14:03:31

my concern with this problem is an excel file is not a file type that is appropriate for slurp - slurp only makes sense for text

cmal11:03:18

@thheller I'll dive into that. Thank you very much

dominicm12:03:27

I dunno, I like C. I think it shares a lot of ideas with Clojure. Simple being one of them. Interop too.

dominicm12:03:38

Not that Racket doesn't also. I just like both 😄

musha68k12:03:45

Me too – my background is in systems programming actually, still to promote C is a bit anachronistic don’t you agree? I’m not talking learning and experiencing how computers work (where simplicity of C still has its place IMHO).

jstew12:03:43

I suppose it all depends on what you're doing. Close to hardware, and need to squeeze every last bit of performance out of something... C is fine. Writing a large enterprise system, don't use C unless you're crazy.

dominicm12:03:55

I like C for utilities these days. Pretty much all of my Xorg is powered by C now.

dominicm13:03:10

Although now Rust is a little more stable, the author has hinted that the Wayland version will potentially be in Rust.

dominicm13:03:47

I like the idea that my laptop is this beast, but I could run my window manager on a microwave 😆

jonpither13:03:58

can you get Lein to simply print the classpath, if you pass it argument of deps? similar to Boot's with-cp?

Alex Miller (Clojure team)14:03:40

I guess maybe that’s not actually what you meant

noisesmith14:03:28

@cmal if you can't add libraries, you can translate one of the answers on this S.O. post with interop http://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java - or there might be something else more direct, but that depends on what you really want to do with that data. If you want to put the attachment in a file, you can put that in directly and you don't need slurping or an array

mike_ananev15:03:41

hi! where i can read about alpha15 release notes /changes ?

greg_arcara17:03:13

I have a project I created with lein that I am using to do some coding problems, so just have been editing core.clj. Today when I tried to lein repl to start the repl I am getting a stack trace with the error

Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: create in this context, compiling:(/private/var/folders/25/t0k03gfd2hz4y_5nll9zn7080000gn/T/form-init9009948996929075819.cl
j:4223:33)
My core.clj file just has a print call in it at the moment and I haven't changed anything since it was last working. Any ideas what could be causing this?

erwinrooijakkers17:03:19

Is it possible in lein-less to create one target-path? I have multiple less files, but want to compile them into one. Or should I then use another plugin as well?

noisesmith17:03:40

greg_arcara try lein run -m clojure.main then (require 'my.ns.core) to see an error that is more directly related to your source files

greg_arcara17:03:25

@noisesmith

user=> (require 'my.ns.core)
FileNotFoundException Could not locate my/ns/core__init.class or my/ns/core.clj on classpath.  clojure.lang.RT.load (RT.java:456)

noisesmith17:03:51

well - I meant to use your actual core namespace, not literally 'my.ns.core

greg_arcara17:03:06

@noisesmith sorry, I am just getting started with clojure and lein, should that just be clojure.core?

noisesmith17:03:20

greg_arcara what is the namespace declared in your core.clj file?

greg_arcara17:03:37

I don't even have one, the only line is (println "Hello world")

noisesmith17:03:53

greg_arcara well that's one of your problems then - what is the path to the file?

greg_arcara17:03:34

noisesmith src/test_app - This was working fine yesterday

greg_arcara17:03:44

not that I question that it's wrong 🙂

noisesmith17:03:14

greg_arcara if all you want is to write a clj file and do simple forms, you can use clojure.jar instead of lein. lein is a project manager, to use it, your files should declare namespaces that reflect their location on the classpath

noisesmith17:03:29

so src/test_app/core.clj should start with (ns test-app.core)

erwinrooijakkers17:03:48

@grrt Is it possible in lein-less to create one target-path? I have multiple less files, but want to compile them into one. Or should I then use another plugin as well?

erwinrooijakkers08:03:51

@grrt I found a solution. The target file is compiled if I import all others. I misunderstood Less, now I understand. Thanks for the software.

greg_arcara17:03:49

I am just trying to use the repl to run my code in vim for testing what I am doing

greg_arcara17:03:52

let me try adding that in

noisesmith17:03:21

greg_arcara OK - java -jar clojure.jar is all you need for that, then (load-file "foo.clj")

noisesmith17:03:37

but lein is really useful for more organized projects, it's good to learn to do things that way

greg_arcara18:03:03

noisesmith that did work, which is interesting, because it was working fine for a few days now. I have been using the lein repl because it allows me to run the code easily from within vim itself. I'll keep investigating the best way to do this, thank you

noisesmith18:03:27

@greg_arcara

$ ed deleteme.clj
deleteme.clj: No such file or directory
a
(println "Hello WOrld")
.
w
24
q
$ java -jar ~/bin/clojure.jar deleteme.clj 
Hello WOrld

joshjones18:03:40

@greg_arcara

$ lein new abc
$ cd abc
$ lein repl
user=>     (load-file "src/abc/core.clj")
user=>     (in-ns 'abc.core)
abc.core=> (foo 42)

noisesmith18:03:45

@joshjones but if you have a lein project, you can just use require - I was trying to show the minimal setup, since clearly some details of what lein is for were being missed

noisesmith18:03:55

and if you can't use require (eg. you removed your ns form) that means you have a broken lein project, which involves a bunch of other things about how clojure needs to be able to use the classpath and how resources map to namespaces

greg_arcara18:03:14

Thanks guys, I appreciate the help

timvisher18:03:03

i recall there being a leiningen plugin or something for counting clojure sloc. any ideas?

bronsa18:03:01

lein vanity

timvisher18:03:54

ah yes. thank you 🙂

niroshanr18:03:15

Hi niroshan, I like to contribute clojurian in GSOC 2017. Can you help me for start contribution now?

qqq19:03:48

I think I have asked this before, but I can't find the function. Given f, x is there a function for generating x, f(x), f(f(x))), f(f(f(x))), f(f(f(f(x)))) , .... ?

ghadi19:03:21

i love iterate

ghadi19:03:26

(take 7 (iterate subtract-day today))

ghadi19:03:48

well I ❤️ nearly everything in clojure.core

jjfine19:03:36

Hi, I'm trying to use clojure.tools.namespace.repl/refresh but I'd like to exclude my test files. Is there something I can add to my lein profile so those files aren't on the classpath?

shdzzl20:03:01

@jjfine :source-paths

shdzzl20:03:13

You can also use clojure.tools.namespace.repl/set-refresh-dirs to set only the directories you'd like to refresh.

jjfine20:03:19

ok thanks i was trying to set :test-paths [] but that wasn't working

facundo22:03:07

Hi! I’m looking for libraries to do integration tests on a restful API. things like “get this url with this headers, expect a json response with this and that property, etc.”. clj-http + clojure.test seems to be the basic choice, any other suggestions?

mars0i22:03:14

@greg_arcara maybe you've fixed your problem by now, but did you change something in .lein? That's usually how I confuse myself with inexplicable errors.

greg_arcara22:03:16

@mars0i no, I just am using the namespace

mars0i22:03:54

OK. Thought it might be worth a shot

seancorfield22:03:22

@facundo Yeah, clj-http + either clojure.test or Expectations would be fine (we use the latter).

seancorfield22:03:08

We found it worthwhile to write some convenience functions to wrap post/get clj-http operations to make our tests easier to write — a mini-DSL if you like.

facundo22:03:47

right I’m thinking of doing something like that, once I settle with the libraries

facundo22:03:17

I’ll take a look at Expectations, thanks @seancorfield

facundo22:03:30

assuming there’s no library that does it already

mtkp23:03:01

@facundo i've used juxt/iota (https://github.com/juxt/iota) occasionally for partial assertions on a response map

facundo23:03:09

mmm I’m not sure about those symbols := :⊃