This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-14
Channels
- # adventofcode (107)
- # aleph (1)
- # announcements (8)
- # beginners (57)
- # boot (3)
- # braveandtrue (18)
- # calva (374)
- # cider (6)
- # cljdoc (8)
- # cljs-dev (140)
- # clojure (199)
- # clojure-berlin (5)
- # clojure-europe (3)
- # clojure-finland (1)
- # clojure-hamburg (4)
- # clojure-italy (17)
- # clojure-nl (16)
- # clojure-spec (2)
- # clojure-uk (70)
- # clojurescript (29)
- # component (2)
- # cursive (10)
- # datomic (44)
- # docker (1)
- # figwheel (3)
- # fulcro (13)
- # immutant (2)
- # juxt (5)
- # leiningen (53)
- # nrepl (3)
- # off-topic (7)
- # pedestal (3)
- # re-frame (7)
- # ring (3)
- # ring-swagger (5)
- # rum (5)
- # shadow-cljs (14)
- # spacemacs (6)
- # specter (12)
- # tools-deps (11)
- # unrepl (11)
- # vim (7)
How do I manipulate #inst
values? Calculate interval b/w two instants, compare time intervals and so on.
@jaihindh.reddy You will want to look at Java Time for stuff like that I suspect.
I'm writing a script that takes data from a SQL database and ssh into servers, grep and parse logs....
^ The new java time thing? I see various names floating around, java.time, clojure.time, clojure.instant, joda etc and don't know what the consensus is (or if there is one)
java time seems to be good upon glancing the API. No blunders like mutable dates ๐
Java Time is the "standard" way to do that sort of stuff ever since Java 8.
You might find the clojure.java-time
wrapper easier to work with than raw Java interop.
@ahmed1hsn I concur with @dpsutton That code compiles without error for me too -- so something you have at line 100 is where the error likely is, in your file, not in the 62 lines that come from that money.clj
script.
This code can't catch first exception java.net.ConnectException
. But when I execute (redis/ping)
, it raise up this exception java.net.ConnectException
.
connections get created in this global pool thing if I recall https://github.com/ptaoussanis/carmine/blob/master/src/taoensso/carmine/connections.clj#L29
@seancorfield i still think java time has an insufficient spec for interval types compared to joda time ;_;
@sova I'm sure Stephen Colebourne has a good reason for that difference...
(and there's always his org.threeten/threeten-extra
library with https://www.threeten.org/threeten-extra/apidocs/org/threeten/extra/Interval.html etc)
Ah! that's right. i forgot about the "extras" library
now that's what i'm talking about. thank you.
hey guys, i am trying to generate the war
file of my compojure-api project but it keep generating a jar
. help? please.
@hiredman I checked out that link source code, still don't understand why can't capture that exception.
I always have trouble using require
the first time I add a new lib. The namespace name isn't always same as the artifact name or the library name. Can I reliably find this information (which nses it has) from the artifact itself somehow knowing just the :mvn/version
of it without relying on documentation. Because once I require it, I can mostly be self sufficient using the stuff in clojure.repl
(`find-doc`, doc
, source
et al)
Unfortunately the honest answer is no. There is no relationship between an artifact group/name/version and the namespaces in it.
how to toggle class via :on-click in cljs?
which includes hiccup more or less
Forgive me if Iโm unhelpful here but I would suspect https://github.com/tonsky/rum#components-local-state combined with a function to take relevant state and return a string of class names?
(defn get-classes
[active?]
(->> (keep some? ["my-class"
"other-class"
(when active? "active")])
clojure.string/join " "))
1. Is there a way to configure clojure.java.jdbc
to return java.time.Instant
s instead of java.sql.Timestamp
s?
2. Is there a way to make Clojure print java.time.Instant
s with #inst
?
3. Is there a way to make Clojure read #inst
s as java.time.Instant
s?
4. Are the above bad ideas?
Re 2, it should already do that with Java 8+
They are good ideas, but 3 would likely be a breaking change for some
check out clj-time https://github.com/clj-time/clj-time
Thank you for your suggestion! I have looked at Joda time, and it seems like java.time
largely replaces all other time stuff in the Java world, making clojure.java-time
the go-to idiomatic Clojure wrapper of java.time
. I was just trying to have minimal deps while also minimizing the amount of interop code.
Hi, friendly people. My question is somewhat n00b annoyance about organisation of namespace and project in general. According to Clojure namespace evaluation, it does read from top to bottom. Which means in normal case, the function have to be defined before it can be used. But that leads that my most abstract and high-level functions are at the bottom of file, and I can't program top-down. Looks like, the most generic functions like main game loop literary is the last function at the very bottom of my file. Is it as it supposed to be? I know one can declare functions ahead, but that sux.
Or the solution is divide namespaces by abstraction... most generic functions in one namespace which requires other namespaces? So it seems that programming would be like writing main function, fill it up with smaller functions, then extract those into another namespace and require :all that namespace
i generally end up putting common/utility functions at the top and dividing out into more namespaces based what seems like a logical organization
so if I end up needing a utility function in several namespaces I'll make a utils namespace and require that everywhere for example
code organization in a purely functional language will generally be a looser than object-oriented languages though
then my main namespaces are named & divided according to what functionality they provide, f.ex. formatters, imports, exports, user, sql, etc. etc.
then try and keep namespaces short enough to be able to mentally "contain" them while working, which for me seems to be 2-300 codelines pr. namespace max
Using clojure.java-time
I'm unable to do this simple thing:
Given a java.time.Instant
t, find the hour(s) the time range t-e to t+e falls on, where e is an epsilon value.
For example, for t = "today 15:56" and e = "5 minutes" t-e would be "today 15:51" and t+e would be "today 16:01" making the output of the hypothetical function ["today 15" "today 16"]. How can I accomplish this?
@jaihindh.reddy Have you looked at org.threeten/threeten-extra ? It has Interval
s and a contains?
function that might be helpful. This extra lib is mentioned at https://github.com/dm3/clojure.java-time#three-ten-extra
@dorab Thanks! This is exactly what I was looking for...
(defn record->hours
[epsilon {:keys [addedon updatedon] :as record}]
"Returns a seq of all hours that might have encompassed all activity in a DB record"
(let [max-time (t/truncate-to (t/minus addedon epsilon) :hours)
min-time (t/truncate-to (t/plus updatedon epsilon) :hours)]
(->> (t/iterate t/plus min-time (t/duration 1 :hours))
(take-while #(not (t/after? % max-time))))))
Is there a recommended way to make this less verbose?
clj -A:repl -m nrepl.cmdline --interactive
Could I just toss that in a repl.sh?{:aliases {:repl {:extra-deps {nrepl/nrepl {:mvn/version "0.5.3"}
proto-repl {:mvn/version "0.3.1"}}
:main-opts ["-m nrepl.cmdline --interactive"]}}}
Usage: clj -A:repl
Works great, thanks!