This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-15
Channels
- # announcements (1)
- # babashka (4)
- # beginners (4)
- # calva (42)
- # clerk (2)
- # cljdoc (1)
- # clojure (71)
- # clojure-denver (3)
- # clojure-europe (4)
- # clojure-uk (11)
- # clojurescript (1)
- # cursive (12)
- # deps-new (4)
- # emacs (3)
- # hyperfiddle (46)
- # java (1)
- # jobs (2)
- # jvm (16)
- # missionary (10)
- # polylith (5)
- # releases (1)
- # remote-jobs (2)
- # scittle (6)
- # sql (7)
- # transit (10)
How do I get next.jdbc
to recognize a UUID type for an ID for get-by-id
?
It works for find-by-keys
(defn find-holder-by-id! [db holder-id]
(sql/find-by-keys db :wallet_holders {:guid holder-id}))
Yet not for get-by-id
(defn find-holder-by-id! [db holder-id]
(sql/get-by-id db :wallet_holders :guid holder-id))
The name of my primary key field is “guid” in the database. PostgreSQL.Per the docs https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.883/api/next.jdbc.sql#get-by-id if you need to specify the pk-name you must also provide opts (which can be {}
)
I freaking love Clojure. The REPL loves me back every time I use it. This is the language I am the most productive in.
If i had a start date/end date, and a "schedule" like {:monday {:start "1am", :end "2am"}}
How could I generate a series of dates ?
I see clj-time
does something with sequences. But I don't want to work with joda-time, I'm using JUT's
you can use the java time wrappers (like Tick or java-time) first to generate an interval, slice it, and then convert instants to java.util.Date as the last step
hm, can't find it haha, looks like I moved to a different approach. It doesn't matter - what you need is to use https://cljdoc.org/d/tick/tick/0.4.30-alpha/api/tick.interval and once you have sub-divisions, pick the start and process the results
so... like... Generate the weeks array ? And then per week, set it to Monday and the start time ?
(def dates (let [intvl (t.i/bounds (t/year))]
(t/range
(t/beginning intvl)
(t/end intvl)
(t/new-period 1 :weeks))))
(def schedule {:MONDAY {:start "1am" :end "2am"}
:TUESDAY {:start "1am" :end "2am"}})
(->> dates
(map (fn [date]
(->> schedule
(map (fn [[k {:keys [start end]}]]
(let [day (case k
:MONDAY (set-date-to-monday date)
:TUESDAY (set-date-to-tuesday date)
( "not finished"))]
[{:start (set-time day start)
:end (set-time day end)}])))
(filter identity)))))
I use https://docs.oracle.com/javase/8/docs/api/java/time/temporal/TemporalAdjusters.html
You can start with an instant, adjust it to whatever point in time you need, and then generate an interval off that and so on
gotcha, I built this somewhat differently: I use cron-utils to build a background scheduler that (among many other things) checks every 5m if there are any upcoming events in the meeting database and handles that (15m-before-start reminder etc). Meetings are created off bounds and do not depend on the scheduler per-se, they just have recurrence information baked in and the scheduler takes care of creating them ahead of time, finding next time slot and so on. So you could define your events in terms of cron expressions, so you don't really have to do the date time math yourself for the most part https://github.com/jmrozanec/cron-utils
Although there's many caveats, you're building something slightly different and you might need to drop down to the java.time.* stuff directly to get the most flexible approach, I started with tick but moved off it to have more control
Is this the following even possible. Someone says start_time "01/01" end time "02/01" I know they're in New York "America/NEW_YORK"
i get the range of dates at midnight, and then parse the dates in
yyyy-mm-dd
and then i concatinate "hh-mm"
formatted in NY time
and then parse the concatinated result... i guess that won't work because unless my range of yyyy-mm-dd
dates are guaranteed to be the right date....
Kinda: you figure out start of the day in their TZ, built a seq of timestamps until end of the day in TZ, and then convert all of them to instants
(def dates (let [intvl (t.i/bounds (t/year))]
(t/range
(t/beginning (java.util.Date.))
(t/end intvl)
(t/new-period 1 :weeks))))
Always stick to the following and it works out: • always store UTC timestamps only plus TZ info for all users • Use timezone info to get zoned data times only for calculations and always convert back to UTC • send only UTC to the UI and display zoned dates time there • Accept only UTC timestamps or explicitly send zoned date times although I don’t advise the latter approach
http://everytimezone.com is invaluable for this btw
That should be a sound approach, although just saving the UTC instant + timezone is usually sufficient
btw, JDK has a TimeZone class so you can get a standard list of all available timezones with offsets and such. One caveat is that you have to start taking care of updating the timezone database, because it changes every now and then
Pretty sure there's nothing built-in. But perhaps you can check whether something is an instance of clojure.lang.ASeq
.
for your purposes, is there a difference between a fully realized lazy sequence and a list?
maybe not, although I'll be happy with
(or (list? form) (instance? Cons form))
most of all for conveying programmer intentwhat's the intent?
Not sure I follow. Clojure evaluates forms, which may or may not be lazy. The reader is separate. I don't think the builtin clojure reader every produces lazy sequences, but you could have other readers or non-reader sources for producing code to evaluate (eg. macros).
I'm only dealing with the "read" phase in this context, I can be certain forms are just lists/cons at this stage (please let's leave the convo at that 🙏)
Ok, I was hoping to maybe learn something new. My guess is that seq?
is the correct predicate, but it's unclear what the use case is.
Why is the Thread
metadata lost if I process it with the following defn? :thinking_face:
(defn macroexpanded-context [ns form]
(->> form
(walk/postwalk (fn [x]
(if (and (list? x)
(-> x first symbol?)
(contains? #{#'clojure.core/->
#'clojure.core/->>
#'clojure.core/..
#'clojure.core/doto}
(->> x first (ns-resolve ns))))
(macroexpand-1 x)
x)))))
(comment
(binding [*print-meta* true]
(clojure.pprint/pprint (macroexpanded-context *ns*
'({:idx 3, :form '(-> x ^Thread (anything) __prefix__)})))))
Awesome, thanks! http://grep.app -ing that issue number gave me this alternative: https://github.com/clojure-goes-fast/clj-java-decompiler/blob/9d7a554d5afc6f3fe81ea46f1f9ee49bf679b1e4/src/clj_java_decompiler/core.clj#L20-L36