Fork me on GitHub
#clojure
<
2017-01-02
>
qqq00:01:16

is there a way to, at runtime, get the arg list, of an anonymously defined function ?

qqq00:01:48

(magic (fn [] )) => 0 (magic (fn [a] ) => 1 (magic (fn [a b]) => 2

qqq00:01:02

I need magic to be a function, not . amacro

henriklundahl01:01:08

@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)))))? 🙂

qqq01:01:52

@henriklundahl : technically correct, not the solution I had in mind, also bad if any of the functions do rm -rf /

gfredericks01:01:35

Also not technically correct since you don't know for sure where the exception was thrown from

qqq02:01:35

(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 ?

qqq04:01:39

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 ?

athinggoingon05:01:39

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.

seancorfield05:01:25

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?

qqq07:01:25

is there a way to inject comments into the output of macros?

qqq07:01:42

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

kana07:01:50

strings? (do "comment" value) will return value, but with "comment" in code

qqq07:01:55

yeah, that works; thanks!

qqq08:01:14

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?

jrychter08:01:56

@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.

qqq09:01:36

@jrychter : thanks http-kit recommendation, seems great from my own research; might just use raw ws instead of sente

jrychter09:01:06

@qqq: I'd recommend sente, unless you really feel comfortable with websockets. I found it very convenient, especially AJAX fallback.

mpenet09:01:43

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)

mpenet09:01:09

doesnt' sente supports pluggable backends now?

kana09:01:29

+ for aleph

mpenet09:01:35

from aleph readme: Supported servers: http-kit, Immutant v2+, nginx-clojure, node.js, Aleph cool stuff

qqq09:01:58

whoa; what's nginx-clojure, I have to look into this

jrychter09:01:58

@mpenet: any quick hints on why I should switch from http-kit to aleph?

mpenet09:01:45

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

mpenet09:01:12

most of the alternative are in general more tested, robust

mpenet09:01:32

jetty9 is rock solid, so is aleph it seems

mpenet09:01:08

(I am talking under decent load)

mpenet09:01:39

the sales pitch of http-kit is appealing, but I am not sure I'd build a critical thing with it anymore

mpenet09:01:49

I am actually sure I wouldn't

jrychter09:01:27

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 🙂

mpenet09:01:17

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

mpenet09:01:49

I also don't think http-kit does anything to support backpressure with WS for instance, which can end up causing some nasty problems

mpenet09:01:59

then again my experience is from a while ago, maybe the new maintainer(s) fixed some of these

jrychter09:01:03

@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.

jrychter09:01:33

Anyway, thanks for the recommendation — I don't really mean to argue, just pointing out that every piece of software likely has bugs.

nooga09:01:23

aleph is awesome, not only for websockets

nooga09:01:19

I’ve written custom proxies/tunnels with aleph+manifold+gloss and they push gigs of data daily without any issues

nooga09:01:24

for a year

qqq16:01:59

okay; so summarizing all the advice from last night: don't use http-kit, use aleph?

qqq16:01:37

#?(: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 folding

fabrao16:01:20

Hello 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 trying

qqq16:01:20

would it be possible to use shorter names, like :a and 1 instead? it's hard to see wht the transform is doing

fabrao16:01:02

tried with group-by, but it´s only count

qqq16:01:18

I meant the weird names is mkaing it hard to see what the transform is doing

qqq16:01:29

is the names were :a 😛 :c 1 2 3, it'd be easier for us to help you

val_waeselynck17:01:21

@fabrao I'll give you that this one is tricky...

val_waeselynck17:01:42

@fabrao you may want to look into Specter 🙂

borkdude17:01:39

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

borkdude17:01:17

Maybe it’s much slower?

val_waeselynck17:01:01

@borkdude yeah, bean is slow 😕

joshjones17:01:11

@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 😉

benfleis18:01:54

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.

jgh18:01:04

is there an active alternative to clauth? Looking for OAuth2 server implementation.

seancorfield18:01:54

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.

bfabry18:01:33

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

bfabry18:01:05

personally I think I like your first one

qqq18:01:25

(keep identity [e]) is 2 chars shorter

qqq18:01:30

(compared to filter)

rickmoynihan18:01:13

ahh you want it kept as a hashmap

seancorfield19:01:51

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).

rickmoynihan19:01:51

((if (nil? e) vec vector) e)) is a bit too baroque

qqq19:01:44

(defn maybe-to-list [x] (if x [x] [])) (maybe-to-list e)

qqq19:01:55

clearly this is a function that will be used in the future

gfredericks19:01:27

(some-> x vector)

