Fork me on GitHub
#clojure
<
2017-08-04
>
yonatanel01:08:01

@lxsameer You will have a problem with middlewares that modify responses if you want to return deferreds from you handlers

josh_tackett03:08:15

anyone familiar with hcitool lescan?

bradcypert08:08:30

Any recommendations on a Clojure library for Kafka integration?

lxsameer08:08:59

@yonatanel please do tell, So on top of my head you need to deref the response and generate a new one in middlewares right ?

yonatanel14:08:03

Well yeah but once you deref you are already blocking. You need to fork the middleware where appropriate if you want not to block.

lxsameer14:08:31

hmmm so it's tricky

lxsameer14:08:37

any other heads up ?

yonatanel15:08:08

I think its logging is silent in comparison with jetty. I can't remember how I configured it.

misha09:08:48

it turns out I can't do (transient (list)), can I?

misha09:08:56

or is looping and consing over just (list) (need to prepend elements) good enough?

leonoel09:08:20

@misha you're right. transients exist because sometimes you don't need intermediate objects so you improve perf by not constructing them in case of a linked list, intermediate objects are part of the final structure, so basically there's nothing to improve

misha09:08:31

@leonoel makes sense, than you. do you happen to know which is faster/preferred from any pov: (list) or '()?

leonoel09:08:59

I doubt there is any difference at all

pwrflx11:08:49

how can I have a spec that makes sure the value is a datetime? (a string with an iso formatted datetime value in it). With a regex or is there something better?

noisesmith13:08:45

@leonoel btw you don't need to use '(), it accepts ()

bcbradley13:08:41

I've got an exercise I can't figure up an elegant solution for: Let S be a sequence of sets. Compute R the sequence of sets such that each element of R is equal to the element of S at the same position, but also shares no elements with any sets that exist before that position in S.

noisesmith13:08:05

@bcbradley so does this mean taking the subset of each set in the series that consists of the elements not seen in any of the sets so far?

bcbradley13:08:51

@noisesmith yeah, almost-- "not seen in any of the sets so far (EXCEPT the current one)"

bcbradley13:08:11

otherwise it would just be empty sets all the way

leonoel13:08:14

