clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
allenj12 2021-02-11T04:03:58.470500Z

removed my message for a more relevant channel

zendevil 2021-02-11T04:11:40.470600Z

This is the create-subscription function:

(defn create-subscription [req]
  (prn "request is " (:params req))
  (prn "payment method is " (:payment-method-id (:params req)))
  (let [customer (cust/create {"email" (:email (:params req))
                               "payment_method" (:payment-method-id (:params req))
                               })
        subscription (esub/create customer {"items"
                                            [{"price" (:price-id (:params req))}]
                                            "expand" ["latest_invoice.payment_intent"]})]
    (prn "subscription is " subscription)
    )
  (req-res/response "response"))

zendevil 2021-02-11T04:11:47.470800Z

and the error is in the cust/create

zendevil 2021-02-11T04:12:38.471Z

in the docs under create a customer, thereโ€™s a payment_method parameter @dsp

zendevil 2021-02-11T04:20:22.471300Z

which is what I have as well

zendevil 2021-02-11T04:42:03.472200Z

I have the following question posted in clj-http: https://clojurians.slack.com/archives/C8860D6BS/p1613018229002500 Your help is much appreciated!

dpsutton 2021-02-11T04:55:44.472600Z

if that's real data you might have a bit of a headache

zendevil 2021-02-11T04:58:09.473400Z

@dpsutton what do you mean by real data? Itโ€™s key value pairs where values are strings

seancorfield 2021-02-11T05:08:21.473800Z

He means that :basic-auth string I think...

seancorfield 2021-02-11T05:09:29.474300Z

That auth seems real (although the customer ID seems invalid)

seancorfield 2021-02-11T05:11:15.475600Z

You might want to delete that message @ps although at this point it's probably been archived to the logging site -- not sure if it respects deletes. The Zulip bot does respect deletes so it will at least remove it from there.

seancorfield 2021-02-11T05:14:28.477Z

The #clj-http channel at least is not logged/archived as far as I can tell so at least it's only in this channel -- and Zulip doesn't copy the body of shared messages. Not sure if logbot does.

KJO 2021-02-11T13:06:47.479500Z

@ps You could try :body "customer= cus_IvNWjfw1q2clxS" in the post request. Itโ€™s equivalent to --data-raw option in curl IIRC.

zendevil 2021-02-11T13:56:09.479900Z

Thanks

takis_ 2021-02-11T16:37:21.481900Z

Hello i am testing a maven project,where Clojure code is also inside the maven. It works fine , but i want to use a class from Clojure code gen-class , and it said it cant find it

takis_ 2021-02-11T16:37:37.482300Z

in lein, i did :aot but in maven i dont know what to do to find it

takis_ 2021-02-11T16:40:25.482900Z

normal call clojure from Java works IFn etc , but i want a class

alexmiller 2021-02-11T16:40:37.483100Z

you can use https://github.com/talios/clojure-maven-plugin for that

alexmiller 2021-02-11T16:40:47.483500Z

it hooks into the compile phase to compile clojure code

takis_ 2021-02-11T16:41:42.484100Z

it does it automatically? or i have to set settings

alexmiller 2021-02-11T16:42:01.484800Z

you'll have to configure your pom to make that happen

takis_ 2021-02-11T16:42:18.485200Z

thank you i will try it now ๐Ÿ™‚

alexmiller 2021-02-11T16:42:31.485400Z

the readme has more info

dpsutton 2021-02-11T17:36:16.486300Z

anyone know of a good transducer that kinda sorts? Ideally holds onto the largest N items by some metric?

dpsutton 2021-02-11T17:36:54.486700Z

and not sorts but just retains the largest values, not necessarily sorted

dpsutton 2021-02-11T17:38:40.487700Z

