Fork me on GitHub
#beginners
<
2018-04-19
>
Nikos05:04:56

I'm reading Web Development with Clojure by yogthos and I've noticed that the book is using metosin/ring-http-response. Has that been superseded by ring.util.response since the writing of the book?

Nikos05:04:29

If not, why would one use metosin/ring-http-response instead of ring.util.response? The github page of the former says that it's a "a drop-in-place replacement for ring.util.response", but I'm not sure what that means.

ikitommi05:04:57

@nikoszp the metosin-version maps all http-status code and with their own names like ok (200), found (302) and see-other (303). Ring has only few most used and have custom names for response (200), redirect (302) and redirect-after-post (303).

Nikos06:04:34

Got it, thank you!

seancorfield06:04:19

@nikoszp Clojure is not very opinionated about libraries but instead takes a mix'n'match approach. Both metosin/ring-http-response and ring.util.response were last updated in the tail end of 2017 so they're both stable and (reasonably) well-maintained. So pick whichever you prefer.

seancorfield06:04:21

A lot of Clojure libraries are very small and focused and therefore often "complete" and rarely in need of maintenance. This is very different to a lot of other technologies, so folks often ask "Is this library dead?"

Nikos06:04:36

Thanks for the insight!

ikitommi06:04:47

In the end, both just generate Ring maps: (ok "kikka") => {:status 200, :body "kikka", :headers {}}

👍 8
seancorfield06:04:26

It's all data, all the way down 🙂

seancorfield06:04:46

