This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-21
Channels
- # announcements (3)
- # babashka (26)
- # beginners (45)
- # calva (10)
- # chlorine-clover (9)
- # cider (4)
- # clj-kondo (7)
- # cljs-dev (10)
- # clojure (95)
- # clojure-europe (33)
- # clojure-france (5)
- # clojure-nl (3)
- # clojure-spec (2)
- # clojure-sweden (3)
- # clojure-uk (33)
- # clojurescript (54)
- # conjure (101)
- # core-async (14)
- # cursive (1)
- # data-science (91)
- # datascript (3)
- # datomic (16)
- # figwheel (3)
- # figwheel-main (15)
- # fulcro (35)
- # ghostwheel (5)
- # graalvm (13)
- # helix (29)
- # java (5)
- # jobs (6)
- # kaocha (6)
- # leiningen (1)
- # meander (12)
- # off-topic (54)
- # pathom (13)
- # re-frame (16)
- # reagent (8)
- # reitit (4)
- # rum (3)
- # shadow-cljs (49)
- # spacemacs (2)
- # sql (5)
- # tools-deps (10)
- # xtdb (8)
- # yada (3)
I have a directory of files. I want to only see ones modified today... Is there a simple way to do this?
The old school approach is to find midnight by truncating the time with Calendar, but
user=> (java.util.Calendar/getInstance)
clojure.lang.ExceptionInfo: Could not resolve symbol: java.util.Calendar/getInstance [at line 2, column 2]
A super cheezy way would be to get the time, format it w/o the time, and parse it back... but
(java.text.SimpleDateFormat. "YYY")
clojure.lang.ExceptionInfo: Unable to resolve classname: java.text.SimpleDateFormat [at line 1, column 2]
(def midnight (* 1000 (.getEpochSecond (.truncatedTo (java.time.Instant/now) java.time.temporal.ChronoUnit/DAYS))))
(filter #(> (.lastModified %) midnight) (.listFiles (.File. "/tmp/myfiles")))
How about:
(LocalDateTime/of (LocalDate/now) LocalTime/MIDNIGHT)
=> #object[java.time.LocalDateTime 0x39d8d143 "2020-05-21T00:00"]
@bherrmann Another variation, more verbose 😉
(require '[ :as io])
(defn day [millis]
(let [instant (java.time.Instant/ofEpochMilli millis)
zoned (.atZone instant (java.time.ZoneId/systemDefault))
local-date (.toLocalDate zoned)
year (.getYear local-date)
day-of-year (.getDayOfYear local-date)]
[year day-of-year]))
(prn (day (System/currentTimeMillis))) ;;=> [2020 142]
(day (.lastModified (io/file "README.md"))) ;;=> [2020 141]
How odd.
$ clj -r
Clojure 1.10.1
user=> (java.time.ZoneId/systemDefault)
#object[java.time.ZoneRegion 0x315df4bb "America/New_York"]
$ bb
Babashka v0.0.94 REPL.
user=> (java.time.ZoneId/systemDefault)
#object[java.time.ZoneRegion 0x1698137b "Etc/UTC"]
weirdly enough:
$ bb -e '(java.time.ZoneId/systemDefault)'
#object[java.time.ZoneRegion 0x15b47051 "America/Los_Angeles"]
while:
$ clj -e '(java.time.ZoneId/systemDefault)'
#object[java.time.ZoneRegion 0x6cdba6dc "Europe/Amsterdam"]
@bherrmann I asked a question about this in the GraalVM slack: https://graalvm.slack.com/archives/CN9KSFB40/p1590063790414600
Maybe it's fixed with 20.1.0: https://github.com/oracle/graal/issues/1833#issuecomment-610578085 I'll try locally
Yes, it appears so!
$ ./bb -e '(java.time.ZoneId/systemDefault)'
#object[java.time.ZoneRegion 0x282638a0 "America/Sao_Paulo"]
$ clj -e '(java.time.ZoneId/systemDefault)'
#object[java.time.ZoneRegion 0x6cdba6dc "America/Sao_Paulo"]
is there a way to use babashka as websockets client ? I couldn’t tell if it’s the case or not (I really love babashka btw 😍)
@thomas.ormezzano There is no built-in websocket support, as far as I know (unless there is something in Java which supports this?) But you could shell out to something like websocat maybe
if you feel inspired, you can build a websocket pod for babashka: https://github.com/babashka/babashka.pods
hato supports websockets, wasn’t there pod for it? https://github.com/gnarroway/hato
I did some experiments around including it as the default http client, but that didn't work out. It was technically possible but it slowed down compilation by 8 minutes and bloated the binary considerably.
However, maybe it's about time bb moved to java11 so we can just include
and people can build a lib around that
ah ok I actually don’t need it anymore but didn’t know about pods - going to keep that in mind for next time :thumbsup:
This is a very cool workflow for doing Clojure exercises with babashka: https://github.com/samedhi/ctci