(transduce (biggest 5 identity) conj [] (range 30) would build up a collection no more than five at any point in time as it reduced the collection

borkdude 2021-02-11T17:42:35.488100Z

@dpsutton I think you can look at a transducer like distinct and then adapt it

dpsutton 2021-02-11T17:44:01.488400Z

good point. thanks @borkdude

alexmiller 2021-02-11T17:44:46.488700Z

you could probably use https://github.com/cgrand/xforms window transducers

dpsutton 2021-02-11T17:45:37.489500Z

yeah i'm not familiar with his excellent library so i was hoping it would ring a bell as something already done with a proper immutable min heap

dpsutton 2021-02-11T17:46:46.489800Z

by which i mean thanks for pointing me towards window!

alexmiller 2021-02-11T17:47:00.490Z

lots of other useful things there too

dpsutton 2021-02-11T17:47:58.490300Z

yeah. i've never delved in and its probably time. thanks

2021-02-11T18:10:08.493200Z

I need a TCP client library. I just want to send bytes and receive bytes. Aleph has exactly the kind of interface I'm looking for:

(def client @(aleph.tcp/client {:host host :port port}))
(manifold.stream/put! client (msg->bytes mx))
(bytes->str @(manifold.stream/take! client))
but I'm wondering if there are any lighter weight libraries out there (or even a gist?)

vemv 2021-02-11T18:19:28.494900Z

sockets appear to form part of the https://github.com/clj-commons/byte-streams abstraction. Not very familiar with it though

alexmiller 2021-02-11T18:29:36.495400Z

the java socket stuff is pretty easy to use via interop, you don't really need a library for it

๐Ÿ‘ 2
๐Ÿ’ฏ 1
โ˜๏ธ 1
alexmiller 2021-02-11T18:33:22.496700Z

on one side you mostly just create a ServerSocket and .accept on it, which gives you a connection, which has an input/output stream on the other, create a new socket and use its input/output stream

alexmiller 2021-02-11T18:33:36.497Z

pretty basic example: https://www.baeldung.com/a-guide-to-java-sockets

2021-02-11T18:37:05.499Z

cool I'll give it a shot with sockets. I've used them a bit before but this time I got hung up on some (java) example code using Nio socketchannels and was trying to do it in that way which maybe has a bit more of a learning curve.

alexmiller 2021-02-11T18:55:55.000500Z

that's a couple more steps (but opens some new options)

phronmophobic 2021-02-11T18:58:13.000700Z

I'm writing a clj wrapper for https://bitbucket.org/chromiumembedded/cef/ (cef) and am trying to figure out the best way to make it consumable as a library. The cef framework by itself is 80MB compressed and ~220MB uncompressed which seems too large to include in a library jar. Currently, I'm putting everything except the cef framework in the library jar and including a function that will download/extract the framework if it doesn't exist on the local file system. Is there a better way to handle this?

borkdude 2021-02-11T19:17:04.001200Z

@smith.adriane I think that's a good tradeoff

๐Ÿ‘ 1
borkdude 2021-02-11T19:17:47.001600Z

This will maybe also allow your tool to upgrade CEF itself without upgrading the jar, might add some flexibility.

borkdude 2021-02-11T19:18:25.002100Z

Or if users already have it, they could maybe set some env variable to indicate where it is

phronmophobic 2021-02-11T19:20:03.003400Z

supporting env variables would make a lot of sense. Currently, I only allow the consumer to specify the target dir, but supporting env variables at some point would also be good.

dpsutton 2021-02-11T21:09:17.005100Z

was asking about a biggest-by transducer earlier but realized i needed a reducing function for this actually. Does anything about this stand out as problematic?

(fn queue-accumulator
  ([] (PriorityQueue. 30 cmp)) ;; custom comparator
  ([^PriorityQueue q]
   (loop [acc []]
     (if-let [x (.poll q)]
       (recur (conj acc x))
       acc)))
  ([^PriorityQueue q item]
   (if (>= (.size q) threshold)
     (let [smallest (.peek q)]
       (if (pos? (.compare cmp item smallest)) ;; custom comparator
         (doto q
           (.poll)
           (.offer item))
         q))
     (doto q
       (.offer item)))))

Ed 2021-02-12T14:15:31.032700Z

@dpsutton did you find a solution you were happy with for this? ... maybe something like this?

(defn keep-group [f init]
  (fn [rf]
    (let [g (volatile! init)]
      (fn
        ([]
         (rf))
        ([r]
         (rf (reduce rf r @g)))
        ([r i]
         (vswap! g f i)
         r)))))

(defn largest-n [n]
  #(let [group (conj %1 %2)] (if (< n (count group)) (disj group (first group)) group)))

(comment

  (into [] (keep-group (largest-n 5) (sorted-set)) (range 10))

  )

Ed 2021-02-12T14:17:51.033Z

I realise it's pretty similar to what you had with the mutable collection ...

dpsutton 2021-02-12T15:10:50.033500Z

yeah. and it doesn't make much sense to do so much accumulation in the transducer. it clogs the whole pipeline until you're done which feels a bit presumptuous of a transducer

dpsutton 2021-02-12T15:11:09.033700Z

also there's no comparisons in yours. so it would just be a huge volatile in a transducer chain

Ed 2021-02-12T15:26:51.034300Z

it's in the largest-n fn ... which limits the number of things in the volatile to n things ... right??

Ed 2021-02-12T15:33:22.034900Z

it's doing the comparison by putting the data into a sorted set (which I guess could be a sorted-set-by ... and it's dropping the first one from the set if the count is larger than the n we give to largest-n ... so there's only 5 things in the volatile ... but in the same way you can't return the first result till you've reached the end when sorting, you can't do that here ... right?

dpsutton 2021-02-12T15:34:04.035900Z

oh i missed that part. i somehow only saw the keep group bit

Ed 2021-02-12T15:34:39.036100Z

๐Ÿ‘