(defn f
  ([sets] (f sets #{}))
  ([sets seen]
   (when-let [[set & sets] (seq sets)]
     (cons (into #{} (remove seen) set)
           (lazy-seq (f sets (into seen set)))))))

bcbradley13:08:50

thats a pretty nice way to do it

bcbradley13:08:42

i wonder how others might try it, there seem to be bunches of ways; i've spent a lot of my free time recently just trying to come up with new ways xd

leonoel13:08:52

is it an elegance contest ?

bcbradley13:08:11

yeah, but thats obviously subjective

bcbradley13:08:25

it might also be interesting to have a performance contest

bcbradley13:08:32

its just a fun problem tbh

noisesmith13:08:47

+user=> (:acc (reduce (fn [{:keys [acc seen] :as state} s] (-> state (update :acc conj (set/difference s seen)) (update :seen into s))) {:acc [] :seen #{}} [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}]))
[#{1 2} #{3} #{4 5} #{}]

noisesmith13:08:04

the lazy-seq version is nicer

bcbradley13:08:26

yours isn't terrible though, its very concise! 🙂

the-kenny13:08:46

hmm one could also whip up something using reductions: (map (fn [r seen] (set/difference r seen)) r (reductions into #{} r)) (untested)

leonoel13:08:29

transducer version :

(defn xf [rf]
  (let [seen (volatile! #{})]
    (fn
      ([] (rf))
      ([r] (rf r))
      ([r s]
       (let [xf (remove @seen)]
         (vswap! seen into s)
         (rf r (into #{} xf s)))))))

noisesmith13:08:33

might as well show the prettier version of mine

+user=> (->> [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}]
             (reduce (fn [{:keys [acc seen] :as state} s]
                         (-> state
                             (update :acc conj (set/difference s seen))
                             (update :seen into s)))
                     {:acc [] :seen #{}})
             (:acc))
[#{1 2} #{3} #{4 5} #{}]

Phil13:08:56

Clojuredocs question (I don't know whom to ask really): a number of pages appear to only work with clojure.data.xml but the examples use (or require) clojure.xml. The codes appears wrong on pages like this. Should this be edited or is it correct as-is? e.g. https://clojuredocs.org/clojure.zip/edit

bcbradley15:08:28

i really like how short it is

bcbradley16:08:15

dang that is the most elegant one yet

drowsy16:08:44

not the most efficient though

bcbradley16:08:01

i feel like leonel's is probably the most efficient

bcbradley16:08:40

well i take that back, maybe astro's is

noisesmith16:08:11

I have a hunch astro’s would be if it used (into #{} (remove …) …) instead of remove / set

bcbradley16:08:45

this was a really fun problem 🙂

bcbradley16:08:50

lots of variety in solutions

leonoel16:08:55

it's actually the same solution as @the-kenny , once cleaned up

leonoel16:08:08

just figured out that set/union and set/difference don't leverage transients

noisesmith16:08:26

yeah, I’d use into instead of set/union in 100% of cases

noisesmith16:08:49

and actually into with a remove transducer can easily replace set/difference

noisesmith16:08:48

(set/difference a b) becomes (into #{} (remove (partial contains? b)) a)

drowsy16:08:41

but doesn't reductions defeat the purpose of using transients in the set/union case?

drowsy16:08:13

I mean with reductions you can't efficiently use transients as every steps needs to be persisted

kingcode17:08:22

@bcbradley I think you meant your problem to state that “…each element of R contains all and only those elements of the lement of S at the same position which are not seen in any sets that exist before that position in S”? Otherwise e.g. in noisesmith’s solution example you should expect [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}] => [#{1 2}] since all sets of R must be equal to their respective positioned elements in S

noisesmith17:08:11

@kingcode right - I read it that way at first but the problem statement didn’t seem coherent

noisesmith17:08:19

so I made some assumptions

kingcode17:08:30

Thanks for confirming…I think all other solutions do the same?

bcbradley17:08:42

your are right! yeah everyone assumed as you put it

noisesmith17:08:47

yeah - they should all calculate the same way

kingcode17:08:06

@bcbradley I think this would be a nice candidate to http://4clojure.com

kingcode17:08:42

I’ll try my own code-golfing on that… 🙂

bcbradley17:08:38

@kingcode i sent them a message on freenode

kingcode17:08:52

@bcbradley Great…hopefully they will respond. I did submit a “Towers of Hanoi” candidate months ago, but never saw it added, or heard from anyone.

kingcode17:08:30

My solution is similar to noisesmith: (fn [sets] (-> (fn [[r seen] s] [(conj r (clojure.set/difference s seen)), (into seen s)]) (reduce [[] #{}] sets) first))

bcbradley17:08:19

@kingcode you can surround your code with ` (triple backtick) to get it to format properly

kingcode17:08:47

Still new to slack…

kingcode17:08:05

How does one enter a new line without triggering a Send?

bcbradley17:08:12

shift + enter

kingcode17:08:18

OK..thanks!

kingcode17:08:13

Sorry for the verbosity, making my code snippet pretti..er:

(fn [sets]
  (-> (fn [[r seen] s]
        [(conj r (clojure.set/difference s seen)),
         (into seen s)])
      (reduce [[] #{}] sets)
      first))

bcbradley17:08:53

thats a very creative way to do it

bcbradley17:08:57

i wouldn't have thought of that approach!

kingcode18:08:30

It’s not very compact/elegant, but probably fast enough…am studying others’ and learning.

kingcode18:08:26

Great problem, thanks for sharing - what name did you give it on http://4clojure.com? I will watch for it…

bcbradley18:08:06

I didn't think to give it a name, I just described the problem and example input and output data in a message on freenode

bcbradley18:08:41

clojure is so compact and elegant as a language there are probably hundreds of ways to solve even a problem the average solution length of which 8 lines; i think there is a ton to learn from simple problems like that one, regardless of whether you are super new to clojure or super experienced with it

bcbradley18:08:23

for instance, drowsy's approach involves a fairly novel use of reductions with sets that i haven't seen before

kingcode18:08:48

aw OK….you might want to register/login and to the “Submit a problem” tab on http://4clojure.com itself..

bcbradley18:08:03

oh sorry i didn't see that xd i'll do that now

kingcode18:08:21

Yes indeed, problems in the small is a fantastic way to improve….thanks!

kingcode18:08:52

Indeed, wasn’t aware of reductions myself, will check it out 🙂

bcbradley18:08:28

hrm i don't see that tab

kingcode18:08:46

Once logged in, you should see two navigation rows at the top. The second row should have ‘Account Settings’, ‘Leagues’, and ‘Submit a Problem’..

bcbradley18:08:24

not for me, but you are free to submit the problem if you'd like (or anyone else, you don't have to bother giving me credit-- name it whatever you want :d)

csm18:08:55

what’s the correct way to place a async/dropping-buffer in a async/pub and a bunch of async/subs?

dadair18:08:25

quick Q: How can one build vars in a macro? I have a spec that I want to turn into a symbol within a macro (e.g.: (defaction ::some-spec ..) should result in a function (defn make-some-spec ..) but not sure how to go about constructing the make-some-spec symbol

dadair18:08:57

... it's always when you finally type something out that you figure out the solution.. nevermind >.<

noisesmith18:08:43

@dadair haha - (comp symbol name) is an elegant choice

dadair18:08:59

yep that was a quick "doh" moment

noisesmith18:08:04

err, I guess you need to use str in there too

csm18:08:01

I do know that if I place a dropping-buffer in all three places, I get a NoSuchElementException internally in core.async

noisesmith18:08:44

@csm put it on b, that way either a or c (or both) could be passed in by the code creating it

noisesmith18:08:18

which is a nice pattern, it lets consumers decide what transducers should be on a channel, etc. or how much buffering they need based on activity patterns

noisesmith18:08:20

b, the one in the middle, is the one that code would always own, so it’s the sensible place for things it specifically should define

csm18:08:47

the use-case is to partition a stream by a key, then to further partition/batch items via a transducer per sub

hiredman18:08:45

using the same buffer in multiple channels is a bad idea

csm18:08:24

ooohhhh..

csm18:08:36

the constantly was totally wrong, I get it

csm18:08:01

I definitely make that mistake a lot, thinking the body is evaluated each time

kingcode18:08:40

@bcbradley strange…perhaps you just need to submit a few exercises ‘ solutions? I’d be happy to submit it for you if you prefer.

bcbradley18:08:56

you can submit it if you'd like

kingcode18:08:17

OK…will do and give you credit whenever possible 🙂

manderson20:08:41

(every? keyword? [])
=> true
^^^ Seems counterintuitive to me… I would think this should be false (or nil). I suppose you could see it both ways, but if there are no elements then every element isn’t a keyword. I suppose it’s a not a big deal but wondering if others have the same intuition as me or if I’m crazy 🙂

tanzoniteblack20:08:20

I've always translated every? to mean that there are no values for which the predicate is not true. So this makes perfect sense to me. This might be akin to Stockholm syndrome though....

manderson20:08:22

I guess it depends on your perspective… like the blind men and the elephant. Anyway, it bit me this afternoon and thought I’d share.

val_waeselynck20:08:20

This is not Clojure - specific :) a lot of logical paradoxes would arise if this was not the case

manderson20:08:50

Do you have an example (genuinely curious)?

val_waeselynck21:08:19

A nice consequence of this is (= (every? p (concat coll1 coll2)) (and (every? p coll1) (every? p coll2))) for any 2 collections coll1 and coll2

manderson21:08:16

Ah, gotcha. Makes sense. Thanks @U06GS6P1N

manderson21:08:41

Thanks for the link @U0NCTKEV8 I’ll read it over. I figured there was a reason

eraserhd21:08:21

Hey, can't believe I haven't hit this before, is there something like swap!, except that it can return an extra value?

eraserhd21:08:09

like, [new-state other-value]... Or would I have to build that with compare-and-set!?

noisesmith21:08:14

you can write it yourself using compare-and-set!

noisesmith21:08:54

there’s also using refs and returning the relevant data from your transaction

noisesmith21:08:36

since caring about two values at once can be a sign that the values should be coordinated and that’s what refs are for

bschrag21:08:12

This was working two weeks ago, breaks today when I launch CIDER from within the project.

error in process sentinel: Could not start nREPL server: Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in central ()

Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in clojars ()

This could be due to a typo in :dependencies or network issues.

If you are behind a proxy, try setting the ’http_proxy’ environment variable.

Per , there has been no change in version number. No change to my files, either. Everything else here seems to be working fine, network-wise. And other dependencies load fine if I comment this one out. Ideas how to proceed?

noisesmith21:08:57

are you sure there isn’t a hidden typo? https://mvnrepository.com/artifact/org.clojure/math.numeric-tower - maven claims that 0.0.4 is available

hiredman21:08:46

(there is a typo)

noisesmith21:08:24

oh yeah - there’s one too many clojures in there

bschrag21:08:25

[org.clojure/clojure.math.numeric-tower "0.0.4"]

noisesmith21:08:35

remove the second “clojure”

bschrag21:08:33

Better, thanks!

drowsy22:08:34

I'm trying to make a lib out of a "predicates by example" functionality I regulary use. So any feedback is welcome: https://github.com/IamDrowsy/ebenbild/

bcbradley23:08:52

i like that it does one thing and only one thing

bcbradley23:08:04

a lot of libraries could learn a thing or two from that

drowsy23:08:05

I tried to keep it simple.

drowsy23:08:07

It's a bit opinionated as for example a String matches on inclusion.

drowsy23:08:26

And I thought about some extensions mechanisms, but settled with the opinions I need, as it's much simpler and you could always fallback to plain fns