This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-02
Channels
- # beginners (29)
- # boot (65)
- # cider (12)
- # cljs-dev (8)
- # cljsjs (31)
- # clojars (5)
- # clojure (147)
- # clojure-austin (47)
- # clojure-berlin (1)
- # clojure-brasil (7)
- # clojure-russia (5)
- # clojure-spec (18)
- # clojure-uk (18)
- # clojurescript (113)
- # css (2)
- # cursive (7)
- # datascript (5)
- # datomic (2)
- # dirac (4)
- # events (3)
- # funcool (143)
- # hoplon (287)
- # jobs (2)
- # off-topic (4)
- # om (10)
- # om-next (5)
- # onyx (18)
- # protorepl (1)
- # re-frame (93)
- # reagent (34)
- # rum (41)
- # test-check (51)
- # untangled (15)
- # yada (18)
@qqq, how about this: (defn magic [f] (some identity (for [i (range 0 11)] (try (apply f (repeat i nil)) i (catch clojure.lang.ArityException _) (catch Exception _ i)))))
? 🙂
@henriklundahl : technically correct, not the solution I had in mind, also bad if any of the functions do rm -rf /
Also not technically correct since you don't know for sure where the exception was thrown from
(defmacro bnds [bnd _ fexpr]
`(reduce into [] (for ~fexpr ~bnd)))
(defmacro run [lst expr]
(let [state (gensym "state")
mbnds (bnds [[state k] (list v state)] :for [[k v] (partition 2 lst)])]
`(fn [~state]
(let ~mbnds
(~expr ~state)))))
(pprint
(macroexpand-1
'(run [a fa
b (fb a 2)
c (fc a c 3)]
(fn [s]
(+ a b b)))))
^^ in the above, is there a way to "inline" the mbnds ?Is the main difference of Protocols vs MultiMethods as follows: protocols dispatch on type of first arg; multi methods dikspatch on result of arbitrary function ?
Is there supposed to be a section under https://clojars.org/profile to add the PGP public key? Clicking on the profile takes me to a screen to confirm my password, and clicking confirm takes me to a screen to conform my password, ad infinitum. Is there a bug or am I doing something wrong? Thanks in advance.
Looks like a bug with #clojars (there's a channel for that) -- maybe @tcrawley et al can take a look when they're back at work on Monday or Tuesday?
I logged a GitHub issue for you @athinggoingon https://github.com/clojars/clojars-web/issues/605
I'm trying to debug the output of a macro, and I'd love to have comments (which the macros generates) to help me figure out wtf I'm doing wrong
I'm building the real time chat part of my server in clojure. I need http and websockets. Any recommendation on webserver for highest performance websockets?
@qqq I'm using sente with httpkit proxied through nginx for https://PartsBox.io/ and I'm quite happy with it, but I don't know what you mean by "highest performance". I don't intend to scale to google/facebook sizes.
@jrychter : thanks http-kit recommendation, seems great from my own research; might just use raw ws instead of sente
@qqq: I'd recommend sente, unless you really feel comfortable with websockets. I found it very convenient, especially AJAX fallback.
I cry a little inside everytime http-kit is recommended here, had some bad experience with it and there are quite a few solid alternatives (aleph, immutant, yada, jetty9 etc)
from aleph readme: Supported servers: http-kit, Immutant v2+, nginx-clojure, node.js, Aleph
cool stuff
it was a while ago, but we once ended up with deadlocked server with 100% cpu consuption because of a race in http-kits code
the sales pitch of http-kit is appealing, but I am not sure I'd build a critical thing with it anymore
Thanks. I guess I should try aleph, then (I need something well supported by Sente). However, in general I found that every complex piece of software has its problems, they just might be different problems. Most people would say jetty is rock-solid, and yet several years ago I had problems with jetty. But — aleph does look well-written and there is the Author's reputation, too 🙂
thing is, jetty is used by a lot of people, and the team behind it is substantial. Aleph was also proven to be reliable by some heavy lifters as well
I also don't think http-kit does anything to support backpressure with WS for instance, which can end up causing some nasty problems
then again my experience is from a while ago, maybe the new maintainer(s) fixed some of these
@qb: ah, found it: my bug report for jetty 6.1.26: "Sockets are not getting closed. Application crashes under load with "Too many open files" after several hours. Application is written in Clojure using Ring (ring-jetty-adapter)." Symptoms reproducible only with hours of load testing.
Anyway, thanks for the recommendation — I don't really mean to argue, just pointing out that every piece of software likely has bugs.
I’ve written custom proxies/tunnels with aleph+manifold+gloss and they push gigs of data daily without any issues
#?(:clj
(deftest nm
(testing ""
[(is true)])))
(defmacro deftest-clj [&rst]
... magic here ...
)
(deftest-clj
)
is it possible to define the macro deftest-clj, so it generates the #?(:clj (deftest .... ? Basically deftest-clj works better for my emacs code foldingHello all, how to transform this
#{{:?origem {:EQX {:TAM :qualidade}}}
{:?origem {:TAM {:VLP :qualidade}}}
{:?origem {:EQX {:VLP :qualidade}}}
{:?origem {:EQX {:ITA :atraso}}}} => #{{:EQX {:qualidade #{:TAM :VLP} :atraso {:ITA}}} {:TAM {:qualidade #{:VLP}}}}
my brain freezed tryingwould it be possible to use shorter names, like :a and 1 instead? it's hard to see wht the transform is doing
@fabrao I'll give you that this one is tricky...
@fabrao you may want to look into Specter 🙂
@matsumoto welcome 🙂
Is there anything against using bean
for implementing wrapper code like this?
https://github.com/scsibug/feedparser-clj/blob/master/src/feedparser_clj/core.clj
@borkdude yeah, bean is slow 😕
@fabrao the result of the transformation you pasted is not even valid. {:atraso {:ITA}}
is not valid. I can guess you mean {:atraso #{:ITA}}
but no need to make people infer what should be correct data 😉
@val_waeselynck you r my hero !!!
RFC: to re-intro myself to clojure (after some time away), I wrote a silly minheap, and tried my hand at test.check property based testing. I would truly appreciate any feedback on style, content, etc., from anybody willing to take a few minutes. https://github.com/benfleis/heaps/tree/master/clj/test/heaps I am most curious about improvements to the extract func, and the formulation of testable heaps. The latter went through 4 iterations before I arrived at this "simplest-thus-far" version.
Is there a cleaner way to write (or (some-> e vector) [])
— (if-let [e some-expr] [e] [])
— e
evaluates to a hash map or nil
; I need either a sequence of one element (`e`) or an empty sequence. It just feels like there ought to be some simpler way to write this.
I dunno that it's any cleaner but another way to write it would be (filter identity [e])
or (remove nil? [e])
depending on what e could be
(vec e)
?
ahh you want it kept as a hashmap
basically, this is Haskell's Maybe to List: http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Maybe.html#v:maybeToList
Thanks. Yeah, it’s an odd use case. I’m thinking I might just be better off modifying the upstream clients of this code to accept a thing or nil (the client is not Clojure, however it is under my control).
((if (nil? e) vec vector) e))
is a bit too baroque
(some-> x vector)
Is almost the same thing
That’s why I had to have (or … [])
around it 🙂
which is the same as the filter/remove above, just with keep, which is slightly different
Yeah, that’s what @qqq suggested … I decided to just modify the upstream code to accept nil
or a hash map instead … which introduced its own problems (but those aren’t Clojure problems so I’m less bothered about ugly code there).
I want to parse/scrape some webpages that might be generated dynamically. My current thought is to load the page into PhantomJS and then use clojure.data.xml
to parse the dom, and maybe convert that structure into a zipper. Any thoughts on this approach? Any oss projects that do something similar?
@grav when hearing about scraping and clojure enlive is the first that comes to my mind.
Oh, but it seems Enlive will only parse the static HTML? Not the rendered DOM structure that might be generated by Javascript? Or am I misunderstanding something?
that's how i would approach it. i like to break everything up into single data transformations
Yes, that makes sense. I guess doing everything in Clojurescript in PhantomJS might also be a performance bottleneck
take a url and return a string, take a string and (thru enlive) return the data i want, take the data i want and do my business logic
if you want to try to use selenium's java library directly you can add it your lein project with this ;; https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java [org.seleniumhq.selenium/selenium-java "3.0.1"]
i'm not sure if there is a clojure wrapper around it already (that probably is... there's always wrappers around commonly used stuff)
but depending on how much of the selenium api you'll need, it may or may not be worth the bother
not sure if you're familiar with selenium, here's the basic intro http://www.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example
Nope, not familiar with it - great with the links! I think doing it all in jvm sounds like a cool idea!
there is https://github.com/semperos/clj-webdriver I used to some extent, but now it says that its unmaintained
i'm curious how working with the selenium java driver feels... might livestream it. need to test out my http://livecoding.tv set up
we'll give it a shot. https://www.livecoding.tv/notanon/
I used the webdriver for two years now and then, there were always some problems regarding browser, but the htmlunit driver worked all the time
htmlunit is said to not have such a good javascript support, you would need a browser for that.
I have used the clj-webdriver thing; I would second trying to use the Java version directly
at one point there was a taxi API that was really great and then it was removed in favor of a new, shinier API that never actually got written
although, if the page renders in JS... does it give you the original html (like a blank div) or the source needed to render after the JS has done its magic?
good question. probably the first … http://stackoverflow.com/a/15531471/202538 gives another way:
elem = driver.find_element_by_xpath("//*")
source_code = elem.get_attribute(”outerHTML")
and as long as you don't have a weird classpath setup, which if you are running a repl from boot or lein you likely won't, they will most likely work
you can actually add jars in a way that is visible to code running in the repl without support from boot or lein, the main thing they bring to the table is maven autodownloading hocus pocus