Fork me on GitHub
#beginners
<
2019-08-14
>
Godwin Ko00:08:30

I’m using ns-unmap for easier code reload of defmulti/defmethod within REPL, but it caused exception when invoking uberjar standalone jar, any way I can detect if current environment is dev or not in order to skip those ns-unmap?

hiredman00:08:02

Use (def multimethod nil) instead

Godwin Ko01:08:30

@hiredman thx for your advise, although it works as if ns-unmap, packaging with uberjar still throw exception, I guess aot compilation don’t allow variable re-binding…

hiredman01:08:15

Don't use ns-unmap at all

hiredman01:08:43

Replace it with def the multimethod var to nil first

Godwin Ko01:08:20

ok got it, but yet to find a way to prevent standalone jar exception

Godwin Ko01:08:38

it turns out simply define the dispatch function separately did solve my issue!! 🎉

hiredman01:08:00

I would not be super surprised if you had some lurking namespaces issue with your project

hiredman01:08:54

Maybe not (trying to remember where and in what order the bytecode to look up vars is emitted)

GC04:08:39

Hey, I have a date format as "2017-02-14T12:00:00.000+4:00", I need it to convert so that it is in format YYYY-MM-DD, so basically get rid of time and timezone stuff. I used clj-time.coerce/from-string to convert it from String to DateTime Instant.

GC04:08:13

So how can I extract the year-month-date from this, so I need 2017-02-14 as output

GC05:08:11

I know how to do it using regex or partly use regex and partly date

GC05:08:34

but I want to know how to achieve this using the date format entirely

alexmiller06:08:34

check out the java.time.format package in the JDK

alexmiller06:08:37

user=> (def d (java.time.LocalDateTime/now))
#'user/d
user=> d
#object[java.time.LocalDateTime 0x643ba1ed "2019-08-14T01:23:05.972628"]
user=> (.format d (java.time.format.DateTimeFormatter/ofPattern "yyyy-MM-dd"))
"2019-08-14"

GC06:08:59

So, how to put LocalDateTime format for this : “2019-07-13T14:00:00.000+10:00”

GC06:08:12

How to convert this to localDateTiem

alexmiller06:08:48

what type are you starting with? what type do you want at the end?

GC07:08:51

so I am starting with this input - “2019-07-13T14:00:00.000+10:00” output- “2019-07-13"

alexmiller07:08:57

so string / string

GC07:08:30

So, need to convert input to locadateTime first

alexmiller07:08:33

so would be best to first parse from string to LocalDateTime, using a DateTimeFormatter (once you create a formatter, it can be used to either parse or format)

alexmiller07:08:44

then use a different formatter to format back to a string

alexmiller07:08:32

just be careful that you understand what you're doing with the timezone offset

GC07:08:57

I am using the joda time thing , it’s kind of a standard

alexmiller07:08:11

it's not anymore

GC07:08:25

here in my organisation, should have specified that

alexmiller07:08:26

the same developers that created joda developed the java.time packages which are now part of java

alexmiller07:08:46

java.time and joda are similar as they were created by the same people

alexmiller07:08:06

same formatter stuff exists

GC07:08:25

Okay, will have a look. I always had troubles with dates

Brandon Olivier09:08:59

If I’m in namespace app.db.core and I want to use a spec from app.db.entity is there a way to do that that doesn’t involve writing :app.db.entity/foo-spec every time I need to reference it?

valerauko10:08:51

You can do (require '[app.db.entity :as e]) and then it'd be just ::e/foo-spec

thanks3 4
ivan minutillo10:08:18

Hi! im stucked trying to use a local library in my clojure project. I created a checkouts folder at the source directory, and symlinked the local lib, but when i run lein ring server, it seems it totally ignores what's in the checkouts...

uosl13:08:08

I've never used checkouts, but running lein do pom, jar, install in your local library directory, then starting your project that depends on it (making sure it's listed as a dependency with the same version number), has always worked for me.

murtaza5210:08:06

@brandon149 you can also try (:require [app.db.entity :refer [::foo-spec]). I know it works with fn syms, I havent tried it with spec syms, but there is no reason it shouldnt work. You can also do refer-all to alias all the syms from that ns into the current ns.

Brandon Olivier11:08:47

@murtaza52 I tried out some stuff in the repl and it looks like doing a regular ns require will let you do :alias/foo

murtaza5211:08:40

yes that should work too, and is actually the better option in your case. I did not mention id bcoz @vale had already mentioned it.

meow15:08:21

Is there a major blog post that people refer to for setting up their Clojure dev environment?

uosl15:08:27

https://purelyfunctional.tv/guide/how-to-install-clojure is good for getting things installed. after that, you have to search for guides on the build tool you're going for (ie. https://clojure.org/guides/deps_and_cli is good for tools.deps)

dpsutton16:08:13

if you already use emacs or have been wanting to learn, then check out CIDER. emacs is a lot to learn and rewarding (i think) but has a long learning curve. Cursive is an excellent option and these two dominate the marketshare if i'm remembering the clojure survey results correctly. Outside of this there's Calva for VS code which reuses a lot of CIDER's underlying tooling and Chlorine for Atom. There's a really nice video from @seancorfield using Atom to fix a bug in a lib that is a nice showcase of its benefits and workflow. But once you choose from this list then just follow along with the docs/blogs about that tooling

calva 4
andy.fingerhut17:08:45

FYI, Clojure survey 2019 results for dev environment can be found at "Q12" here: https://www.surveymonkey.com/results/SM-S9JVNXNQV/

chrisulloa17:08:59

Error messages are important to a lot of people!

chrisulloa17:08:06

Didn’t realize, I guess after a while you get so used to them

andy.fingerhut18:08:14

I think anything unfamiliar, that at first seems confusing and/or you believe was done better in previous dev environments you worked in, you notice and wish for what you used to have 🙂

gerred21:08:56

I agree/disagree with this, and I have a specific why!

gerred21:08:36

tools.deps brought me back into the clojure fold because it drastically changes the Clojure environment imo and isn't talked about enough.

👏 4
gerred21:08:04

which may sound silly

andy.fingerhut22:08:12

I wouldn't call it silly, but if you feel that strongly about tools.deps bringing you back, have you considered writing an article about it?

andy.fingerhut22:08:21

(maybe you have, and I didn't notice -- sorry if so)

gerred22:08:02

I haven't!

gerred22:08:15

if that'd be helpful, I'll throw it into my list. 😄

gerred22:08:10

To me, the Clojure environment before tools.deps was so unfamiliar I couldn't justify the time investment with a whole cambrian explosion of many things going on and me having many interests through all of that.

gerred22:08:34

tools.deps just made sense. I can write a deps.edn file {:deps {}} and get rocking.

gerred22:08:21

did I spend some time coming up to speed with lein and project.clj? sure. but the ecosystem to date just has a lot of "this is how I solved it as someone experienced" and a lot less of what @seancorfield has already done with his breakdown of his $HOME level deps.edn

henrik13:08:38

I have to agree, deps was a lot easier to learn than project.clj.

henrik13:08:24

I started using it as a side-effect of using Ions, and now I just default to it where I can. Shadow-cljs has good support for sourcing dependencies from deps.edn as well.