Fork me on GitHub
#beginners
<
2020-03-27
>
johnj00:03:47

curious, what's wrong with cheshire?

johnj00:03:07

or data.json

ghadi00:03:11

data.json is fine, cheshire incurs a dependency (jackson) that is extremely problematic

ghadi00:03:43

Probably The most frequent dep compatibility issue in large apps

johnj00:03:32

k, guess clj-http has the same issue with its dependency

johnj00:03:56

has anyone tried to use the new java http client directly? how well does it lends itself to the task?

hiredman01:03:27

I suspect it would be pretty good, but it is hard to displace very entrenched libraries

hiredman01:03:36

At one point I created a stripped down version of clj-http that just used urlconnection (part of the jre) and I suspect something similar on the new http client would be good

hiredman01:03:21

But it might be a useful inflection point to ask if a new interface would be better, the new http client offers new features like websockets which clj-https API isn't great for, same for some new http2 features

johnj01:03:59

yeah, writing a new library is probably a lot effort since just copying the clj-http API on top the built-in client is not a good idea as you said

johnj01:03:22

everyone is going to have their own little wrapper for their use case

jlmr07:03:48

Hi! If you have created a protocol and want to define something that implements it, when do you use reify and when to use defrecord?

Jakob Durstberger07:03:46

> While deftype and defrecord define named types, reify defines both an anonymous type and creates an instance of that type. The use case is where you need a one-off implementation of one or more protocols or interfaces and would like to take advantage of the local context. In this respect it is use case similar to proxy, or anonymous inner classes in Java. https://clojure.org/reference/datatypes#_reify So use reify when one want an anonymous implementation of a protocol. Hope this helps

Stas Makarov08:03:56

What's [C in (type (char-array "3"))? Why can't I do (conj (char-array "2") \j) ? (getting "[C cannot be cast to clojure.lang.IPersistentCollection") And what should I do instead if I want to add some char to the end of the result of char-array?

hindol08:03:22

That's the symbol for Java primitive char array.

hindol08:03:52

conj cannot work with Java's array types.

hindol08:03:23

Stick to Clojure's vector for all your array needs.

Stas Makarov08:03:15

Thank you! Is there any better way to create a vector of char-digits from a number? Right now I'm doing (char-array (str (count some-countable-thing)))

hindol09:03:05

What does the count do?

Stas Makarov09:03:33

I probably want vec ..

👍 4
hindol09:03:54

(into [] "ABC")

hindol09:03:43

Even simpler, (vec "ABC").

👍 4
Phil Hunt11:03:58

Is Heroku a reasonable first choice for deploying some Clojure / Clojurescript web apps?

teodorlu12:03:17

I'd say yes. I was quite happy with my Dokku[1] setup after a while, but if I were to go back, I'd just use Heroku. Caveat: I don't have a ton of Ops experience. [1]: http://dokku.viewdocs.io/dokku/

Phil Hunt12:03:18

OK thanks. I do have a fair bit of AWS experience, but it seems like it’d be a distraction from Clojure to go that route.

lepistane12:03:52

netlify is option also

hindol12:03:31

@U45SLGVHV Can I deploy Clojure code to Netlify? Thought it's just for static sites.

lepistane12:03:28

@UJRDALZA5 i havent tried it i can't find example of clojure https://medium.com/ampersandas-clojure-thing/how-to-publish-clojurescript-application-to-netlify-for-free-c7d148afaa64 this is from quick google search guide for cljs it's not only static, i saw interactive apps with cljs on there https://www.netlify.com/blog/2015/09/08/netlify-news-no.-4/ it should be possible 🙂

hindol12:03:55

Okay thanks. I am looking for a service to host frontend and backend together.

CarlaD12:03:50

@Here does anyone have any experience with the java,jdbc library, and doing a dryrun of a db query? I am wanting to do a dryrun but am not sure the library supports it.

hindol12:03:55

Think people are using next.jdbc now.

CarlaD12:03:37

Unfortunately I'm at the mercy of a legacy codebase

CarlaD12:03:39

Though looking at the docs I'm not sure next.jdbc has a dryrun option either...

lispyclouds12:03:37

@carladrago maybe running your commands within a BEGIN transaction and ROLLBACK at the end?

ghadi13:03:18

what would a dryrun of a query do?

CarlaD13:03:22

A 'pretend' query. It's for making sure the query does what you want it to before you actually run it.

ghadi13:03:25

I don't understand still, what does it return?

Alex Miller (Clojure team)13:03:08

is it just like adding a LIMIT 0 to get back the result set metadata?

hindol13:03:59

No, I think dry run is about reporting "If you ran this query, it will delete/modify 100 rows" without actually deleting/modifying. Also validates the query.

4
ghadi13:03:07

queries don’t delete things

ghadi13:03:17

They query