(sometimes it's better to learn to use the data than to learn the DSLs in these libraries)

seancorfield06:04:52

I think that Web Development book pushes Luminus, doesn't it? I'd recommend starting with Ring basics and learning how it works at a lower level -- Luminus has a fair bit of "magic" in it...

seancorfield06:04:09

Where I work, everything is built with Ring + either Compojure or Bidi + Selmer (sometimes). No frameworks.

Nikos06:04:39

Thanks, that's great advice! I'm reading the Ring documentation too in parallel. Btw, the first chapter of the book starts off with a luminus app but then the next chapter goes on to explore the elements of the Luminus stack, including Ring.

seancorfield06:04:18

The story I like to tell about this... I wrote one of the most popular MVC frameworks in Language X. I decided to port it to Clojure. We started to convert our Language X Framework Y apps over to Clojure Framework Y. We fairly quickly discovered that Framework Y didn't really add anything in Clojure so we decided to sunset it and just use the raw libraries instead.

seancorfield06:04:12

When you come from Language X, the lack of Framework Y can be a little unsettling... But it's normally because Clojure does not need an equivalent of Framework Y 🙂

👌 4
nakiya06:04:10

Anyone here using re-natal? Would anyone recommend it to someone who has not used react-native before?

gklijs16:04:19

I checked some example in the hope of quickly transforming a re-frame project to react native. Had it running fast, but the templating is a lot different, and has no real use, so gave up.

mfikes11:04:29

@duminda Yes. And there are users of re-natal in #cljsrn

shin14:04:01

Hi does anyone know if mount merges settings found in profiles.clj?

mathpunk17:04:02

ahhhhhhhhh how do people remember how contains? works? I have to look up the docs every time I want to know if 2 is in [0 1 2]

mathpunk17:04:37

wait, do I mean some? same question either way

mathpunk17:04:59

(some #{2} (range 0 10)) ;;=> 2 --- this is the same line i find every time i look up contains?, remember some, reread the "set as a function" trick

sundarj18:04:57

(#{} x) is equivalent to (get #{} x), like ({} x) is equivalent to (get {} x). contains? checks for the presence of a key (index) in an associative collection - in the case of sets, this is set membership some runs the function passed on every element of a collection, and if the return value is truthy, returns that return value, else nil

mathpunk16:04:44

riiiiight, and a set is 'really' the map {:x :x, 1 1, "item" "item"} so running it as a function gets the value associated with the key which happens to be the key. Thank you, I think this helps

4
dpsutton18:04:36

i do wish there was a member function

seancorfield18:04:43

I almost never use contains? -- and when I do, it's only ever on a hash map where I specifically need to support nil values. Even there I mostly prefer either (the-key the-map ::not-found) or (get the-map the-key ::not-found)

👍 4
seancorfield18:04:44

Hmm, interesting, I have just twelve occurrences of contains? in my code but my colleague uses it a lot -- about 80 occurrences in their code. And that's in a total of about 80,000 lines of Clojure.

grierson18:04:40

What SQL lib do you guys use? HugSQL, Toucan, Korma?

cjohansen19:04:31

Datomic troll

💯 12
sveri19:04:09

clojure/java.jdbc

val_waeselynck19:04:40

Start with plain old clojure.java.jdbc, and specialize if necessary.

seancorfield19:04:39

@U3G3MBL9H Korma has gone unmaintained for a while (although I believe it is being updated now) but it is a bit too ORM-like for most Clojurians tastes I think.

grierson19:04:50

I think I’m going to stick with jdbc then transition to HuqSQL and Walkable when I need to. Thanks for the advice guys.

seancorfield19:04:05

HugSQL is great if you like keeping your SQL outside your code. HoneySQL is a great Clojure DSL for composable queries in code -- we use it very heavily.

seancorfield19:04:28

And we use org.clojure/java.jdbc very, very heavily (at World Singles). Also, I maintain that.

seancorfield19:04:07

(we run a hundred dating sites on top of java.jdbc and Percona!)

grierson20:04:26

Stupid question, how do I unit test SQL queries? I’m using HugSQL and would like to test my query is correct given different database states.

dadair20:04:54

You could use a test DB, and then use clojure.test fixtures to set up the DB state in a transaction that rolls-back after each test? Then you can just use the query functions.

v3ga21:04:18

Can someone tell me the difference between clojure.lang.Cons and PersistentList?

oVerde21:04:24

Clojurist newb help in need! Interop troubles me. So I have this beauty piece of Java

AccessToken token = new AccessToken.Builder(twilioAccountSid, twilioApiKey, twilioApiSecret)
        .identity(identity).grant(grant).build();

    System.out.println(token.toJwt());
So I tried this beautier Cloj:
(doto (AccessToken$Builder. "twilioAccountSid" "twilioApiKey" "twilioApiSecret")
                      (.identity    "indentity")
                      (.grant
                        (doto (ChatGrant.)
                          (.setServiceSid   "ServiceId")))
                      (.build))
BUT! How do I solve the .toJwt() part? I still keep getting CompilerException java.lang.IllegalArgumentException: No matching field found: toJwt for class java.lang.String, compiling reading the error I understand I cant call .toJwt to a string. And here I stop don’t knowing where to go 😞

sundarj21:04:58

@overde how are you trying to call .toJwt? also note that doto returns the first argument, so it'll be the AccessToken$Builder instance, not the return value of .build.

oVerde21:04:13

was placing this doto to a def and calling like (.-toJwt token)

oVerde21:04:36

but looks my doto is already wrong?

sundarj21:04:43

the syntax for a method call is (.method obj); (.-toJwt token) would be a field access

oVerde21:04:03

Something like this @sundarj?

sundarj21:04:59

right, although you can use the -> macro to clean that up

sundarj21:04:59

doto is intended to be used when you want to do something to an object, but return that same object, like with setters

oVerde21:04:15

No luck CompilerException java.lang.IllegalArgumentException: No matching field found: toJwt for class com.twilio.jwt.accesstoken.AccessToken, compiling

sundarj21:04:07

that should be (.toJwt token), since `toJwt is a method

oVerde21:04:33

I missread your explanation of field access

oVerde21:04:52

Now everything is fine @sundarj, so many thanks!

sundarj21:04:52

hurrah! glad i could help 🙂

severo22:04:14

anybody integrated nvim with vim-fireplace + piggieback to develop in cljs?

severo22:04:26

works fine with clj, but not with cljs 😞

severo22:04:29

feel like i'm missing something . Do I need to run a :Piggieback command in nvim to get things going?