beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
seancorfield 2020-11-27T00:18:50.456600Z

PostgreSQL can be pretty fussy about date/time fields -- see for example https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/doc/getting-started/tips-tricks#working-with-date-and-time -- but you'll definitely want to be using an actual date/time value and not a string.

seancorfield 2020-11-27T00:20:17.456900Z

If you're using clojure.java.jdbc, I'll point out that's not actively maintained any more and you should consider using next.jdbc (the latter is the "1.0" release that I was not able to give c.j.j because I needed to make some big changes, based on what I'd learned maintaining c.j.j for many years).

seancorfield 2020-11-27T00:21:55.457100Z

Also, that SO answer suggests clj-time @highpressurecarsalesm which is deprecated now and the readme recommends either using Java Time directly or one of the wrapper libraries (and, yes, clj-time is another one of my libraries where I want people to migrate off it to something else 🙂 ).

Pablo 2020-11-27T01:46:27.457500Z

Thanks a lot!

Marcus 2020-11-27T15:05:41.460300Z

Hi! 🙂 About MongoDB. Does anyone here know how the monger library (via the mongodb java driver) converts the internal JSON data structures to and from Clojure data types?

Marcus 2020-11-27T15:06:41.460500Z

Documentation says: "Monger does not try to offer object/document mapping functionality. With Monger, you work with native Clojure and Java data structures like maps, vectors, strings, dates and so on"

Marcus 2020-11-27T15:07:38.461100Z

Conversion seems very fast so I am trying to find out why. :)

Marcus 2020-11-27T15:31:29.461500Z

I guess there are some BSON <-> clojure converter involved

Louis Kottmann 2020-11-27T16:09:04.462700Z

hello, is there an easy way to get the formatted time elapsed since a given date (for example: "5days ago") in clojure?

2020-12-01T15:57:55.110700Z

@lkottmann have a look at tick - it uses Java-time and you can use it in both clj and cljs https://github.com/juxt/tick

Louis Kottmann 2020-12-01T16:34:28.111200Z

looks interesting, don't know why I went past it, thanks

Louis Kottmann 2020-12-01T16:53:22.111600Z

it doesn't seem to support humanizing a time "ago" (i.e: "5 days ago")

Louis Kottmann 2020-12-01T16:53:31.111800Z

but it's definitely more complete than java-time

2020-12-01T17:20:25.112Z

Oh @lkottmann I'm sorry I completely missed the point of your initial message. Try this https://duckling.wit.ai/

Louis Kottmann 2020-12-01T17:37:42.112300Z

actually I replaced my code with and it's much better already

Louis Kottmann 2020-12-01T17:38:35.112500Z

that duckling lib looks awesome

Louis Kottmann 2020-12-01T17:38:40.112700Z

I never saw it before!

Louis Kottmann 2020-12-01T17:47:44.113200Z

I'm trying to see if it can handle the reverse (a duration to a humanized representation)

Louis Kottmann 2020-12-01T17:59:36.113400Z

mmh it doesn't seem to do that, and it has been deprecated in favor of an haskell version from facebook 😕

2020-12-01T18:28:18.113900Z

@lkottmann sorry I can't help much. I don't think it would be too hard to implement one, though. And at the end you can publish that as a lib 🙂

Louis Kottmann 2020-12-01T18:41:47.114300Z

well, I did but I didn't make into a library

👏 1
Louis Kottmann 2020-12-01T18:42:05.114500Z

Louis Kottmann 2020-12-01T18:42:16.114900Z

(uses tick)

👏 1
2020-12-02T13:45:11.213600Z

Just a quick tip (as a user) - I personally don't like when apps do that. I even have JS tweaks to replace the "... ago" on github. So please remember some people might not want that "feature". So I'd add that as an configurable option.

Louis Kottmann 2020-12-02T18:50:27.252200Z

I use it for knowing how long ago an app was deployed, and my users are my employees so it's fine ^^

scythx 2020-11-27T16:50:40.467600Z

Hello, i have to develop web app with clojure (API) + vue.js. Is there any framework that nearly equal to express.js? Are Ring + http-kit recommended? I haven't completely read about them yet. The project is relatively small only crud stuffs and user administration.

walterl 2020-11-27T17:03:16.468400Z

Searching for clojure humanize got me to https://github.com/trhura/clojure-humanize#datetime

Louis Kottmann 2020-11-27T17:30:46.468700Z

