Hi, I'm curious about embedding sci (or cherry or squint) into a custom node runtime (Google App Script). Wondering where I should start. I've got a self-hosted CLJS running on GAS, so you can run code in formulas in Google Sheets and what not, which is interesting. But it's a bit heavy weight, having the whole self host in there. And 99% of your GAS code is going to be interop with GAS libs, so even squint might be a fit.
I noticed this: https://github.com/babashka/sci/blob/master/src/sci/impl/js.cljs
So that might work. But is it possible to share a namespace/context environment across different evalString calls, so that diffrent sheet cells can refer to the same definitions?
Still figuring out how to send cells in as parameters to clojure functions defined in a cell formula, but it might be an interesting tool
Using the whole self hosted compiler on every call is too heavyweight though and slows the call down
The great thing about Google App Script, by the way, is that 1) it's free, and 2) https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app, which you can use to build a bot that can scrape the internet and store results in google sheets, for free, so that's pretty sweet
GAS is serverless node before serverless was even a thing lol
Anyway, no reason to write scripts on there in an uncivilized manner, so I figure I'll try one of these slimmer alternatives to cljs for wrapping GAS
And with https://developers.google.com/apps-script/guides/clasp you can just deploy from the cli. So a cljs->gs build/deploy pipeline would be easy. There's no reason we shouldn't be just firing off scripts to the cloud using our personal hosted google node servers using our google accounts. It's a free lambda. Maybe that's what I should turn my clgs project into. A tool like nbb, but sends it to GAS. Not sure how a repl would work - it's ephemeral, like a lambda 🤔
And you can even host https://developers.google.com/apps-script/guides/web and https://blog.ohheybrian.com/2021/09/using-google-apps-script-as-a-webhook/ and https://sites.google.com/a/mcpher.com/share/Home/excelquirks/gassnips/apps-script-as-a-proxy off your free google account in gas
Would probably be pretty easy to host a free ngrok/pagekite thing, for getting repls out from behind firewalls, etc
And it could probably be as easy as nbb -e '(+ 1 2 3)', but it just runs it on gas
hmm. Not sure where that pointed. But essentially, you just start a project that has a Javasript.html file in it. Then you can just use script tags in it, with something like:
<script src="" type="application/javascript"></script>
<script type="application/x-scittle">
(defn my-alert []
(-> js/google
.-script
.-run
(.withSuccessHandler #(println :contents %))
(.doMyFn #js {"id" 12}))
(js/alert "You clicked!"))
;; export function to use from JavaScript:
(set! (.-my_alert js/window) my-alert)
</script>
Where doMyFn is some js fn you've defined in your file.
Then in your index.html file you can have something like:
<button onclick="my_alert()">
Click me!
</button>That's for frontend logic using scittle. Using it on the backend, in a .gs file is a different workflow, IIRC
Oh yeah, for that workflow, I'd advance compile a self-hosted version of CLJS, which IIRC was like 1.5 megs of JS. I pasted that into a file in the app script project. Then, in some other file or whatever, add a function to call the CLJS compiler:
function evalStr(s) {
clgs.core.evalCljs("(ns cljs.user)");
var res = clgs.core.evalCljs(s);
//Logger.log("output: " + res);
return res;
}
And then you can eval cljs forms directly in spreadsheet cells using evalStr. And you could probably use that eval in other places where app script code interfaces with. I played with that before sci was out I believe. But the idea there is to just put the whole js artifact in a gs file - not sure sci has a singular js artifact that exposes an eval call - probably does.thanks @john 👍
Hi - apols for being almost 2 years late... I am interested in sci on GAS. I can't access this link bc permissions. What tooling setup did you use in the end for clojure and GAS? anything on github I could see? thanks
Has that ugly ToS banner bar at the top, but good enough to get stuff done for free
> Hi, I'm curious about embedding sci (or cherry or squint) into a custom node runtime (Google App Script). Wondering where I should start. I guess you figured it out?
Well, I guess a number of different paths could work. Sorry about the longwindedness above, kinda pitching it and ruminating options at the same time
google cloud functions play well with nbb btw
no custom runtime necessary
And I guess there's a free threshold there too yeah?
not sure, but I would assume so
https://github.com/babashka/nbb/blob/main/doc/gcloud_functions.md
first two million are free
Cloud Functions provides a perpetual free tier for compute-time resources, which includes an allocation of both GB-seconds and GHz-seconds. In addition to the 2 million invocations, the free tier provides 400,000 GB-seconds, 200,000 GHz-seconds of compute time and 5GB of Internet egress traffic per month.Wow
That's probably even more than the GAS quotas anyway
GAS is an interesting stack though, with the webservices and docs integration
You could spin up a form from the CLI to take community comments that auto populated a google sheet