This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-14
Channels
- # admin-announcements (21)
- # aws (5)
- # boot (41)
- # cider (76)
- # cljs-dev (15)
- # clojure (251)
- # clojure-brasil (25)
- # clojure-dev (16)
- # clojure-japan (8)
- # clojure-nl (1)
- # clojure-russia (110)
- # clojure-uk (7)
- # clojurescript (168)
- # clojurewerkz (1)
- # cursive (10)
- # datomic (45)
- # devcards (50)
- # emacs (5)
- # hoplon (6)
- # instaparse (6)
- # ldnclj (73)
- # lein-figwheel (4)
- # leiningen (6)
- # liberator (7)
- # luminus (2)
- # off-topic (19)
- # om (80)
- # onyx (2)
- # re-frame (11)
- # testing (12)
I’m parsing it using clojure.data.xml, which I thought would be lazy, but it’s chewing up huge amounts of memory
starting the jvm up with 12G means I end up using all of it on the parse process and it doesnt return
I can't speak to the Clojure xml libs, but there are certainly streaming apis in Java that are more than performant and memory friendly.
Regarding data.xml, are you using the lazy marked functions? http://clojure.github.io/data.xml/
Parses the source, which can be an
InputStream or Reader, and returns a lazy tree of Element records
(defn load-feed
"Loads the given filename"
[filename]
(-> filename
clojure.data.xml/parse))
thanks, that helps. What are you doing to cause the memory symptom? Are you printing to repl (that won't be lazy)
Let us know. You should be good: (-> "<foo><bar baz=\"42\" /></foo>" x/parse-str :content class)
gives back clojure.lang.LazySeq
I admit I'm not super familiar with the peculiarities of the library. (But there's always Java, yippee!)
hrm, testing loading my large XML file in an exploded war is leading to java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.com.sun.xml.internal.stream”)
I have the xml file in my /resources directory. When I build it into a war it ends up in WEB-INF/classes
hi, Im still trying to identify my bottleneck here. I am loading a 2 gig xml file, building a zipper on it, then attempting to take the first 5 elements from it and println a token
Reading logging and debugging from https://github.com/Day8/re-frame#logging-and-debugging and Talking To A Server section. With regards to replay, if I log anything sent to dispatch such as [:initalize], which is handled by a http call to setup initial db state, then dispatches a [:populate-db], if I replay I'm going to see two [:populate-db] one caused by log replay and one caused by http call of initialize.
nicholasf, I dont think clojure.data.xml/parse is SAX style
yeh, I just switched to golang and did what I wanted to do in 5 minutes after not thinking about it for 6 months
the documentation for parse is confusing it does mention something about SAX, but i guess XML gets less attention nowadays given the uncoolness
Im pretty sure if Id just broken out a sax parser and used java interop I would have been fine
The transit github made it to #1 on HN right now! Is there a reason why its topical today?
Is there any way to get a projects version while running code inside project.clj
?
I know about the System/getProperty trick, but that doesn’t seem to be set at the time I’m running code inside an :alias
in project.clj
, I think that only applies when you’re evaluating code in the context of your app.
@nicholasf: dealing with laziness can be tricky - but I still far prefer to use a lazy language to parse xml than sax! It really depends on the XML though. Wikipedia is an overly-simple example, but it was handy as it’s huge and easily avaialable.
@danielcompton: what about something like (-> "project.clj" slurp read-string)
?
@sander I was trying to avoid that route
@danielcompton: why? the edn structure of project.clj is well-defined
it’s not really edn
@nicholasf: True - or just very terse. I got far more value browsing the code than the docs. And it’s a pain as it’s split over several libraries.
oh nice, that is what I was thinking as nrepl is pretty JVM specific with all the bindings and stuff
So it’s possible, but it’s complicated and involves a commercial component. But I’m planning to try it out.
I don't think that is the best approach and even things like piggieback have to work arround tricks to get it going
Ok. It’s a long time since I looked at this, I’ll try to look soon and refresh my memory.
you can have them side by side, probably to much work to deal with devtools and other stuff
I’d like to sort out the CLJS REPL soon since it’s a pain point for a lot of people.
There’s an OSS one but the price on that is pretty reasonable and people speak highly of it.
I was just playing around with my REPL implementation which is now at figwheel level and working quite nicely
I’d be interested if you have ideas about what an interface to a CLJS REPL should look like. Ideally I’d provide an interface that a REPL implementation would provide an implementation of, so that Cursive could fire up different impls.
Although I’m not sure how much I need to make it generic, since there’s probably not a lot more custom REPLs out there.
That said, there’s already Figwheel, cljs.repl and yours so there’s clearly scope for different takes on tooling.
Ok. It’ll probably be a while before I can look at it seriously, definitely post-conj.
Ok, I have to get to bed, but I’ll copy all this and look at it when I get a chance.
Any ideas in compojure-api, why does PUT* ignore :body while POST* reads it? Both seem to read :body-params though.
Nevermind.
I am new to clojure, and I got a question I have not being able to find a definitive answer on google
I work with a big java desktop application, where I have managed to embedd jython to provide a scripting framework
it works well, but I hate java scientific libraries, jython cannot use numpy and Co. I got interested in Inchanter instead.
Now I am wondering if I can also embedd clojure into the java app in the same way as I did for jython.
What I do with jython, is on java, I create an interpreter, set paths to different modules I need dynamically
and then I load the script I want and execute a function that will always be in every script by convention, and which takes that 2D matrix I put into the interpreter
the function returns another 2D matrix, which then I can recover from java side and cast to java types
and then some other small things like redirecting jython stdout and stderr to java so that I can print nicely on the java app, etc
Would it be possible with clojure? Somehow I got the feeling it is not designed for this purpose.
@sidrero: I don’t have the final answer on this because I’m not very familiar with the environment, but my understanding is that since Clojure compiles to JVM code, mixing Clojure and Java is much simpler than what you had to do with Jython.
@sidrero: I don’t know how you make a Clojure / Java hybrid project, but Clojure can use Java libraries and viceversa.
I guess the only problem is that for jython they provide very clear examples on how to do this, while for clojure the documentation is not there, or at least I have not been able to find it
@sidrero: when I was working at Google, as a 20% project I wanted to figure out whether we could use Clojure to build apps using Google’s infrastructure. I don’t remember building a mixed project, but long story short, I was done within a day, having built sample apps that touched on the various internal databases, deployed them to our staging infrastructure and so on.
the Clojure->Java interop is pretty straight forward and I’ve made many mixed projects (requires some fiddling with the build process though). The other way around (calling Clojure from Java) I’ve not much experience with, but should be possible. Maybe this helps? https://stackoverflow.com/questions/2181774/calling-clojure-from-java
sidrero: how do you build your java apps? what build tool do you use?
also for scientific computing we pretty much decided to use Python and call it from Clojure using IPC (over ZeroMQ usually)
joelkuiper: I think more than the actual code, he needs the build tool chain.
ah I see, sorry!
sidrero: I think this might help, if you are using Maven: http://alexott.net/en/clojure/ClojureMaven.html
sidrero: and this might help if you wan to have java in a lein (clojure) project: https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
but for the scripting, the idea is not to compile the script as in the stackoverflow example, but load the script and interpret in on the fly
eval should do
sidrero: in that case, yeah, just add the clojure jar to your project and call its eval from java.
As joelkuiper said.
sidrero: something like this: https://clojurefun.wordpress.com/2012/12/24/invoking-clojure-code-from-java/
does clojure have a mechanism to load a whole script and then pass it to eval? or I should read the script with java, build a string, then pass to clojure eval
sidrero: it’s definitely possible and I would bet the results are much satisfying than Jython (not due to Lisp being great, but due to Clojure targeting Java).
sidrero: what about this: http://threecrickets.com/scripturian/ (from https://groups.google.com/forum/#!topic/clojure/slFNKpw1gLk)
Anyway, I have to go now.
just thinking out loud here (no idea what your project actually is …) but if it’s some sort of scientific project you can also try and start the iPython notebook as a subprocess and call that over WebSockets 😛 as Python science libraries are still the best out there imho
except that I need to pass a 2D array as argument to the clojure function I want to run
alternatively take a look at https://github.com/mikera/core.matrix
and if I would like to hide this complexity from my users? they should see only clojure types in and out
probably, or otherwise with a straight forward loop
wouldn’t starting a Clojure REPL be an option?
core.matrix works just fine on Object[][]. And on nested Clojure vectors like [[1 2] [3 4]]
All the different types are handled by protocols, so the translation is pretty seamless
But you can convert if you want, something like (coerce :persistent-vector (object-array [1 2 3])) => [1 2 3]
@mikera: I have a project somewhere on the todo to write an APL interpreter using core.matrix (including all the funky symbols) so I’ll take this moment as an opportunity to say thank you for the excellent library!
And the reverse works, e.g. (coerce :object-array [1 2 3]) => an Object[] array containing the longs 1, 2, 3
my thoughts exactly!
mikera: regarding matrix, what if I have an Object[][] where sometimes I have numbers, sometimes strings and sometimes dates, would matrix cope with that?
Yup. The following round-trip works just fine: (coerce :persistent-vector (coerce :object-array [[:a "Hello"] [1 nil]]))
Also check out the "dataset" functionality, which allows named columns etc. Useful if you are importing DB tables / CSV files etc
thanks for all the suggestions by the way, it is very cool to see such a lively community ... as comparison jython chat is mostly dead and it is difficult to get any help
Question about components: Let's say that I have a bunch of components that access a database, I have the connection set up as a component in the system. That's all fine, but I have all of my database access code as a function in some namespace. I can require this wherever I want, but the purpose of components seems to be to keep things like that from happening (having my database functions wrapped around all my other code like tentacles). Thoughts on how I might clean that up?
Also, kind of related, let's say I have a component with a bunch of workers. These workers get assoc
on to the component and may need restarting, or to be removed. Is it a bad idea to change what's in a component after it's assoc
'ed on to the system?
swizzard: Not really. I've been spoiled by my last project. Everything was pretty self contained, passing data back and forth between core.async channels, and not using too many things from other namespaces.
@jstew There's a lot of options there; for example you could have a component that owns the database connection. It may even store the connection in an Atom (as part of, say, a failover strategy). So inside that namespace are functions that access the database, expecting (by convention, as the first parameter) the component ... from which is extracted the active connection. If this really irritates you, you could define a kind of derived component, that is just a map of partial functions.
But still, if you were using Java and a DI container, you'd be invoking dbComponent.writeToDatabase(myRecord)
and here it's just (write-to-database db-component my-record)
.
map of partial functions: i.e., {:write-to-database (partial write-to-database db-component)}
... seems like a lot of work.
@jstew: it is valid for components to encapsulate some local state, typically stored in Atoms (or some other mutable ref type). I've used that for things like caches, tracking failover state, even some orderly shutdown code. There is a debate about whether that works best as one-global-atom-to-rule-them-all, or distributed state in Atoms inside components. I favor the latter in my experience, but there's something compelling about being able to see all application state in one place, as a kind of aid to debugging.
@hlship: Thanks! That's exactly the type of input I was hoping for. I'm going to try going with local state encapsulated by components.
I have a small question regarding clj-http. How can I emulate a curl post that does this? curl -X POST 'https://website.com/endpoint' -d 'request_body={ ... }'
I have a question for those using Pedestal: Is there a way to prevent a route handler from being called? For example, I am writing an authentication interceptor that will assoc
:status 401
to the context if the user is not authenticated but the problem is that the handler still gets called. To reduce load on the db/server, I do not want the handler to be called unless the user is authenticated.
Nothing with that case in particular @ghadi
and query-params doesn't do it either @jstew
It's expecting -d 'request_body={ ... }' which is where the problem is
not -d '{"request_body" : {...}}' but -d 'request_body={"data1" : "val1" ... }'
@nnbosko: I'm assuming you tried (http/post "
nnbosko: see https://github.com/dakrone/clj-http#input-coercion Body as string specifically
If you really have to go low level you can use clj-http/request
and set the body yourself.
hmm I'll try clj-http/request
Either way you're setting the body the same way as the 2 other examples though, so I would expect the same results.
As long as it's not https, you could use something like charles proxy to see what the difference is between the curl post and clj-http. That might give you more insight into what's going on with your request body.
@nnbosko: curl sets the content-type to application/x-www-form-urlencoded
automatically, clj-http doesn't
hello!!!
does anyone know of a good way to set up a local maven proxy?
I'm building docker containers and each one downloads the same jars over again
each time it's built!!!
maybe it's as simple as mounting the .m2 directory (hoping)
We usually build our jars on our machines and have docker build using the uberjar that’s generated from that for local dev.
that's interesting
do you have a build server do the same?
and that probably keeps the container leaner
@ericnormand: we mount the local .m2 directory