This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-06
Channels
- # announcements (12)
- # asami (3)
- # babashka (59)
- # beginners (20)
- # biff (1)
- # calva (87)
- # cherry (8)
- # clj-kondo (41)
- # clj-together (4)
- # cljdoc (5)
- # cljfx (4)
- # cljs-dev (2)
- # cljsrn (6)
- # clojure (63)
- # clojure-europe (22)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (4)
- # clojurescript (5)
- # conjure (2)
- # datalevin (4)
- # datascript (8)
- # datomic (16)
- # events (1)
- # figwheel-main (1)
- # fulcro (9)
- # hyperfiddle (4)
- # introduce-yourself (1)
- # jobs (3)
- # kaocha (10)
- # lambdaisland (2)
- # lumo (7)
- # nbb (1)
- # off-topic (29)
- # pathom (15)
- # re-frame (80)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (13)
- # spacemacs (9)
- # sql (25)
- # squint (32)
- # tools-deps (6)
- # uncomplicate (6)
- # xtdb (15)
I want to write simple script which will fetch some data via rest (http get), and I want this script to be runnable from babashka and jvm, which pod/lib should I use ?
@rafal.wysocki you can use babashka.curl
which is built into bb
You could also use http-kit.client (built-in) or a Java 11 client based library like https://github.com/schmee/java-http-clj
I tried copy-pasting it from clojure.core:
(defn ^java.io.PrintWriter PrintWriter-on
"implements java.io.PrintWriter given flush-fn, which will be called
when .flush() is called, with a string built up since the last call to .flush().
if not nil, close-fn will be called with no arguments when .close is called"
{:added "1.10"}
[flush-fn close-fn]
(let [sb (StringBuilder.)]
(-> (proxy [java.io.Writer] []
(flush []
(when (pos? (.length sb))
(flush-fn (.toString sb)))
(.setLength sb 0))
(close []
(.flush ^java.io.Writer this)
(when close-fn (close-fn))
nil)
(write [str-cbuf off len]
(when (pos? len)
(if (instance? String str-cbuf)
(.append sb ^String str-cbuf ^int off ^int len)
(.append sb ^chars str-cbuf ^int off ^int len)))))
java.io.BufferedWriter.
java.io.PrintWriter.)))
But when I try using it:
(PrintWriter-on println nil)
I get:
java.lang.IllegalArgumentException: No matching clause: ["java.io.Writer" #{}] [at <repl>:27:1]
And I don’t really understand why.While I have you, do you know why this fails on Babashka? (java.util.concurrent.atomic.AtomicInteger.)
It says No matching ctor found for class java.util.concurrent.atomic.AtomicInteger
, but that definitely is a valid constructor.
About java.util.concurrent.atomic.AtomicInteger
- currently it has limited interop support to save space, but we could expand that
Can you tell me more about your use case? We can make a PR which supports your program
Currently that class is in :instance-checks
which makes only the class available but no methods etc
AtomicInteger
is more of a nice-to-have thing, but I can’t do much without PrintWriter-on
.
What about the java.lang.IllegalArgumentException: No matching clause: ["
thing, though?
after that you can get a new binary from https://github.com/babashka/babashka-dev-builds
That error has to do with the support in reify
: the support for that is hardcoded and Writer
has not been added to that list
Thanks for all the help. :thumbsup: I’ll dive into this once I’m on the other side of this flu.
When current master build finishes you can download from: https://github.com/babashka/babashka-dev-builds
Thank you so much! I really appreciate it. :thumbsup: I gave it a try and this is beginning to look doable. 🙂 https://tutkain.flowthing.me/bb.mov
I went ahead and made a quick list of all the things Tutkain uses that Babashka doesn’t currently support:
• clojure.core.server/stop-server
(https://github.com/babashka/babashka/blob/2400fc7be077ea54b95d94c91cbbb2ebf0ff47de/src/babashka/impl/server.clj#L20-L24)
• clojure.core/*source-path*
(https://github.com/babashka/sci/blob/133a7565749ac6cd5a8308182f0b1c7fc47e8a3d/src/sci/impl/namespaces.cljc#L942)
• clojure.core/ns-unalias
(https://github.com/babashka/sci/blob/133a7565749ac6cd5a8308182f0b1c7fc47e8a3d/src/sci/impl/namespaces.cljc#L1324)
• clojure.main/with-bindings
(https://github.com/babashka/babashka/blob/ddf03c50ae14c942c69c85e73e96caed00767e37/src/babashka/impl/clojure/main.clj#L28-L51) (not sure why this doesn’t work — it seems to exist?)
• clojure.main/ex-triage
, clojure.main/ex-str
, clojure.main/repl-exception
, clojure.main/repl-caught
, clojure.main/skip-whitespace
(https://github.com/babashka/babashka/blob/2400fc7be077ea54b95d94c91cbbb2ebf0ff47de/src/babashka/impl/clojure/main.clj)
• clojure.lang.Compiler/load
(probably not possible? maybe clojure.core/load-reader
instead?)
• java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy
I can definitely live without almost all of these, but stop-server
would be very nice to have. Luckily, it seems to me to be the most straightforward to add…? I’m willing to do the legwork on all of this, of course, but I’m wondering whether you have any quick thoughts on the feasibility of adding these things? I certainly understand wanting to keep the binary size small, and I’m not expecting you to add these things just for Tutkain’s sake. 🙂
not sure what the other things entail, but we could discuss/think about that in separate issues
Definitely, that works for me. :thumbsup: I’ll get back to you via issues/PRs later.
What’s the equivalent to, say, (System/getProperty "java.class.path")
in babashka? I’d like to see everything it thinks it has access to.
I just have to keep reminding myself that you’re just so so awesome to keep myself from feeling so incredibly incompetent. Thanks, @U04V15CAJ 🙂
A few quick google searches didn't turn up anything - is there an established way to import csv files into a sqlite database?
Something like this:
sqlite> .mode csv
sqlite> .import ./test_events.csv events
sqlite> .import ./test_users.csv users
if I remember correctly, you can also then do:
sqlite> .output somefile.csv
sqlite> select * from users u join events e on e.user_id = u.id
I was reading babashka and honeysql documentation thinking that it would be some kind of tedious thing lol
https://sqlite-utils.datasette.io/en/stable/ is quite nice as well