Matthew Curry13:03:54

They mean query in the larger sense, not just SELECT.

4
ryan echternacht15:03:09

I have a collection of filter functions (fns to be used with filter) if I call (filter filter-fn1 (filter filter-fn2 coll)), I get the result I expect but I can’t find a scalable way to combine filter-fn1 and filter-fn2 into a thing so I can just do (filter combined-filters coll). I thought I should just be able to comp them, but that doesn’t seem to work (just returns no items). suggestions?

Kelsey Sorrels15:03:21

Have a look at every-pred

ryan echternacht15:03:02

thanks @aaron-santos, that worked perfectly

👍 4
ryan echternacht15:03:23

one other q, is the best way to use this with my list of filter-fns (apply every-pred filter-fns) ?

ryan echternacht15:03:42

so all in all, (filter (apply every-pred filter-fns) coll)

Jakob Durstberger15:03:57

Looks good to me 🙂

ryan echternacht15:03:18

I ended up with (filter (apply every-pred (map make-filter-fn filters)) cards) which is great. Is that “too much” for 1 line? I’m used to the OO days where I’d probably break that up a bit

delaguardo15:03:30

you can use transducers for that

(into [] (comp (filter filter-fn-1)
               (filter filter-fn-2))
      collection)

ryan echternacht15:03:45

I expect to have a variable amount of filters (which are maps I need to convert to fns with make-filter-fn). what would it look like then?

delaguardo15:03:20

(into [] (make-filter-tx filters) collection) where make-filter-tx is a function returning transducer assebled from filters

ryan echternacht16:03:44

thanks, ill give that a shot

Eric Scott18:03:05

So this is neat:

> #inst "2020-03-27"
#inst "2020-03-27T00:00:00.000-00:00"
>
But then
(str *1)
"Thu Mar 26 17:00:00 PDT 2020"
How can I get it to render just "2020-03-27T00:00:00.000-00:00"?

hiredman18:03:34

(str (.toInstant *1))

Eric Scott18:03:21

Cool! Thanks!

Bill Phillips21:03:30

I’m working with a library that is emitting some output that I think would be useful through clojure.tools.logging. How can I find or redirect that output to somewhere I can read it?

Bill Phillips21:03:24

I found with-logs, but what about logger-ns? I’m not even sure what that is. It seems like I’d want an instance of that that would just write out and err to stdio, but how to build one?

Bill Phillips21:03:09

is that just a string?

ataggart21:03:20

That can work.

Bill Phillips21:03:33

Ahh, I think I’ve got it. It looks like it has to do with my logging level not being verbose enough; log/debug isn’t emitting anything. I’ll see if I can’t figure out how to change that

ataggart21:03:51

What logging implementation are you using?

Bill Phillips21:03:52

Whatever the default is. I don’t really need fancy logging yet, but this library I’m using uses it

ataggart21:03:38

So, if you aren't setting the system property, and don't have any of the first 4 implementations on your classpath, then you're using java.util.logging

ataggart21:03:39

This will avoid a lot of complications.

ataggart21:03:56

And stick this on the classpath, e.g., in the resources directory of your project. Set rootLogger.level to whatever global logging level you prefer.

Bill Phillips21:03:27

Thanks. I was wondering if I could get away without all that…. apparently not

ataggart21:03:33

It's a one-time cost.

Bill Phillips22:03:28

I wasn’t able to get log4j configured to my satisfaction… but I was able to read the logs I wanted to read with a hack:

(def stdout-logger 
  (reify log-impl/Logger
    (enabled? [_ _] true)
    (write! [logger level throwable message]
      (println level ":" message ":" throwable))))
(binding [log/*logger-factory*
          (reify log-impl/LoggerFactory 
            (get-logger [_ _] stdout-logger)
            (name [_] "stdout factory"))]
  (etaoin/chrome)))

ataggart02:03:14

Oh, I took your original request to mean the library wasn't using logging (e.g., was using println), and you wanted direct its output to logging.

Bill Phillips04:03:20

I think your advice would’ve gotten me there anyway! As I was cleaning up, I realized I had forgotten to save my project.clj with all the log4j deps… d’oh!

Bill Phillips04:03:40

Still getting used to the new editor

acim121:03:48

Is there a convenience method for converting false to nil ? I've got a situation where I want to do something like (and a b c) but if a gives false I really want nil there (correction: "and" not "or" function)

acim121:03:29

^^yah, sorry, mistyped

noisesmith21:03:30

oh, it's harder with and

noisesmith21:03:12

({false nil} x x) replaces false with nil and otherwise returns x

👏 4
noisesmith21:03:55

(ins)user=> ({false nil} false false)
nil
(ins)user=> ({false nil} :a :a)
:a

Alex Miller (Clojure team)21:03:48

(or (and a b c) nil)

💯 8