this uses clj-time and I was told to use java-time now

Louis Kottmann 2020-11-27T17:30:55.468900Z

datetimes in Java-land are a nightmare..

st3fan 2020-11-27T18:17:47.469500Z

Ok I have the stupidest thing that I've been staring at for too long...

st3fan 2020-11-27T18:18:37.469600Z

Syntax error compiling at (/tmp/form-init9098034618826095313.clj:1:73).
No namespace: devbots.bots.vacation

st3fan 2020-11-27T18:18:45.469800Z

ls -l src/devbots/bots/vacation.clj
-rw-rw-r-- 1 stefan stefan 1538 Nov 27 18:15 src/devbots/bots/vacation.clj

st3fan 2020-11-27T18:19:06.470Z

head src/devbots/bots/vacation.clj
(ns devbots.bots.vacation
  (:require [devbots.events :as events]
            [devbots.github :as github]
            [devbots.macros :as macros]
            [java-time :as jt]))

st3fan 2020-11-27T18:20:04.470300Z

(ns devbots.dispatcher
  (:require [taoensso.timbre :as timbre :refer [info]]
            [taoensso.carmine :as car :refer [wcar]]
            [taoensso.carmine.message-queue :as mq]
            [clojure.core.cache.wrapped :as cache]
            [devbots.events :as events]
            [devbots.util :as util]
            [devbots.bots.vacation :as vacation]
            [devbots.bots.lock-issue :as lock-issue]
            [devbots.bots.lock-pull-request :as lock-pull-request]
            [devbots.bots.needs-triage :as needs-triage]
            [devbots.bots.needs-review :as needs-review]))

st3fan 2020-11-27T18:20:13.470500Z

That is where it fails ...

st3fan 2020-11-27T18:20:27.470700Z

The file is in the right place with the right name with the right ns .. so wth

st3fan 2020-11-27T18:23:33.471500Z

OMG ... I had a test/devbots/bots/vacation.clj which I just renamed to vacation_test.clj (it did have the right devbots.bots.vacation-test namespace though

1
seancorfield 2020-11-27T18:37:24.472400Z

@raefaldhiamartya We have used both Jetty and http-kit at work. They're pretty much interchangeable although http-kit claims to be faster -- but most monitoring/observability solutions out there work much better with Jetty (we ended up switching from http-kit to Jetty because we use New Relic and it doesn't work very well with http-kit).

seancorfield 2020-11-27T18:38:12.472700Z

(rubber-duck debugging: figuring out the solution, just by explaining it to someone else)

Marcus 2020-11-27T18:58:55.473Z

Thanks @seancorfield! I will look into the code. 🙂

st3fan 2020-11-27T19:50:38.473100Z

yup

st3fan 2020-11-27T19:50:47.473300Z

being a lone coder is not always easy

st3fan 2020-11-27T19:50:59.473500Z

i do think out loud, but writing it down usually helps better 🙂

Louis Kottmann 2020-11-27T20:03:45.474400Z

Louis Kottmann 2020-11-27T20:03:47.474800Z

for the "time ago" thing, I ended up (painfully) writing this

seancorfield 2020-11-27T20:20:24.474900Z

I hear ya! Although I have a team mate, we've always worked remotely, so we're both almost "lone coders" 🙂

st3fan 2020-11-27T20:21:22.475400Z

I see logging is still the same mess I remember it was

seancorfield 2020-11-27T20:24:20.476300Z

