Fork me on GitHub
#babashka
<
2022-02-22
>
nyor.tr10:02:27

Is it possible to do an input redirection in shell with Babashka tasks? I would like to make a script like: mysql --login-path=mydb db < db_backup.sql But I get an error when I use the "<" character. This did not work: (shell {:out "out.txt" } "mysql -h localhost -u user -pPASSWD db < db_backup.sql") Is there any other way to pass the contents of a file into a shell script?

borkdude10:02:26

@nyor.tr yes! use (shell {:in (io/file "db_backup.sql")} ...)

nyor.tr10:02:47

Oh thanks, I'll try that!

nyor.tr10:02:32

Yes, that did work, thanks!

Mícheál Ó Catháin16:02:40

hi! I'm getting a great kick out of learning Babashka. Has anyone managed to use it to access currency exchange rates via a web api?

borkdude16:02:04

Is your question: how you can you access a web api in babashka?

borkdude16:02:54

there are a couple more options for doing http but that's a convenient one

Mícheál Ó Catháin16:02:00

@U04V15CAJ thank you - that is essentially my question yes!

Mícheál Ó Catháin16:02:34

I am trying babashka.curl just now...

Mícheál Ó Catháin17:02:48

Thanks so much @U04V15CAJ. It just works!

👍 1
Mícheál Ó Catháin17:02:23

(require '[babashka.curl :as curl])                                 
(require '[cheshire.core :as json])    (def resp (curl/get "" {:headers {\
  "Accept" "application/json"}}))                                     
(def body (json/parse-string (:body resp)))                         
(println (str "EUR:USD = " (get body "EUR_USD")))

🎉 2
☘️ 1
Ben Sless20:02:32

Is it possible to use babashka to run clojure tools.tools?

borkdude20:02:06

Do you mean, to invoke a -Tfoobar tool?

borkdude21:02:41

The tools.tools project seems to work under the following conditions: • include babashka/spec.alpha • include the tools-deps-native pod (which brings in tools.deps.alpha via a pod)

$ bb -cp $(clojure -Spath -Sdeps '{:deps {org.babashka/spec.alpha {:git/url "" :sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}}') -e "(babashka.pods/load-pod 'org.babashka/tools-deps-native \"0.0.5\")' "-e "(require '[clojure.tools.tools.api])"

borkdude21:02:52

But it requires further testing. So I'd say: it could work, but I'm not sure if it's worth pursuing.

Ben Sless04:02:09

Motivation - I want fast start up times for tools introspection

dabrazhe21:02:03

I noticed when creating the Self contained bb executable with caxa that it takes ages to create and ages to start the executable for the first time. Is it perhaps related to the mac's M1 processor (lot's of issues seem to be related to it these days:)

borkdude21:02:34

@U96LS78UV Make sure that your directory doesn't contain any garbage and doesn't contain an executable you created before since it will package itself within the new executable. I.e. have the least amount of files in the directory so the binary will be the smallest possible.

borkdude21:02:20

I don't have experience on m1, but I'll try what a hello world yields here:

borkdude21:02:37

It takes around 10s or so. Image is around 50mb. First time takes a while to invoke, but second time is way faster.

dabrazhe22:02:01

Yes, actually this was the case. When I cleared all the nonsense from the folder it started to work really fast. I need a bb task wrapper for the caxa command to remove the old executable first : )

borkdude22:02:59

Or move everything to a separate dir and use a different input argument

✔️ 1
dabrazhe22:02:07

ha, that's even simpler: ) after cleaning it up it takes ~ 6 seconds. great stuff!

dabrazhe22:02:24

why the exec file is about 34MB? for a script of 100 B? )

borkdude22:02:03

because it compresses babashka inside of that binary