This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-27
Channels
- # announcements (2)
- # asami (25)
- # babashka (124)
- # beginners (46)
- # calva (55)
- # cljdoc (70)
- # clojure (68)
- # clojure-australia (2)
- # clojure-dev (63)
- # clojure-europe (38)
- # clojure-nl (1)
- # clojure-spec (1)
- # clojure-uk (8)
- # clojurescript (56)
- # community-development (4)
- # conjure (1)
- # copenhagen-clojurians (1)
- # core-async (1)
- # cursive (3)
- # datahike (5)
- # datomic (183)
- # depstar (2)
- # figwheel-main (10)
- # fulcro (20)
- # honeysql (2)
- # hyperfiddle (1)
- # integrant (68)
- # jobs (6)
- # jobs-discuss (5)
- # juxt (1)
- # malli (13)
- # off-topic (8)
- # pathom (2)
- # rdf (10)
- # reagent (11)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (69)
- # spacemacs (1)
- # sql (5)
- # tools-build (51)
- # tools-deps (6)
- # xtdb (24)
Hi, how I can serve a static directory index.html, page.html, css/, js/, etc
using ring
?
I searched on google but in the codes found the directory was resources
by default or hardcoded. I need to specify the directory when I run the server, something like (serve-dir "dist" :port 3000 :open? true)
Ring middleware wrap-resource to sever html pages from which ever directory you define https://github.com/ring-clojure/ring/wiki/Static-Resources It's typically in resources as that directory is included in the jar (as it's on the class path) when the project is built.
So I deployed my first basic web app. Any suggestions on how to add some kind of metrics tracking to it so I can see how many page views, session duration, stuff like that? Do people generally just use stuff like mixpanel or are there clojure libraries I should use?
what is non-lazy for
? I need it for side effects like prn
or db actions
I have a need to train a developer in Clojure. What is considered the best Clojure course for a beginner programmer? Preferably something with exercises, that maybe needs input from a mentor every 16 hours of work or so?
For our new engineers I did a 2 hour workshop explaining the basics, then gave them brave clojure & the koans. Asked them to read but generally skip the macros part. Worked quite well, had them asking for help about as often as you’re looking for
84 exercises at https://exercism.org/tracks/clojure
What's the easiest way to get the epoch for the current week Friday?
Eg this week it's smth like [1633046400 "Fri Oct 01 2021"]
with java.time:
ZonedDateTime.now().with(TemporalAdjusters.next(DayOfWeek.FRIDAY)).truncatedTo(ChronoUnit.DAYS).toEpochSecond()
that’s Java code but the same thing can be done with interop in Clojure :)how can I translate
with(TemporalAdjusters.next(DayOfWeek.FRIDAY))
into Clojure code?like so!
(defn epoch-of-next-friday []
(-> (ZonedDateTime/now)
(.with (TemporalAdjusters/next DayOfWeek/FRIDAY))
(.truncatedTo ChronoUnit/DAYS)
(.toEpochSecond)))
make sure to import these things in your namespace:
(ns your-ns
(:import [java.time DayOfWeek ZonedDateTime]
[java.time.temporal ChronoUnit TemporalAdjusters]))
Thanks! @U3L6TFEJF My solution was to create a range of Fridays with the exact time i need
(take 12 (range 1632441600 18263936000 604800))
Then I find-first date the date in the sequence where it's higher than the current date
(find-first #(> % (quot (System/currentTimeMillis) 1000)) fridays-seq)
Hi everyone, how come I can slurp a file (i.e. (slurp "gcloud_service_account.json")
) successfully but when I try to use the following (slurp (io/resource "gcloud_service_account.json"))
I get an error?
Execution error (IllegalArgumentException) at app.firestore/eval48272 (form-init17699889922621730434.clj:26).
Cannot open <nil> as a Reader.
I'm going to guess from the error that (io/resource "gcloud_service_account.json")
returns nil
resources are loaded from the classpath. if the current directory is not on the classpath, that's not a valid resource path.
slurp
is relative to the current dir. resource
is relative to any of the items on the classpath.
hm but I put my file in the root directory (same location as project.clj
) yet I can do (io/resource "project.clj")
successfully
A resource lookup checks the entirety of the application's classpath.
Are you sure you are getting the same project.clj that is in the root directory? Perhaps you are getting a different project.clj that is somewhere else on the classpath?
oh shit @U0AT6MBUL that's it
Any advice for getting io/resource
to look in the right path? I'm using CIDER REPL if that changes anything
You just need to make sure that the current directory .
is first in the classpath. The default for cider is to use the classpath used when starting up the nrepl process under emacs.
If you can explain exactly what you're doing, we can help better. Since you mention project.clj, I presume you're using lein
. How are you starting up the nrepl process?
Typically src
and possibly resources
are the first two directories in the classpath. If that is so, you could consider putting your new file under the resources
directory instead of in the root directory.
I just do cider-jack-in
from a file within my project. I tried moving the file to src
and to resources
but no luck 😕
From within your cider nrepl bufffer, find out what the classpath is. (System/getProperty "java.class.path")
should tell you what is on the classpath.
@U01BRM3MQET the reason io/resource
doesn't look at the top level of your project is that you don't want to put your entire source tree in your deployed artifact. If you put the file somewhere that gets packages (eg. resources/
) you can ensure it will be available via io/resouroce from packaged code
thanks everyone. resources/
is in my class path according to (System/getProperty "java.class.path")
. I'll have to try moving the file there again and see if it works.
Hey, I'm trying to implement the microKanren paper and have some troubles to translate from scheme's cons
to clojures cons
(defn mplus
[stream1 stream2]
(cond
(fn? stream1) (fn [] (mplus stream2 (stream1)))
(empty? stream1) stream2
:else (cons (first stream1) (mplus (rest stream1) stream2))))
With clojure this expr. fails (mplus '({'a 1}) (fn [x] 1))
which is basically (cons {'a 1} (fn [x] 1))
while the scheme version (cons '(a . 1) (lambda (x) 1))
evaluates to ((a . 1) . #<procedure (? x)>)
My question is, how do I implement the scheme behavior of cons in clojure?in the scheme of minikanren cons is a generic pair constructor, it will make a pair out of any two things
clojure's cons is strictly for constructing sequences, so the second argument must be a seq or nil
the streams of (mini|micro)kanren are not disimilar to clojure's lazy-seqs, so you might look at directly representing them that way (there is some trickiness with supporting mplus for interleaved search)
https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic.clj#L1092-L1108 is core.logic's sort of equivalent to mplus I believe