@st3fan After a lot of back and forth at work, we ended up settling on clojure.tools.logging and log4j2 (and setting the JVM option -Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory

seancorfield 2020-11-27T20:24:46.476800Z

(and using the log4j2 adapters to pipe all the other logging libs through it)

seancorfield 2020-11-27T20:25:12.477400Z

;; use log4j 2.x:
    org.apache.logging.log4j/log4j-api {:mvn/version "2.13.3"}
    ;; bridge into log4j:
    org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.13.3"}
    org.apache.logging.log4j/log4j-jcl {:mvn/version "2.13.3"}
    org.apache.logging.log4j/log4j-jul {:mvn/version "2.13.3"}
    org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.13.3"}

st3fan 2020-11-27T20:25:33.477800Z

Right now I see Jetty and my own logging end up in different formats in the console ..

seancorfield 2020-11-27T20:26:17.478300Z

Yup, another reason to bridge all logging into one place.

st3fan 2020-11-27T20:26:53.478800Z

This sounds like something I should pour at least an hour into to understand and get right

st3fan 2020-11-27T20:31:26.479300Z

Clojure is a side project for me ... work is all Kotlin 🙂

seancorfield 2020-11-27T20:31:55.479500Z

Kotlin is nice. Better than Java or Scala 🙂

st3fan 2020-11-27T20:31:57.479700Z

I don't even write Kotlin actually - I'm managing the team, not writing code 😉

st3fan 2020-11-27T20:36:44.479900Z

coders gonna code

st3fan 2020-11-27T20:44:36.480100Z

Maybe I should find a Clojure job and get paid to do this

nate sire 2020-11-27T20:52:21.481200Z

is Clojure considered a really expressive language? meaning... can represent almost any algorithm or idea.

st3fan 2020-11-27T20:57:52.481600Z

yes and what the foundational clojure forms cannot express well you can build with macros and functions

zackteo 2020-11-27T20:59:14.482600Z

Can someone help me understand why this throws an error?

((fn [start stop]
   (loop [start start
          stop  stop]
     (if (start &gt;= stop)
       start
       (recur (inc start)
              stop)))) 1 4)

st3fan 2020-11-27T20:59:33.482900Z

because (start >= stop) should be (>= start stop)

zackteo 2020-11-27T20:59:59.483400Z

oh my goodness :man-facepalming:

st3fan 2020-11-27T21:00:03.483700Z

or maybe <= i also get confused with the notation 🙂

st3fan 2020-11-27T21:00:33.484700Z

no worries, earliet today i typed something like (defun something [] (return 123)) 🙂

zackteo 2020-11-27T21:00:44.485100Z

i keep being oblivious to that from time to time

st3fan 2020-11-27T21:01:30.485400Z

i find it specially hard when switching between languages

👍 1
zackteo 2020-11-27T21:02:16.486Z

yeahh, i think everything clicks but conditionals tends to be something i skip over

zackteo 2020-11-27T21:04:29.486900Z

I suppose I also need to understand how to read clojure error messages better - couldn't tell what error my line was on. So i thought the issue was with recur

seancorfield 2020-11-27T21:25:04.487100Z

Some of my roles have involved more management or more architecture than actual coding -- that's when my OSS projects get a lot more attention! When work is heavy coding, my OSS projects take a back seat. I just have to code to stay sane 🙂

william 2020-11-27T23:29:26.487900Z

here's a question of specs and namespace s:

william 2020-11-27T23:31:34.489800Z

I defined:

(ns minimal.spec
  (:require
      [clojure.spec.alpha :as s]))
(s/def ::my-spec ...)
and in the main file:
(ns minimal.core
    (:require
      [clojure.spec.alpha :as s]
      [minimal.spec :as spec]))

(s/conform :spec/my-spec ...)
but I get
unable to resolve spec: :spec/judgement
what's going on?

seancorfield 2020-11-27T23:41:57.490300Z

@meditans You need ::spec/judgement so the alias is auto-resolved.

seancorfield 2020-11-27T23:42:14.490600Z

(you have a single : instead of a double ::)

william 2020-11-27T23:44:18.491900Z

thanks @seancorfield (I can't wait to see your talk on the repl btw). But why do I need to autoresolve that? isn't :spec/judgement equivalent to :minimal.spec/judgement given my import? I was under the impression (maybe wrong) that :: added the current module

william 2020-11-27T23:44:42.492400Z

(I mean, it works, but I can't see why)

seancorfield 2020-11-27T23:45:07.493Z

No. :foo/bar is always just :foo/bar. But ::foo/bar will expand an alias foo into its namespace.

seancorfield 2020-11-27T23:45:25.493400Z

In the same way that ::bar expands to :current.namespace/bar

william 2020-11-27T23:46:30.494400Z

I see, so without the :: there's no namespace substitution! Thanks! Where can I find the complete semantic of ::?

seancorfield 2020-11-27T23:48:18.494900Z

I was just looking on http://clojure.org for that... I suspect it might be in the Reader section...

seancorfield 2020-11-27T23:49:27.495600Z

https://clojure.org/guides/weird_characters#autoresolved_keys (and the following section about namespace map syntax) touch on it -- but don't really show aliases being expanded...

seancorfield 2020-11-27T23:50:09.496Z

Oh, they do give an example further down in the namspace map syntax section!

william 2020-11-27T23:50:40.496300Z

I see, thanks for the pointer 🙂