This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-25
Channels
- # beginners (20)
- # boot (25)
- # cider (1)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (1)
- # clojure (79)
- # clojure-austin (2)
- # clojure-berlin (13)
- # clojure-dusseldorf (1)
- # clojure-germany (7)
- # clojure-russia (10)
- # clojure-serbia (1)
- # clojure-spec (18)
- # clojure-uk (4)
- # clojured (1)
- # clojurescript (90)
- # cursive (10)
- # datomic (7)
- # emacs (14)
- # hoplon (6)
- # luminus (16)
- # lumo (4)
- # numerical-computing (2)
- # om (25)
- # om-next (1)
- # onyx (11)
- # pedestal (10)
- # protorepl (1)
- # reagent (11)
- # remote-jobs (1)
- # ring (1)
- # rum (38)
- # spacemacs (5)
- # test-check (7)
- # untangled (122)
- # vim (1)
- # yada (8)
Great call @hiredman !
I'm gonna start with my first clojure web app today, and thought to follow this: http://clojure-doc.org/articles/tutorials/basic_web_development.html
riz: @riz After going through that exercise, you might want to have a look at https://github.com/danielsz/system-dependency-injection/tree/master. It has a similar stack, but it wires up everything together by leveraging some neat Clojure idioms.
@riz Ring and Compojure are widely used in production. H2 not necessarily, but it is just a handy placeholder for a store because it ships as a jar. Hiccup is widely used too, but not essential.
I'm trying to get a quick and dirty timestamp, and (new java.util.Date)
returns #inst "2017-02-25T12:43:15.284-00:00"
. How do I access that string?
(.toString (new java.util.Date))
it will return something like "Sat Feb 25 14:50:28 EET 2017"
user=> (.toString (Instant/now)) "2017-02-25T12:53:35.660Z"
metametadata: or (str (new java.util.Date))
agree )
Instant
is from java.time
which should be preferred to java.util
in repl: (import [java.time Instant])
in (ns ...)
: (:import (java.time Instant))
java.time is from java 8
riz: java: new java.util.Date().getTime() clojure: (.getTime (new java.util.Date))
riz if you’re going to anything non-trivial with dates I strongly recommend using https://github.com/clj-time/clj-time
well, pre-java8 java date handling is notoriously bad, so I’d just bite the bullet and use clj-time anyway 😄
here’s how you get unix time for instance:
(c/to-long (t/date-time 1998 4 25))
=> 893462400000
@schmee I wouldn't use clj-time for any new project. It's recommended not to use joda time anymore and instead use java.time.
Frankly, I'm not a fan ob wrappers that add nothing but some convenience. java.time is already immutable so it's quite idiomatic for clojurians
I don't mind the dot
-syntax, it's also got great documentation. If I redo some things i just write a few convenience functions
usually I’d agree about wrappers, but IMO datetime stuff is pervasive enough to warrant an exception
They were for my use-case. Other might need completely different functions. I used clj-time before but I'm much happier with just staying to java.time now.
I tried clojure.java-time
wrapper but then quickly switched to bare java.time
because Clojure lib didn't play well with Cursive IDE and I had to consult with JDK docs anyway to figure stuff out. The only minor drawback is dot-syntax.
The clj-time team are planning a 2.0 version based on java.time
at some point. It will mostly be a drop-in replacement for the 1.0 version but we're still nailing down how to handle the few differences that will be required.
@ghadi Thanks. In the docs there is mention of any - TaggedObject. What does that refer to?
if you read something tagged (a fressian tag), that doesn't have a readhandler registered, you'll get a TaggedObject that has the {:tag and :value}. This is so that you can write it back without understanding what it was
I'd like to create a new type which is like a vector, except where (= coll (reverse coll))
is true. Is there a terse way to create a new type which defaults to the same protocol implementations of another type?
So far, I've just been using a vector and comparing them with a function i've written called branches-equal?
. The issue with this is that functions such as distinct
do not work as I'd like, since they do not use my custom compactor function
I feel completely stupid: If given two numbers: a and b, and one of them has to be positive: - they can't both contain positive value at the same time - they can't be both nil or zero at the same time How do I check for this?
ignoring the nil requirement, you're looking for xor essentially. (not= (pos? a) (pos? b))
@dmh43 I think you just define a new type that declares the same interfaces as a collection and only implements new functions where it needs to like https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L121
i kinda like the "group-by a predicate, then destructure the booleans" trick... sparingly
group-by will return a map though @ghadi 😉
so it's something like (= 1 (count pos))
ah right, it's a list
forgot