babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
bherrmann 2021-01-24T01:25:28.092200Z

bah, I need to process some html (specifically to pull data out of a table.) I know there is a jsoup pod... but is there anything lighter weight?

bherrmann 2021-01-24T02:13:55.092600Z

Regex for the win... (def rows (drop 1 (clojure.string/split table-contents #"<tr class=\"\w+\">")))

borkdude 2021-01-24T09:35:51.092800Z

@bherrmann

#!/usr/bin/env bb

(require '[babashka.pods :as pods])

(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")

(require '[pod.retrogradeorbit.bootleg.utils :as utils])

(-&gt; "&lt;html&gt;&lt;p&gt;Hello&lt;/p&gt;&lt;/html&gt;"
    (utils/convert-to :hiccup))
;; =&gt; [:html [:p "Hello"]]

๐Ÿ‘ 2
borkdude 2021-01-24T09:36:11.093Z

This pod will self-install itself

bherrmann 2021-01-24T15:17:05.094800Z

Thanks, I now realize I need to do even more parsing... I have to pull data out of a simple form. Life is too short to parse HTML with regex and indexOf and subs() - I will try the pod.

borkdude 2021-01-24T20:03:20.097500Z

I am going to include test.check as a preparation for including clojure.spec in babashka. https://github.com/babashka/babashka/pull/717 clojure.spec will be included when it's clear what happens to alpha and version 2, but I've already made a start with this as a feature flag, which is disabled by default.

1
borkdude 2021-01-24T21:06:19.098700Z

Released babashka 0.2.8 with additional built-in libraries: - core.match (much requested) - clojure.test.check (prep for including spec once it comes out of alpha) - hiccup (who doesn't use it?) https://github.com/babashka/babashka/blob/master/CHANGELOG.md#v028

๐Ÿ‘ 4
๐Ÿ”ฅ 1
nate 2021-01-24T21:11:43.099400Z

Awesome!

2021-01-24T21:53:49.101100Z

Whatโ€™s the recommended way to connect to a postgres db via babashka?

borkdude 2021-01-24T22:00:00.101600Z

@jayzawrotny I recommend https://github.com/babashka/babashka-sql-pods/

borkdude 2021-01-24T22:02:55.101800Z

Welcome btw!

2021-01-24T22:04:54.102200Z

Thanks on both accounts ๐Ÿ˜„

2021-01-24T22:23:26.103200Z

./test.clj
/home1/[redacted]/.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home1/[redacted]/.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql)
Is there a way to get a static binary for this or should I try a different route?

borkdude 2021-01-24T22:24:02.103600Z

@jayzawrotny Are you running this in an alpine docker container?

2021-01-24T22:25:28.104700Z

Itโ€™s a shared hosting environment as a cgi-script for learning\experimenting.

borkdude 2021-01-24T22:26:31.105200Z

currently we don't have a static version of this pod. theoretically it's possible

borkdude 2021-01-24T22:27:05.105600Z

you can compile it yourself locally, it's not hard

borkdude 2021-01-24T22:27:29.106300Z

the other way of connecting to postgres would be to shell out to psql

borkdude 2021-01-24T22:28:46.107800Z

There is even a library around shelling out to psql for bb: https://github.com/DarinDouglass/clj-psql

borkdude 2021-01-24T22:28:53.108200Z

But this was before there were pods.

2021-01-24T22:29:59.109800Z

Great! I did see that library mentioned in the docs but was curious about alternatives. The psql bin does exist on this server so shelling out should be doable, but local compile then uploading might be more performant Iโ€™m guessing? Any docs on compiling it locally? Should I setup a docker container to match the host environment?

borkdude 2021-01-24T22:30:02.109900Z

And there is another way: there is a feature flag in babashka itself which includes the postgres driver. So you could have a static babashka with postgres support and you could then upload this to your shared env.

2021-01-24T22:30:29.110300Z

I did upload the static babashka already

borkdude 2021-01-24T22:31:07.111Z

@jayzawrotny yeah, so you could compile the pod statically, or you could compile babashka statically with pg support enabled

borkdude 2021-01-24T22:31:27.111500Z

then you would have it built into bb, you can require next.jdbc directly without the pod

2021-01-24T22:32:51.112Z

That could work too for sure. This is quite exciting!

2021-01-24T22:35:51.113300Z

Thanks very much!

borkdude 2021-01-24T22:36:31.113600Z

Be sure to use GraalVM java11-20.3.0.

๐Ÿ‘ 1
2021-01-24T23:53:31.115700Z

After a bit of research Iโ€™m going to start with compiling the pods. As it stands, Iโ€™m unable to use any pods at runtime so tackling this is a must for any definitive guide. Fortunately those links gave me enough info to get that going.