babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2020-09-01T10:31:42.043100Z

I have a branch http-kit-client now in which I added the http-kit-client.

$ ./bb '(:status @(org.httpkit.client/get "<https://www.google.com>"))'
200
Only a 0.7MB increase for an http client. That doesn't seem too bad!

borkdude 2020-09-01T10:33:42.043900Z

I didn't get SNI working. When I did what the README said, I got a NPE:

$ clojure -A:bb-local "@(org.httpkit.client/get \"<https://www.google.com>\")"
{:opts {:method :get, :url "<https://www.google.com>"}, :error #error {
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [sun.net.util.IPAddressUtil textToNumericFormatV4 "IPAddressUtil.java" 49]}]

borkdude 2020-09-01T10:34:04.044200Z

Maybe @alekcz360 knows a proper solution to this?

borkdude 2020-09-01T10:34:40.044500Z

There are binaries in #babashka_circleci_builds for trying this out btw.

borkdude 2020-09-01T13:51:37.045600Z

I guess error handling with http-kit works by checking manually for :error ?

alekcz 2020-09-01T17:10:00.046500Z

@borkdude how do I include the SNI client? in bb

alekcz 2020-09-01T17:12:38.047600Z

./bb "(require '[org.httpkit.sni-client :as sni-client])
      (require '[org.httpkit.client :as client])
      (:status (binding [org.httpkit.client/*default-client* sni-client/default-client]
          @(client/get \"<https://www.google.com>\")))" 

borkdude 2020-09-02T07:20:37.058100Z

Thanks 🙏 I shared the article on Twitter. On the libraries page there is also a library for psql. Also we have a pod so you can directly use jdbc.next and honeysql with Postgres

kari 2020-09-02T12:50:18.059100Z

Ok. Good to know. I'll use the library support for sql next time!

borkdude 2020-09-02T12:52:15.059300Z

At one point I had the JDBC driver for PostgreSQL included in babashka, so you could use next.jdbc directly from babashka, but I wasn't sure if this was the right approach, since I maybe would have also include drivers for other databases and this would maybe bloat babashka. But it is still possible to compile babashka with postgres support using a feature flag as well. So, several options. But your basic approach is also valid, whatever works :)

borkdude 2020-09-01T17:37:01.048600Z

@alekcz360 That's already been done in babashka.impl.http_kit.clj

borkdude 2020-09-01T17:37:12.048800Z

At least, I tried, but it only works with JDK 1.8

borkdude 2020-09-01T17:37:56.049Z

Awesome! I'm going to read through it tonight when I'm back at the keyboard!

borkdude 2020-09-01T17:41:37.049600Z

@alekcz360 You can run this locally from the bb repo as follows:

clojure -m babashka.main "@(org.httpkit.client/get \"<https://www.google.com>\")"

borkdude 2020-09-01T17:41:41.049800Z

without compiling first

borkdude 2020-09-01T17:42:20.050200Z

afk for a while now

alekcz 2020-09-01T19:26:12.050500Z

@borkdude It worked when running locally. I'll investigate more tomorrow. Going afk for the evening.

borkdude 2020-09-01T20:14:50.050800Z

Yes, note that it works as is, but not when you uncomment the alter-var-root line :)

borkdude 2020-09-01T20:21:55.051Z

Ah, it does work when I set JAVA_HOME to GraalVM 11!

borkdude 2020-09-01T20:22:06.051200Z

but just not with AdoptOpenJDK 11

borkdude 2020-09-01T20:31:15.051400Z

Upgrading to AdoptOpenJDK 11.0.8 worked! https://github.com/http-kit/http-kit/issues/440

borkdude 2020-09-01T20:38:19.051800Z

I now fully read your blog. Very nice! Babashka does offer some libraries in addition to what is built-in: https://github.com/borkdude/babashka/blob/master/doc/libraries.md

borkdude 2020-09-01T20:50:12.052500Z

I updated the README a bit: https://github.com/borkdude/babashka#built-in-namespaces

borkdude 2020-09-01T20:50:39.052900Z

But I do get your point: Python has a much bigger library ecosystem, no argument there :)

borkdude 2020-09-01T20:51:07.053300Z

Thanks for your nice blog. Are you going to share it anywhere? Reddit / Twitter, etc?

borkdude 2020-09-01T21:21:59.054Z

This is pretty awesome. Inspect a big chunk of edn using clojure.datafy, bb and portal:

$ cat deps.edn | bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "RELEASE"}}}'` -m portal.main edn

👍 5
2020-09-02T13:11:25.059500Z

Sure. Happy to share the awesome stuff you and @djblue have made 🙂

borkdude 2020-09-02T13:16:15.059700Z

To be honest I hadn't used clojure.datafy that much myself, but I'm mind blown now ;)

2020-09-02T13:40:23.060100Z

Related to datafy, do you know if the pod edn format preserves metadata? I tried some of the https://github.com/babashka/babashka-sql-pods examples but wasn’t seeing any of the metadata next-jdbc puts on its results for datafy

borkdude 2020-09-02T13:41:02.060400Z

Hmmmmm

borkdude 2020-09-02T13:41:40.060600Z

I wasn't aware of the metadata on that and I think you need to turn this on explicitly, it's probably not currently

2020-09-02T13:41:44.060800Z

Even if there is metadata support, not sure this would work because the metadata it puts on are protocol fns

borkdude 2020-09-02T13:41:59.061Z

yeah, I think this doesn't work with pods probably

borkdude 2020-09-02T13:42:28.061200Z

well maybe we could make it work

borkdude 2020-09-02T13:42:38.061400Z

a pod can also define client side functions

2020-09-02T13:42:40.061600Z

Example metadata:

#:clojure.core.protocols{datafy #object[next.jdbc.result_set$navize_row$fn__17145 0x4c1ea0ab "next.jdbc.result_set$navize_row$fn__17145@4c1ea0ab"]}

borkdude 2020-09-02T13:42:52.061800Z

oh functions

borkdude 2020-09-02T13:43:19.062Z

we could hack around that by representing the function using a name, but if it's a closure then that won't work

2020-09-02T13:43:43.062200Z

ah yep

borkdude 2020-09-02T13:44:42.062400Z

can you point me to the place where next.jdbc attaches that metadata?

borkdude 2020-09-02T13:45:34.062600Z

if everything was in babashka itself, it would work. I'm partial about including only postgres, but we could

borkdude 2020-09-02T13:48:44.062800Z

it's still available behind a feature flag

borkdude 2020-09-02T13:48:52.063Z

if you compile bb on your own system

2020-09-02T13:50:58.063500Z

Forgot about the feature flag. I’ll try that 🙂 I’m definitely not advocating for bloating bb core. It is interesting to see where pod’s limitations are

borkdude 2020-09-02T13:59:40.063700Z

I'm very tempted to add postgres support, since it's so cool ;)

borkdude 2020-09-02T14:00:16.063900Z

ah yeah, so it's a closure over this

2020-09-02T14:25:20.064100Z

What am I missing? It is a library right? So I don't have to install a pod, correct? cat deps.edn | bb -cp clojure -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "RELEASE"}}}'` -m portal.main edn` clojure.lang.ExceptionInfo: Could not resolve symbol: realized? [at portal/http_socket_server.clj, line 65, column 20]

borkdude 2020-09-02T14:26:04.064300Z

@mmz Are you using bb 0.2.0?

borkdude 2020-09-02T14:26:09.064500Z

That one is required

2020-09-02T14:26:20.064700Z

let me check ... bb -v ?

borkdude 2020-09-02T14:26:43.064900Z

$ bb --version
babashka v0.2.0

2020-09-02T14:30:26.065100Z

Works now! (did a brew update before testing ... should have done a brew upgrade babashka :face_palm::skin-tone-3: )

2020-09-02T14:31:36.065300Z

This is indeed pretty awesome! :thumbsup::skin-tone-3:

borkdude 2020-09-01T21:22:10.054200Z

Also works for json or transit. Thanks for sharing @cldwalker