This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-12
Channels
- # announcements (1)
- # babashka (67)
- # beginners (39)
- # calva (56)
- # clojure (72)
- # clojure-berlin (3)
- # clojure-boston (1)
- # clojure-europe (10)
- # clojure-nl (1)
- # clojure-norway (67)
- # clojure-uk (5)
- # clojurescript (7)
- # emacs (21)
- # figwheel-main (5)
- # graalvm (24)
- # hyperfiddle (26)
- # missionary (5)
- # music (1)
- # off-topic (21)
- # polylith (4)
- # releases (2)
- # sci (3)
- # shadow-cljs (25)
- # squint (28)
#!/usr/bin/env bb
(require '[babashka.cli :as cli])
(import (java.time YearMonth))
(import (java.text DecimalFormat))
(def cli-options {:month {:coerce :long}
:year {:coerce :long}
:help {:coerce :boolean}})
(def decimal-format (.DecimalFormat "00"))
(def last-hour "23:59:59")
(let [{:keys [month year]} (cli/parse-opts *command-line-args* {:spec cli-options})
days-in-month (.lengthOfMonth (YearMonth/of year month))
two-letter-month (decimal-format/format month)
formatted-date (str year "-" two-letter-month "-" "01" " " last-hour)]
(prn formatted-date))
When I run I get this error
bb src/calc-month.clj --month 3 --year 2024
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: Unable to resolve classname: java.text.DecimalFormat
Location: /Users/rnatarajan/Documents/Coding/ekata/calc-cpm/src/calc-month.clj:5:1
----- Context ------------------------------------------------------------------
1: #!/usr/bin/env bb
2:
3: (require '[babashka.cli :as cli])
4: (import (java.time YearMonth))
5: (import (java.text DecimalFormat))
^--- Unable to resolve classname: java.text.DecimalFormat
6:
7: (def cli-options {:month {:coerce :long}
8: :year {:coerce :long}
9: :help {:coerce :boolean}})
10:
----- Stack trace --------------------------------------------------------------
user - /Users/rnatarajan/Documents/Coding/ekata/calc-cpm/src/calc-month.clj:5:1
https://github.com/babashka/babashka/blob/master/src/babashka/impl/classes.clj I think this is a list of the java classes available in Babashka
Babashka doesn't include all Java classes. Only three java.text
classes are exposed: https://github.com/babashka/babashka/blob/master/src/babashka/impl/classes.clj#L412-L415
Hah, jinx!
You could just use format
:
(~)-(!2002)-> rlwrap bb
Babashka v1.3.188 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (format "%02d" 12)
"12"
user=> (format "%02d" 2)
"02"
user=> (format "%02d" 10)
"10"
user=>
Yeah perhaps I could add this class since it came up before. I never ever used it myself though :)
I basically just want to know branch and git sha of the HEAD. But often when I roll something like that I discover that I am reinventing wheels. 😃
https://github.com/clj-jgit/clj-jgit doesn’t work with babashka, right? Asking because there’s a Clerk notebook that uses clj-jgit: https://github.com/nextjournal/clerk-demo/blob/main/notebooks/git.clj
jgit certainly doesn't work with bb. note that even tools.deps dropped the dependency on jgit just to shell out to git instead
Awesome. For my usecase p/sh was what I needed. But I’ll try to remember tools.gitlibs!
just wondering, with babashka i get this nice exception with exact place in code that thrown, however why I catch and rethrow, I dont get it, is there some simple way to just try+catch, do some op and rethrow + get this nice marking?
Hi, first of all, many thanks to "The Dude"; love bb, it makes Clojure real and practical for a non-developer like me. A very lovely experience indeed. I have a question: I use babashka on Windows and it doesn't seem to be able to print Korean characters, printing question marks. Am I doing something?
OMG OMG OMG am I talking to THE borkdude? I really appreciate all you have done. Thank you very much!!! Now as for the problem, it's as simple as (println "한글"), which prints ??? instead of 한글. Is bb supposed to print Asian character properly?
In DOS prompt and BB REPL respectively: echo "보크듀드 감사합니다!" "보크듀드 감사합니다!" user=> (println "보크듀드 감사합니다!") ?????? ????????! nil
$ rlwrap bb
Babashka v1.3.190-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (println "보크듀드 감사합니다!")
보크듀드 감사합니다!
When using Calva on VS code, it prints properly in the output window. It's when I'm using cmd.exe when it doesn't print correctly.
yeah this isn't specific to bb:
C:\Users\borkdude>clj
Clojure 1.11.1
user=> (println "보크듀드 감사합니다!")
???? ?????!
nil
Active code page: 65001 C:\Users\urban>bb Babashka v1.3.189 REPL. Use :repl/quit or :repl/exit to quit the REPL. Clojure rocks, Bash reaches. user=> (println "한글") nil
oh the characters aren't even printed properly here. Let me read the post and get back to you later!
I don't know exactly what is the problem with bb + cmd.exe but it does work for me with wsl2 and mac iterm2
You may want to look into the details of how Windows encodes UTF-8 characters; frequently Windows applications default to the windows-1252
encoding for files which is primarily ASCII based and will fail on non-Latin character sets. Windows continues to rely on the presence of a https://en.wikipedia.org/wiki/Byte_order_mark to decode UTF-8 properly. I recently had to add a https://github.com/jimpil/clj-bom to my JVM Clojure project to deal with this issue on Windows.
I suspect that a similar issue may be occurring here.
I don't have wsl2 installed, but it seems like the problem lies with cmd? It's not bb specific because the clj command example also prints ??? instead of Korean characters.
you might also see if you have better luck with PowerShell than cmd
Anyhow, it seems like the problem lies with something other than babashka. If I find anything useful, I'll come back and post.
This is my very first experience with this channel (and Slack) so if I'm not following any rules here by simply posting a question, please let me know!
Is there an alternative to clojure.core.memoize
in Babashka? That library does not seem to be apart of Babashka so I was wondering if anyone uses anything else!
How sophisticated a cache system do you need?
I am writing a babashka AWS lambda, and I wanted to avoid making it too complicated so a library that just worked would be nice, but honestly I just made a simple cache with an atom and it seems to be fine.... Its not too hard to follow
Might be a better way but like I just needed to cache a token
(defn memo!
[f atom]
(fn [& args]
(if @atom
@atom
(reset! atom (apply f args)))))
(defn clear-memo!
[atom]
(fn []
(reset! atom nil)))
looks good to me. (if x x ...)
could be written as (or x ...)
but this is just a minor nitpick
Thanks 😄
And clojure.core/memoize
isn't sufficient?
i.e., the built-in function memoization
I need to clear the cache when I get a 401 back! Hence why I wanted to use the former I mentioned
Ah, gotcha. Yeah, that would be a nice enhancement to the built-in one -- some magic set of arguments that caused the cache to be cleared for all invocations.