gfredericks19:01:42

Is almost the same thing

seancorfield19:01:10

That’s why I had to have (or … []) around it 🙂

hiredman19:01:48

user=> (keep identity [nil])
()
user=> (keep identity [{:foo 1}])
({:foo 1})
user=> 

hiredman19:01:04

which is the same as the filter/remove above, just with keep, which is slightly different

seancorfield19:01:02

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).

grav20:01:06

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?

sveri20:01:55

@grav when hearing about scraping and clojure enlive is the first that comes to my mind.

notanon20:01:13

i would skip the xml part and use enlive to just select the nodes im interested in

grav20:01:28

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?

notanon20:01:00

correct, you will need phantom or selenium/webdriver to render a dynamic html page

grav20:01:08

Ah okay. But that might make sense to slit those two tasks.

notanon20:01:40

that's how i would approach it. i like to break everything up into single data transformations

grav20:01:46

I’ll definitely look into Enlive. Thanks for the pointers

grav21:01:10

Yes, that makes sense. I guess doing everything in Clojurescript in PhantomJS might also be a performance bottleneck

notanon21:01:20

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

notanon21:01:57

there are java webdriver libraries, probably the best way to do it

notanon21:01:11

let me do some googling, havent tried it before

grav21:01:21

Great, thanks!

notanon21:01:11

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"]

notanon21:01:44

i'm not sure if there is a clojure wrapper around it already (that probably is... there's always wrappers around commonly used stuff)

notanon21:01:15

but depending on how much of the selenium api you'll need, it may or may not be worth the bother

grav21:01:11

Nope, not familiar with it - great with the links! I think doing it all in jvm sounds like a cool idea!

notanon21:01:38

best of luck. let us know how it turns out

grav21:01:10

Will do! Thanks again 🙂

sveri21:01:22

there is https://github.com/semperos/clj-webdriver I used to some extent, but now it says that its unmaintained

notanon21:01:12

i saw that, the unmaintained made me worry 🙂

notanon21:01:15

i'm curious how working with the selenium java driver feels... might livestream it. need to test out my http://livecoding.tv set up

sveri21:01:10

I would watch 🙂

sveri21:01:45

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

notanon21:01:26

better than the native driver?

hiredman21:01:44

htmlunit is a nice alternative to webdriver and similar

hiredman21:01:05

I reach for it first when scraping

notanon21:01:15

cool. ill try it out

notanon21:01:38

does it support SPAs/etc?

sveri21:01:25

htmlunit is said to not have such a good javascript support, you would need a browser for that.

lvh22:01:33

I have used the clj-webdriver thing; I would second trying to use the Java version directly

lvh22:01:53

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

grav22:01:53

@notanon great with the screen cast. definitely going to try it out myself.

grav22:01:27

Oh, there’s also driver.getPageSource() apparently

notanon22:01:25

that would have been good to know 🙂

notanon22:01:20

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?

grav22:01:19

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")

bcbradley23:01:29

is it possible to require a library at the repl?

bcbradley23:01:41

say i'm in boot or lein, and I want to require clj-tagsoup, can I do that?

hiredman23:01:53

he is asking about adding a jar to the classpath

hiredman23:01:53

in fact it isn't a yes/no question

hiredman23:01:12

but boot can do it, and there are lein plugins to do it

hiredman23:01:24

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

bcbradley23:01:33

i'm just goofing around on the repl

bcbradley23:01:56

i've got a forum i like to frequently visit and it has a "members" page

bcbradley23:01:01

its a table of members with various stats

bcbradley23:01:06

i want to turn it into a graphic

bcbradley23:01:16

so i opened up a repl and started with slurp

bcbradley23:01:26

but its in html, and that isn't really what i want to work in

bcbradley23:01:35

so i figured a hiccup like syntax would be easier to work with

hiredman23:01:22

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

bcbradley23:01:47

how would I require this library then?

bcbradley23:01:59

i'm not terribly concerned about whatever hocus pocus has to happen

bcbradley23:01:03

this is just a plaything

bcbradley23:01:41

@notanon i know of the various libraries that would be helpful

bcbradley23:01:52

what i don't know is how to tell the boot repl or lein repl to require them

hiredman23:01:00

well if you are in a lein repl, you need to have a plugin that does it, which I dunno, I don't use one. I think alembic was the name of one

bcbradley23:01:24

how would i require alembic if i can't require some other random library?

bcbradley23:01:27

at the repl i mean

notanon23:01:29

do you already have the jars added to lein or boot?

bcbradley23:01:50

i was hoping for remote maven magic