Fork me on GitHub
#beginners
<
2020-11-27
>
Marcus15:11:41

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?

Marcus15:11:41

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"

Marcus15:11:38

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

Marcus15:11:29

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

Louis Kottmann16:11:04

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

Louis Kottmann17:11:46

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

Louis Kottmann17:11:55

datetimes in Java-land are a nightmare..

Igor Garcia15:12:55

@U01CVNTDF34 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 Kottmann16:12:28

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

Louis Kottmann16:12:22

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

Louis Kottmann16:12:31

but it's definitely more complete than java-time

Igor Garcia17:12:25

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

Louis Kottmann17:12:42

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

Louis Kottmann17:12:35

that duckling lib looks awesome

Louis Kottmann17:12:40

I never saw it before!

Louis Kottmann17:12:44

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

Louis Kottmann17:12:36

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

Igor Garcia18:12:18

@U01CVNTDF34 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 Kottmann18:12:47

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

๐Ÿ‘ 3
Louis Kottmann18:12:16

(uses tick)

๐Ÿ‘ 3
Igor Garcia13:12:11

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 Kottmann18:12:27

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

scythx16:11:40

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.

seancorfield18:11:54

Clojure tends to prefer composing libraries over using frameworks. compojure-api is probably a good place to start looking if you want to build an API. Pretty much all the web libraries in Clojure are based on Ring. The default adapter is the built-in Jetty web server and that's a good, solid choice for production usage.

โค๏ธ 3
seancorfield18:11:24

@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).

scythx00:11:33

okay, thank you very much!

Michaรซl Salihi03:11:59

@raefaldhiamartya You can also take inspiration here http://www.todobackend.com/ There is 4 Clojure implementations including a recent one I did with the Ring Reitit stack.

scythx06:11:29

Pretty useful, thank you!

๐Ÿ‘ 3
st3fan18:11:47

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

st3fan18:11:37

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

st3fan18:11:45

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

st3fan18:11:06

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]))

st3fan18:11:04

(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]))

st3fan18:11:13

That is where it fails ...

st3fan18:11:27

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

st3fan18:11:33

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

duckie 3
seancorfield18:11:12

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

st3fan19:11:47

being a lone coder is not always easy

st3fan19:11:59

i do think out loud, but writing it down usually helps better ๐Ÿ™‚

seancorfield20:11:24

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

st3fan20:11:26

Clojure is a side project for me ... work is all Kotlin ๐Ÿ™‚

seancorfield20:11:55

Kotlin is nice. Better than Java or Scala ๐Ÿ™‚

st3fan20:11:57

I don't even write Kotlin actually - I'm managing the team, not writing code ๐Ÿ˜‰

st3fan20:11:44

coders gonna code

st3fan20:11:36

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

seancorfield21:11:04

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 ๐Ÿ™‚

seancorfield18:11:54

Clojure tends to prefer composing libraries over using frameworks. compojure-api is probably a good place to start looking if you want to build an API. Pretty much all the web libraries in Clojure are based on Ring. The default adapter is the built-in Jetty web server and that's a good, solid choice for production usage.

โค๏ธ 3
Marcus18:11:55

Thanks @seancorfield! I will look into the code. ๐Ÿ™‚

Louis Kottmann20:11:47

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

st3fan20:11:22

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

seancorfield20:11:20

@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

seancorfield20:11:46

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

seancorfield20:11:12

;; 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"}

st3fan20:11:33

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

seancorfield20:11:17

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

st3fan20:11:53

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

nate sire20:11:21

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

st3fan20:11:52

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

zackteo20:11:14

Can someone help me understand why this throws an error?

((fn [start stop]
   (loop [start start
          stop  stop]
     (if (start >= stop)
       start
       (recur (inc start)
              stop)))) 1 4)

st3fan20:11:33

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

zackteo20:11:59

oh my goodness :man-facepalming:

st3fan21:11:03

or maybe <= i also get confused with the notation ๐Ÿ™‚

st3fan21:11:33

no worries, earliet today i typed something like (defun something [] (return 123)) ๐Ÿ™‚

zackteo21:11:44

i keep being oblivious to that from time to time

st3fan21:11:30

i find it specially hard when switching between languages

๐Ÿ‘ 3
zackteo21:11:16

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

zackteo21:11:29

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

william23:11:26

here's a question of specs and namespace s:

william23:11:34

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?

seancorfield23:11:57

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

seancorfield23:11:14

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

william23:11:18

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

william23:11:42

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

seancorfield23:11:07

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

seancorfield23:11:25

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

william23:11:30

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

seancorfield23:11:18

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

seancorfield23:11:27

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...

seancorfield23:11:09

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

william23:11:40

I see, thanks for the pointer ๐Ÿ™‚