Fork me on GitHub

curious, what's wrong with cheshire?


or data.json


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


Probably The most frequent dep compatibility issue in large apps


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


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


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


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


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


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


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


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


That's the symbol for Java primitive char array.


conj cannot work with Java's array types.


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


What does the count do?

Stas Makarov09:03:33

I probably want vec ..

👍 4

(into [] "ABC")


Even simpler, (vec "ABC").

👍 4
Phil Hunt11:03:58

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


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

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.


netlify is option also


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


@UJRDALZA5 i havent tried it i can't find example of clojure this is from quick google search guide for cljs it's not only static, i saw interactive apps with cljs on there it should be possible 🙂


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


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


Think people are using next.jdbc now.


Unfortunately I'm at the mercy of a legacy codebase


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


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


what would a dryrun of a query do?


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


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?


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.


queries don’t delete things


They query

Matthew Curry13:03:54

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

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


you can use transducers for that

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

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?


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


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


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


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


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


This will avoid a lot of complications.


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


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


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


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)


^^yah, sorry, mistyped


oh, it's harder with and


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

👏 4

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

Alex Miller (Clojure team)21:03:48

(or (and a b c) nil)

💯 8