Fork me on GitHub
#beginners
<
2019-09-20
>
sova-soars-the-sora04:09:51

what do you all use to send e-mail from your application?

sova-soars-the-sora04:09:03

I used postal years ago but it seems to no longer be developed

andy.fingerhut04:09:32

If it still works, does it need to be changed? (I do not know if it still works)

sova-soars-the-sora04:09:48

um. i think it works actually

andy.fingerhut04:09:21

If the underlying language and libraries it relies upon value backwards compatibility, and the things it interoperates with, then changes are needed less often.

sova-soars-the-sora05:09:34

sweeps typos under rug

David Omar06:09:10

What is the idiomatic way to reject a function call if parameters do not meet the expectations? Let's say a function only works in non-empty lists, and I call that function with an empty list.

David Omar06:09:15

Does it need to be specified with spec?

Jakub Holý20:09:57

No, you can use preconditions like {:pre [(some-predicate? my-arg1)...]}

Lennart Buit06:09:00

you can spec it with fdef, e.g. by saying that its input should be a (s/coll-of something? :min-count 1)

Jakub Zika06:09:00

Good Morning everybody. I decied to do a webapp from ground up. But the documentation... it is so fragmented, everybody is using different libraries, a lot of things are deprecated etc... Can somebody help me here? I would love to use sse-consumer as SSE which updates my HTML generated by HICCUP (function (html-layout/driver-monitoring-country "Driver Monitoring" country-selection)) renders HTML. I know that there is async abstraction in http-kit but it looks different than "native" async that i would like to use as I already implemented one part in it. So if i can stay with ring + compojure + async it would be great. This is my async block - when I get driver-status, something is saved to the database and sse-consumer writes out message.

(defn sse-consumer
  "Accept messages and persist them to a database."
  []
  (fn [req res raise]
  (let [in (chan (sliding-buffer 64))]
    (go-loop [data (<! in)]
      (when data
        (do
          (println (format "sse-consumer received message %s" data))
          (recur (<! in)))))
    in)))

(defn database-consumer
  "Accept messages and persist them to a database."
  []
  (let [in (chan (sliding-buffer 64))]
    (go-loop [data (<! in)]
      (when data
        (do
          (save-driver-status)
          (recur (<! in)))))
    in))

(defn producer
  "Produce messages and deliver them to consumers."
  [& channels]
  (go
    (doseq [msg (get-driver-status)
            out channels]
      (<! (timeout 300000))
      (>! out msg))))

(xbim.driver-data/producer (xbim.driver-data/database-consumer) (xbim.driver-data/sse-consumer)) 
These are my routers
(defroutes route-map
           (GET "/driver-monitoring" {cookies :cookies}
             (html-layout/driver-monitoring-general "Driver Monitoring" cookies))
           (GET "/driver-monitoring/custom" [country-selection]
             (do (println country-selection)
             (html-layout/driver-monitoring-country "Driver Monitoring" country-selection)))
           (route/not-found "<h3>Route Not defined!</h3>"))  
These are my wrappers
(def app
  (-> route-map
      (wrap-resource "public")
      (wrap-file-info)
      (ring.middleware.session/wrap-session)
      (wrap-cookies)
      (compojure.handler/site))) 
Thank you very much.

Jakub Zika07:09:42

https://www.lucagrulla.com/posts/server-sent-events-with-ring-and-compojure/ This tutorials leads just to...

Fri Sep 20 08:59:01 CEST 2019 [worker-3] ERROR - GET /async
clojure.lang.ArityException: Wrong number of args (1) passed to: xbim.core/fn--18358/fn--18359
	at clojure.lang.AFn.throwArity(AFn.java:429)

Lennart Buit06:09:06

you can spec it with fdef, e.g. by saying that its input should be a (s/coll-of something? :min-count 1)

Lennart Buit06:09:30

(uh did I send doubly? flaky internet)

David Omar07:09:22

hahaha, yes. But thank you. I'll check that out.

David Omar08:09:39

Hi again. I just finished writing the spec for one function my-function inside namespace. I also created a test-my-namespace.clj inside test. Then, I was able to call (stest/check my-function)`, and I got this output:

;; => ({:spec #<[email protected]>,
;;      :sym namespace.line/my-function,
;;      :clojure.spec.test.check/ret {:num-tests 1000, :pass? true, :result true, :seed 1568968371375, :time-elapsed-ms 5851}})

David Omar08:09:30

But now I'd like to know how to set those generated tests, so they run when I run lein test from the terminal.

David Omar08:09:17

In the same way a test defined with deftest would have run.

David Omar08:09:27

I've read the guide on spec and haven't found it yet. In the guide, it lists the different ways to build the generators. And the third one says >Use test.check or other test.check compatible libraries (like test.chuck) https://clojure.org/guides/spec#_custom_generators

David Omar08:09:23

I don't know if that's what I'm looking for. Specially since it's the least preferred.

David Omar09:09:59

Wow. Just checked the first one. Very creative. I think I'll stick with that one. Thanks!

patientplatypus13:09:51

im having a really hard time getting a CORS middleware to return 200 on options requests, and was hoping someone might help walk me through it

Andros14:09:58

Hi! I'm having a problem doing a redirection with Ring. If I'm on a page with the POST method, doing the redirection will keep it. How can I force all my redirections to be GET? Thank you in advance.

Andros07:09:01

Thank you!

Andros07:09:52

I just tested it and it doesn't work. Crashes directly into anti-forgery token

patientplatypus14:09:27

does anyone have any idea why this wont pass cors? i have been at this for hours and hours and hours https://gist.github.com/patientplatypus/810e8719a3c3905c3c2f04b966a3c624 this shouldnt be this hard!

seancorfield17:09:42

@pweyand What's with the preflight stuff in that code? You should just be able to use wrap-cors but it needs to be the outermost layer of middleware, e.g.,

(-> handler
    (main-middleware)
    (wrap-cors ,,, various CORS options here))

seancorfield17:09:32

Here's what we have at work:

(-> handler
    ,,, other middleware ,,,
    (ring-cors/wrap-cors 
                               :access-control-allow-headers #{"accept"
                                                               "accept-encoding"
                                                               "accept-language"
                                                               "authorization"
                                                               "content-type"
                                                               "origin"}
                               :access-control-allow-methods [:delete :get
                                                              :patch :post :put]
                               ;; 24 hours (in seconds) -- note that only Firefox
                               ;; will honor this; other browsers cap lower!
                               :access-control-max-age "86400"
                               :access-control-allow-origin #".*"))

seancorfield17:09:15

wrap-cors handles the preflight check internally.