#clojure logs

2015-12-06

03:00ben_vulpesis creating a form in clojurescript really the only way to do file uploads?
03:00ben_vulpesi suppose it would be too easy if i could just jam the file input file into the POST array...
03:01justin_smithben_vulpes: the way I did it was I googled "upload file javascript" and translated it to like 3 lines of interop
03:02ben_vulpesootay
03:02ben_vulpesthanks justin_smith
03:03justin_smithnp - it is straightforward, once you see a working example of the js api
03:04justin_smith(and iirc it does not need a form)
03:14ben_vulpesi'd just hoped to wire this into one of the more standard ajax libraries
03:14justin_smithyeah, we tied it into a websocket
03:16ben_vulpesblech
03:16ben_vulpesweb tekmologee
03:54irctchi
03:55irctcthis a place to get help?
03:56ianhedoesitsure!
03:56irctcok
03:56irctc(def response (http/get "http://hi.com"))
03:56irctc(keys response) returns this
03:57irctc(:status :headers :body :request-time :trace-redirects :orig-content-encoding)
03:57ben_vulpesjustin_smith: i'd hoped that i wouldn't have to drop down, that cljs-ajax would actually handle this
03:57irctc(take 1 (keys response))
03:57ben_vulpeshow is a javascript post more complex than a curl one-liner
03:57irctcreturns :status
03:57irctchow can i see that value of :status?
03:57ben_vulpes(:status response)
03:57ianhedoesit(:status response)
03:57ianhedoesitaw
03:58irctcwhat is that called?
03:58ben_vulpesirctc: keys are functions of their maps
03:58irctcoh yeah! i recall reading that, ty
03:58ben_vulpesit doesn't work all the time
03:58ben_vulpesbeware
03:58ben_vulpesand there are no types to save you
03:59ben_vulpes /s
03:59irctcty
04:00ianhedoesitalso, (response :status); (get response :status)
04:01WickedShellI'm looking through yourkit and I have almost a MB of memory (just in the early list of results)) of duplicate strings like "clojure.lang.numbers" and "java.lang.Object" is there anyway to get clojure to intern these whenever it creates them? I'm not sure why they are all strings on the stack. (memory is a problem for me on some target devices)
04:03irctcok how can i get the :status in one line without using def?
04:03ben_vulpes(let [s (http...)] (:response s))
04:03oddcully(-> (http/get "...") :status)
04:03ben_vulpesslick
04:04ben_vulpes(:status (http/get "...")) << ?
04:04ben_vulpesactually i've seen the above eat stacktraces
04:05oddcullyi assume, that http/get is some costly operation? and you might need more than just one key? so a let might be better
04:05irctcty very very much
04:05TEttingerWickedShell: I'm guessing those may be for reflection at some point, even if you aren't using reflection they may be so it can or a jar that uses yours can
04:06oddcullyben_vulpes: -> is a macro. it has potential to mess with your mind
04:06irctcindeed -> is i recognise that though i don't know what it does yet
04:07TEttinger,(-> 0 (inc) (inc) (inc))
04:07clojurebot3
04:07irctclet binds the http/get to s, correct?
04:07oddcullyirctc: if you find the doc strings to crips for your taste, have a look at conj.io - it helps me alot to see something used with example code
04:07TEttingersame there as (inc (inc (inc 0)))
04:07ben_vulpes(let [{:keys [status]} {:status "bar"}])
04:07ben_vulpesif we're playing golf
04:08ben_vulpeswhere that last map is the http call
04:08irctcty for conj.io, needed that
04:09oddcully,(-> 0 inc inc inc)
04:09clojurebot3
04:09irctctheres an eval bot here?
04:10TEttingerI was wondering if that would work, heh oddcully
04:11irctcok, why does (let [s (http/get "http://hi.com&quot;)] (:response s)) return nil?
04:12TEttinger,(:blargl {:a 1})
04:12clojurebotnil
04:12TEttingercould be that there's no key for :response
04:12irctcgot it! ty
04:12TEttingercould be that it's really a vector of maps, or a map of maps and only the inner ones have :response
04:13TEttinger(not sure how http lib works)
04:13TEttinger(the :response may actually be a valid key and it has a value of nil)
04:28WickedShellTEttinger, yeah looks like you're right its all from reflection...
04:28WickedShellI still hold that interning the string on reflection would be kinda nice though for memory reasons
04:30WickedShellalthough on further reflection it would probably slow down most reflection uses :/ (although I shouldn't be reflecting at all within my code, I know some libraries I use do)....
04:51WickedShellTEttinger, found a great solution: if you are using java 8 (I forget what update) you can run string deduplication during GC with the following args "-XX:+UseG1GC -XX:+UseStringDeduplication -XX:+PrintStringDeduplicationStatistics"
04:51TEttingeryessss neat
04:52TEttingerdoes it need the last arg, WickedShell?
04:52WickedShellTEttinger, no not at all, I just had it in so that I could see the stats
04:52TEttingeroh ok cool
04:53WickedShellI'm seeing it dedup around 853KB every GC, and I had a bunch of stuff get pulled out after the start of the repl/etc before ever launching the app
04:54WickedShellthat does require the G1GC though, (I haven't had a problem with it, but I've never been picky about that kinda thing yet)
04:54TEttingerreducing memory usage successfully?
04:54WickedShellIt's doing far better, but I need to see what that GC would do in general without the string dedup
04:55TEttingertry with just the arg "-XX:+UseG1GC"
04:55WickedShellI know I just need to finish doing it :D
04:55TEttingerhehe
04:55WickedShellIE I was GC'ing after hitting 1.5GB heap, now its taking me to around 500MB before GC'ing. (Which I'm fine with really)
05:00WickedShellTEttinger, yeah seems to have the desired effect, it vastly reduces my duplicated strings. The effect is moderately limited after the initial startup as most of the reflections that create it are still happening, and would be GC'd anyways, and since the dedup is only on GC it doesn't effect it till then
05:01WickedShellSupposedly for people's who apps are more string based (IE servers etc that do lots of http stuff) the effect can be fairly large/have almost all the benefits of interning without having to figure out/manage the interns as the programmer
05:02WickedShellI'm going to stick with it, and I'll see if I encounter a problem down the road, but since I was already stuck targeting JDK8 it doesn't adjust my requirements really
05:05visofhi guys
05:07WickedShellTEttinger, not from my app, but someone else's comparing java 7's parallel gc http://i.stack.imgur.com/rhmQ9.png vs java 8 G1GC with string dedup http://i.stack.imgur.com/tDWnV.png
05:08WickedShellI'm seeing similair behaviour here
05:16visof(partition-by identity '(1 1 2 3 4 4 1 1))
05:16visof,(partition-by identity '(1 1 2 3 4 4 1 1))
05:16clojurebot((1 1) (2) (3) (4 4) (1 1))
05:16visofhow can i do the same for some hashes for specific key?
05:17visof, (partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))
05:17clojurebot(({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))
05:18visof, (partition-by identity (map #(:k %) '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1})))
05:18clojurebot((1) (2 2) (1 1))
05:18visofbut i need the original hash
05:18visofnot the values of the keys
05:19visofcan anybody help?
05:25ARM9,(map keys '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1})) ;visof
05:25clojurebot((:k) (:k) (:k) (:k) (:k))
05:26visofARM9: that's what i don't want
05:27visofi want collect equal hashes in some specific keys without lossing the hash itself
05:27opqdonut,(partition-by keys [{:k 1} {:k 2} {:k 2} {:k 1} {:k 1}]) -- like so?
05:27clojurebot(({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))
05:27opqdonut,(partition-by keys [{:k 1} {:k 2} {:j 2} {:j 1} {:k 1}]) -- this is what I meant
05:27clojurebot(({:k 1} {:k 2}) ({:j 2} {:j 1}) ({:k 1}))
05:28TEttingerdo you mean adding the values together for identical keys?
05:28visof'({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}) should return (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))
05:28visofsomething like this
05:29TEttingeryou had that
05:29opqdonutvisof: you already tried (partition-by identity ...), wasn't thatexactly the right thing?
05:29visofopqdonut: nope
05:29TEttinger, (partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))
05:29oddcully,(partition-by :k '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))
05:29clojurebot(({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))
05:29clojurebot(({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))
05:29opqdonutoddcully's solution works when you have other keys besides :k
05:30opqdonut,(partition-by :k '({:k 1 :a 1} {:k 2 :b 2} {:k 2 :c 3} {:k 1} {:k 1 :d 4}))
05:30clojurebot(({:k 1, :a 1}) ({:k 2, :b 2} {:k 2, :c 3}) ({:k 1} {:k 1, :d 4}))
05:30opqdonutlike so
05:30TEttingerI think that's not the goal, opqdonut. if I understand correctly, it's whole hash-maps being compared
05:31opqdonutbut he did that already and wasn't satisfied with it :P
05:31TEttinger,(partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1} {:j 1 :l 2}))
05:31clojurebot(({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}) ({:j 1, :l 2}))
06:01visofwhat is the best way to collect similiar things together ?
06:02visof'(1 1 2 1 3 4) -> (1 1 1) (2) (3) (4)
06:02oddcullygroup-by? frequencies?
06:22MJB47,(vals (group-by identity '(1 1 2 1 3 4))) ; visof does this work?
06:22clojurebot([1 1 1] [2] [3] [4])
08:12MONODAfor some reason: (= (c/complex-number 0.0) (c/complex-number -0.0)) returns false
08:12MONODAthis is definitely wrong, any ideas if I'm doing something incorrectly?
10:13jonathanjis there a neat way of writing this in Clojure: gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build()).build(sha1Signer, new X509CertificateHolder(cert)));
10:14jonathanji'm not sure if you can use (new) in a (..) form
10:21ucbI'm confused, I'm depending a project on a lib L, which depends on a lib L2. I'm trying to access L2 from within my project and I'm getting Not Found errors. Am I correct in thinking that if I add L in my :dependencies in leiningen, then L2 should be available too?
11:30xeqiucb: yes, it will normally pull in L2 as well
11:31ucbxeqi: that's what I thought too, but when requiring an ns from L2, it can't be found. I'm wondering why :/
11:31xeqidoes lein deps :tree show L2?
11:32xeqiand the correct version of L2
11:32ucbit does not
11:32ucbvery strange
11:35xeqithen either L does not say it requires L2, or the project.clj file is saying not to bring in L2. The later is easy to check, does the project.clj have any :exclusions in the tree?
11:35ucbthe current project, and L are both mine
11:35ucband I can tell you that L depends on L2 for sure, and that there are no exclusions anywhere
11:36ucbthis is L
11:36ucband this is L2 https://github.com/puniverse/pulsar/
11:36ucbmy current project depends on [sliver "0.0.1-SNAPSHOT"]
12:16ucbxeqi: apparently I didn't deploy the right version of sliver; it's all good now
12:16ucbthanks for looking
13:14favetelinguisIs there something like Prolog _ in core.logic when i want to express any value is valid?
13:44dnolenfavetelinguis: yes `fresh` makes new logic vars
13:44dnolen`(fresh [_] ...)`
13:44favetelinguisthanks
14:37weebzhas anyone had any experience with MMJ / sending sysex to midi devices with clojure?
14:37weebzor on OS X adding a jar to /Library/Java/Extensions?
14:37weebzI'm running into this error, and I'm not sure how to solve it
14:37weebzno mmj in java.library.path
16:00ben_vulpesso i'm uploading a file with xhrio via clojure.browser.net, and don't naively understand how to deserialize the file object in the k/v map i'm POSTing to the server -- justin_smith, any insight to offer?
16:01justin_smithben_vulpes: accessing the file from the server side?
16:01ben_vulpesjustin_smith: myeah
16:01ben_vulpesi'm using http-kit, so the whole map is coming in on the body. at this point i'm naively calling (slurp (.bytes (:body r))) just to see the map printed out to the repl
16:01justin_smithben_vulpes: I know that with ring's wrap-upload you get a file on disk in /tmp
16:03ben_vulpesi might still be misusing xhr
16:05ben_vulpeshttp://dpaste.com/0XHWZFY
16:08justin_smithben_vulpes: I am extremely suspicious of '(js->clj file)'
16:08ben_vulpesi have tried it both ways
16:09ben_vulpessad hacking detritus
16:14ben_vulpeshttp://dpaste.com/0B1NZ7C << more detail
16:14justin_smithben_vulpes: so that file should be your thing
16:15ben_vulpesjustin_smith: myeah, that's what i'm given to understand. i don't quite grasp how to pull that out of a map-shaped string, though.
16:15justin_smithI mean it created a file object
16:16ben_vulpesriiiight. i think the cljs side of things is working now, i just need to understand how to turn that POST data into k/v pairs and a file object.
16:16justin_smithwhat is "net" there - are you sure it expects the clojure version of the file and not a js version?
16:18justin_smithbecause with the current state of that, I would not be super surprised if it was a "File" on the js side, but the server just got the str representation of a file (which is of course kind of useless)
16:18ben_vulpesgood question
16:18ben_vulpesnet is clojure.browser.net
16:19ben_vulpesit is showing up in string printing as #object[File [object File]]
16:25ben_vulpeswell i fell back to form data and now i get java.io.File
16:26ben_vulpesMUH LAYORZ OF INDIRECTION
16:26justin_smithcool, so that file should have the stuff you need, right
16:26ben_vulpesburned again by the law of leaky abstractions
16:27ben_vulpesright yeah. have yet to confirm it but i see java.io.file now which is what i'm looking for
16:27ben_vulpesthanks again justin_smith
16:27justin_smithnp - I am sure this would have been different if json had a file representation (but of course it does not)
16:51benjyz1hi. how can i define a short-hand for a java-namespace?
16:51justin_smithno
16:51benjyz1(:import foo.bar)
16:51benjyz1(def fb foo.bar)
16:51benjyz1not a good idea?
16:52justin_smithyou don't even need the import thought
16:52justin_smithbut that's a class, not a package
16:52benjyz1I mean class
16:52justin_smithmaybe I misunderstand what you mean by "namespace"
16:52benjyz1yes, that was confusing
16:53justin_smithwell, the symbol you define won't work with the interop forms
16:53justin_smith,(def d java.util.Date)
16:53clojurebot#'sandbox/d
16:53justin_smith,(new d)
16:53clojurebot#error {\n :cause "Unable to resolve classname: d"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalArgumentException: Unable to resolve classname: d, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.IllegalArgumentException\n :message "Unable to resolve classname: d"\n :at [clojure.lang....
16:53justin_smith,(new java.util.Date)
16:53clojurebot#inst "2015-12-06T21:53:44.401-00:00"
16:53justin_smithso the def you make is mostly useless
16:53TEttingerbenjyz1: do you mean something like renaming AbstractProxyFactoryBean to bean-thing ?
16:54benjyz1interesting...
16:54justin_smithyou can use a def, but the def is pretty much useless, and you can't do a true rename
16:54TEttingeryeah, there's sorta workarounds
16:54benjyz1ok. are there are other ways to get a shorter name?
16:54TEttingerhow's your macro writing skills?
16:54justin_smithjust import
16:55justin_smithbut really, all you need is a constructor with the name, otherwise you only need to worry about instance methods
16:55justin_smith(usually)
16:55benjyz1ok, I'm accessing static fields.. perhaps I'm confused about import
16:56justin_smithbenjyz1: import doesn't do much, other than change the rules for class lookup, but import does not support any sort of renaming
16:58benjyz1ok, I'll try some macro.. I have a stack language in Java
17:07benjyz1,(defmacro op [x] `(com.foo/~@x))
17:07clojurebot#<RuntimeException java.lang.RuntimeException: Invalid token: com.foo/>
17:08benjyz1com.foo is invalid token. hmmm..
17:09justin_smithit's not taken - it just doesn't resolve to anything that exists
17:09justin_smithoh, misread, sorry
17:10benjyz1I have a bunch of static fields of the com.foo class
17:11benjyz1which are opcodes of a language
17:22benjyz1idea someone how to do this?
17:22benjyz1https://www.refheap.com/112423
17:22TEttinger,(defmacro op [x & args] `(. java.util.Math ~x ~@args))
17:22justin_smithbenjyz1: macro splicing does not work at the symbol level
17:22clojurebot#'sandbox/op
17:23TEttinger,(op PI)
17:23clojurebot#error {\n :cause "java.util.Math"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: java.util.Math, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.ClassNotFoundException\n :message "java.util.Math"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :tra...
17:23TEttingermm.
17:23TEttingerlang
17:23TEttinger,(defmacro op [x & args] `(. java.lang.Math ~x ~@args))
17:23clojurebot#'sandbox/op
17:23TEttinger,(op PI)
17:23clojurebot3.141592653589793
17:23TEttinger,(op sin (op PI))
17:23clojurebot1.2246467991473532E-16
17:23justin_smithbut yeah, do it TEttinger 's way
17:24benjyz1thx. I've just recently worked with a clojure jython interpreter and it worked pretty well
17:25benjyz1https://github.com/rplevy/clojure-python
17:25yonatankorenI haven't done Clojure in a couple weeks, I'm going through withdrawals
17:26benjyz1TEttinger: thx
17:26TEttingerno prob, I am not very good with macros so I'm mostly pleased that it seems to work!
17:27benjyz1I'm trying it for my case, which is actually simpler, since it doesn't have any args
19:19ben_vulpeswhat's a concise way to turn a list of values into a map with keys that are those values and an arbitrary value on each key in the new map?
19:19ben_vulpeseg [1 2 3] -> {1 {} 2 {} 3 {}}
19:19justin_smith,(zipmap [1 2 3] (repeat {}))
19:19clojurebot{1 {}, 2 {}, 3 {}}
19:20ben_vulpesnoice
19:20ben_vulpesthanks justin_smith!
21:27m00nlightHow can I export a function with default argument in clojure to be called in Java ?
21:29justin_smithm00nlight: if you have gen-class for the namespace, each argument list should be a separate method overload, based on argument count (both should take Object for each arg)
21:30m00nlightjustin_smith: So I just to need to export two overloading methods in gen-class, right?
21:31justin_smithm00nlight: you shouldn't need to export at all, the functions in that namespace should all be accessible as static methods
21:33m00nlightjustin_smith: Actually, I define which methods to gen for the class to be called in Java, so in this situation, I need to export two different methods, right?
21:33justin_smithI'm not sure, but if you don't mention the function at all, and its namespace is gen-class compiled, it should be accessible as a method for each arity it defines
21:35m00nlightjustin_smith: http://pastebin.com/TK8FaM9Z
21:35m00nlightfor this example, I want to export an overloading for generateVector
21:36m00nlightwhich could take another default empty list as input
21:36m00nlightin Java, in this case, I need to define two seperate methods in the :method of gen-class, right?
21:37justin_smithyes, I think so - argument count is a form of overloading, each count calls a different definition
21:37m00nlightjustin_smith: OK. I will try, Thanks for your help :)