This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-20
Channels
- # announcements (26)
- # babashka (25)
- # beginners (16)
- # biff (12)
- # calva (36)
- # clj-commons (4)
- # clj-kondo (3)
- # clojars (1)
- # clojure-art (1)
- # clojure-dev (1)
- # clojure-europe (10)
- # clojure-gamedev (1)
- # clojurescript (7)
- # clr (10)
- # fulcro (10)
- # helix (6)
- # introduce-yourself (2)
- # malli (7)
- # matrix (203)
- # off-topic (12)
- # pedestal (4)
- # practicalli (2)
- # reagent (5)
- # specter (1)
- # sql (8)
- # vim (1)
- # xtdb (5)
Iβm looking for some examples of how to use regular expressions in Babashka. More specifically, I need to process a few hundred JSON files, located in a few dozen subdirectories (variable depth), and search and replace a string within the contents of each JSON file with parts of its filename. So I need to use regular expressions to capture parts of the filenames and parts of the JSON contents. I'm updating some connection strings in many appsettings.json
files for a bunch of .NET microservices. Does anyone know if there are any examples of how to do something like this?
@U01PE7630AC you can maybe use babashka.fs/glob
for finding the json files:
(babashka.fs/glob "json-dir" "**.json")
will find every json file in all the subdirectories below json-dir
About replacing by regex in a string:
(str/replace the-string #"my-regex" "the-replacement")
?Thanks for pointing me in the right direction, @U04V15CAJ! I've been watching all your talks on YouTube today. I'm excited to try it out at the office on Monday!
By the way, Babashka is the perfect way to sneak some Clojure into my workplace. Nobody likes Bash scripts, so they're happy to give me all those tasks, and nobody cares what I use to solve them. I plan to break the ice with Babashka and use it to demo the strengths of Clojure to my teammates. Perhaps I can convince the rest to try to build one microservice with Clojure. At present, weβre all in on C# .NET on Microsoft Azure.
Would it be wholly unreasonable to attempt to embed Clojure in a C# .NET application, to provide end-users with scripting capabilities, using Babashka or SCI? In a similar way to how Lua is often embedded in game engines for gameplay designers to create NPC brains, create GUI modifications, etc. We have a use case where we want to provide semi-technical business users with a DSL for creating business logic/βrulesβ in some of our applications, and I suspect this might be one viable path to success.
@U043RSZ25HQ I've had a look at that, and it seems rather thinly documented and not actively maintained. I could be mistaken. It seemed like Clojure on GraalVM could be a viable alternative to embed Clojure due to it being one small binary.
Check #clr, seems pretty active and will be the simplest option. It's still quite a niche thing, although it's the same clojure so docs for clojure should apply fine
It's possible to compile sci to a shared library. And it's possible to call shared libraries from C#. Though you might have to break some new ground! https://github.com/babashka/sci/blob/master/doc/libsci.md
Using something like IronPython is probably going to be easier, though (if you want easy more than you want Clojure). Dynamo's Python cells are implemented with IronPython. IronPython: https://ironpython.net/ A video about using Python from Dynamo: https://m.youtube.com/watch?v=3sDMHG2NlQM&list=PLBKwx9iS-Lun4z5igR9dCzTG3-GdNayq7&index=1&pp=iAQB Though is definitely cooler than π.
"I made all the examples from htmx in Clojure-Babashka! I had a lot of fun coming up with ideas along the way." @kyogatama on Twitter: https://twitter.com/keychera/status/1659879552175464448
Using core.match
for routing was an interesting idea! Don't think I've seen that before.
https://github.com/keychera/panas.example/blob/main/babashka-httpkit/src/serve.clj#L21
just got around to opening slack, thank you for sharing this @U04V15CAJ ! @U3X7174KS I actually got the idea from somewhere in this slack here but I didn't remember exactly from who, since I often got my question answered just by searching through slack past questions/discussions
Nice! I have that relationship to way too many of "my" ideas. Often I've seen them coined by somebody else. Then some time has passed. Then it feels like the idea is "mine" because it feels right. π π
When core.match in bb was just included, this was one of the original examples, to use it for routing. So the example may be somewhere in examples maybe in the babashka repo.
I can also recommend https://github.com/askonomm/ruuter as a routing lib in bb
I've been playing around with Babashka and HTMX myself this week. Which brings me to a question about namspaces. I've set up my local HTTP server to run bb for .clj files and that works great! Got over all the humps reading environment variables and stdin to get POST data. But then I wanted to break that down into namespaces and can't get to a happy place that works both over HTTP and with my IDE (aka Vim). Thought maybe you folk would have some clever ideas to share.
How have you arranged the code for the project? does it have a bb.edn
with a src
folder structure or is it a single file?
I was trying to have the code flat in a directory as would make sense for the URLs. But I believe namespace requirements won't allow for that.