Fork me on GitHub
#beginners
<
2020-07-13
>
alexmiller00:07:03

this is a bug in core.unify that was fixed years ago (macro emitting fn with a qualified symbol, which violates the spec)

alexmiller00:07:53

I would guess that using newer deps would pull it in, but I'm not sure what exactly the scope of that is (how much of the dep tree) would need to be updated.

alexmiller00:07:17

I would expect adding the newest version of org.clojure/core.unify as a dep would probably fix this problem, but I'm not sure if there are other things that should be updated too

alexmiller00:07:14

newest version is "0.5.7"

alexmiller00:07:06

and just as a data point on stasis, I have a static site I've been running on stasis for years and still do, but I don't really mess with it much

👍 1
dpsutton01:07:54

A common culprit of this is lein ring server. It needs to be 0.12.5 or 0.5.12 (on mobile)

👍 1
Micah Redding01:07:58

Thanks! Updating Lein Ring Server did the trick, I assume by also updating the org.clojure/core.unify dependency.

dpsutton01:07:23

Yeah it’s transitive

g02:07:08

when importing a protocol from another namespace and attempting to invoke it in a deftype , i get clojure.lang.Var cannot be cast to java.lang.Class

g02:07:58

i’m importing it as :require [namespace.ns :refer [ProtocolThing]]

g02:07:10

anything seem obviously wrong?

alexmiller02:07:35

how are you using it in the deftype?

g02:07:43

(deftype TypeName [] ProtocolThing …. )

alexmiller02:07:21

should be fine - maybe you have some bad repl state?

g03:07:42

ugh… yep

g03:07:46

thanks 😕

👍 1
stopa03:07:40

noob compojure question:

(defroutes
  routes
  (POST "/api/" [] emails-handler)
  ....
  (POST "/api/me/checkout/webhook" [] checkout-webhook-handler)

  ;; static assets
  (resources "/" {:root static-root})
  (GET "*" [] (render-static-file "index.html")))

... 

        app (-> routes
                wrap-keyword-params
                wrap-params
                (wrap-json-body {:keywords? true})
                wrap-json-response
                wrap-cors)
^ Above is a slice of my app with compojure. problem: Stripe's webhook checkout-webhook-handler requires the request body to be a string, so I can run sig verification Buut because I wrap all the routes with wrap-json-body -- I think this eats the input stream, and I can no longer get the value as a json string. Is there a simple way I can make
(POST "/api/me/checkout/webhook" [] checkout-webhook-handler)
Out of those wraps?

stopa04:07:29

Update: I think the answer is:

(defroutes
  api-routes
  (context "/api" []
    (POST "/emails" [] emails-handler)
    ...))

(defroutes
  webhook-routes
  (POST "/webhooks/stripe" [] webhooks-stripe-handler))

(defroutes
  static-routes
  (resources "/" {:root static-root})
  (GET "*" [] (render-static-file "index.html")))
... 
        app (routes
              (-> api-routes
                  wrap-keyword-params
                  wrap-params
                  (wrap-json-body {:keywords? true})
                  wrap-json-response
                  wrap-cors)
              webhook-routes
              static-routes)
Buut for some reason I am not able to trigger the webhook handler.

stopa19:07:27

Update: The reason this didn't work, is because my wrap-cors middleware (custom written), would always add into response headers. This would tell ring to "stop" checking other routes, as it did get a response back

dpsutton04:07:57

I thought the json middleware only turned it into json when the content type was application/json

👍 1
stopa04:07:40

indeed -- unfortunately though -- stripe's webhook request does say application/json xD

stopa04:07:04

(to be fair it is -- just in order to verify the signature i need the plain string)

Micah Redding15:07:00

What's the best way to evaluate available libraries? For example, I'm trying to decide on a Markdown parser, by looking through https://clojars.org — is this the best way to see what's popular, updated, etc? Is there a better place to look?

phronmophobic16:07:25

I always just search duckduckgo for "clojure <thing>"

phronmophobic16:07:20

usually that will turn up results on github which I think generally has more relevant information for deciding which library might be the best fit

Adrian Smith14:07:51

I was thinking this the other day it'd be nice if Clojars had a popular section or trending section etc

dpsutton15:07:41

That’s probably the best place to look. There’s also interop too though

1
👍 1
seancorfield17:07:57

@micah688 https://www.clojure-toolbox.com/ can be a good place to look for libraries that solve specific problems. It's not exhaustive and it's not always completely up-to-date but it can give you a sense of where the ecosystem is for a particular task.

👍 1
bitpadawan18:07:39

for new projects, tools.deps, lein or something else?

seancorfield20:07:08

@bitpadawan I would recommend the Clojure CLI / deps.edn at this point for new projects. Create the new project with clj-new (`clj -A:new ...` if you are using the aliases from my dot-clojure repo) so that it has a full pom.xml and some useful basic aliases in deps.edn.

ashnur20:07:32

Hi, what is the idiomatic way to dynamically create the vector passed to select-keys? I have a fixed set of keys that I want to always select and a single key that only some of the time.

noisesmith20:07:18

it can be any collection (eg. set, vector, list) - you can use the standard collection ops to add or remove elements

noisesmith20:07:56

artificial example

user=> (select-keys {:a 0 :b 1 :c 2} (conj #{:a} :c))
{:c 2, :a 0}

seancorfield20:07:18

Sounds like (cond-> [:fixed :set :of :keys] (some-time) (conj :single-key)) ?

ashnur20:07:27

exactly that, thank you!

seancorfield20:07:30

(set or vector)

noisesmith20:07:18

yeah, I suggest set for doing this dynamically, since sets have the semantics we like (you can remove items by equality, you don't care about order, having an item twice has no meaning)

ashnur20:07:31

I got to conj but I was wondering how to not add a nil to the set/vector of keys

noisesmith20:07:42

nil is just another value

ashnur20:07:58

sure, but I didn't want to add it 🙂

noisesmith20:07:11

sorry, misread

noisesmith20:07:32

you can just do an unconditional (disj s nil) after merging in the keys

ashnur20:07:36

good advice on set, I am using cljs and still operating with js mindset, so I overuse vectors 😞

ashnur20:07:52

in js if you want to do functional programming, you need to use arrays constantly

Kamuela22:07:50

@ashnur not if you use lodash

ashnur23:07:21

I don't get this joke

👍 1
Kamuela09:07:12

It’s not a joke? Lodash lets you apply functions that transform all collections rather than just arrays

ashnur09:07:38

I see, that explains why I didn't get it : D

ashnur10:07:33

So what kind of collections do you use in javascript? 🙂 I like to use Object literals, but if I need to take an object and manipulate it, I always do an .entries first and then a fromEntries when I finished, or something analogues. Do you use Set a lot with lodash?

JP Silva22:07:37

hi folks, which libraries, books and/or tutorials do you recommend for writing a web (rest) api?

JP Silva22:07:07

should I go with luminus or stick to compojure + ring or something else?

Tamizhvendan S05:07:34

You may find this article which I wrote almost two years ago. https://www.demystifyfp.com/clojure/blog/restful-crud-apis-using-compojure-api-and-toucan-part-1/ If I am starting today, I’d be replacing the following

Tamizhvendan S05:07:47

Componjure-api with Reitit Prismatic Schema with core.spec toucan with HoneyEQL I am planning to write about this in near feature