Fork me on GitHub
#beginners
<
2018-02-06
>
roelof06:02:13

good morning all

roelof07:02:51

some intelij expert who can help me figure out what to enter on the module part : https://pasteboard.co/H6lRPXp.png

timo10:02:45

does anyone know a more sophisticated re-frame app that I can learn some reg-event-fx testing from?

manutter5112:02:29

@roelof I’m guessing the “no module selected” message is because the Leiningen Project field isn’t showing your project. If you created your project with lein new and then opened it in IntelliJ using File -> Open, it’s possible that IntelliJ failed to recognize it as a Clojure project. The way I start new Clojure projects is by creating it with lein new, and then in IntelliJ, under the File menu, select New -> From Existing Sources. That will let you create the project as a leiningen-based Clojure setup, and things like this should just work.

roelof14:02:53

oke, after a few times importing the project and deleting the .idea folder everything works fine

roelof14:02:27

It seems that Intelij and Cursive have some problem with importing a luminus project

timo14:02:02

hey there, I am watching lambda island '33. Running ClojureScript Tests' and he uses emacs. I am using spacemacs and I wonder if I should use inf-clojure as well. it looks good! hitting a key and having output in the repl seems awesome. How do you do it with spacemacs? Is there an alternative way?

cperrone15:02:19

@timok I haven’t seen the episode, but I assume you could do a cider-jack-in-javascript (SPC-m-“). Once connected, you could do (SPC-m-e-e) and see the result of each expression inline. (Or open a repl buffer and do SPC-m-s-e)

timo15:02:10

ah, I was searching for quite exactly that. I knew this was existing

timo15:02:06

but SPC-m-s-e always tells me 'Indenting region...done'?!?

cperrone17:02:38

@timok you’ll get that if you don’t have a repl connected (cider-jack-in-javascript) and its buffer open (so that the code buffer can “send it” to it).

roelof17:02:16

why is here timbre/info not resolved :

(ns hipstr.handler
  (:require [compojure.core :refer [defroutes]]
            [hipstr.routes.home :refer [home-routes]]
            [hipstr.middleware :refer [load-middleware]]
            [hipstr.session-manager :as session-manager]
            [noir.response :refer [redirect]]
            [noir.util.middleware :refer [app-handler]]
            [ring.middleware.defaults :refer [site-defaults]]
            [compojure.route :as route]
            [taoensso.timbre :as timbre]
            [taoensso.timbre.appenders.rolling :as rolling]
            [selmer.parser :as parser]
            [environ.core :refer [env]]
            [cronj.core :as cronj]))

(defroutes base-routes
  (route/resources "/")
  (route/not-found "Not Found"))

(defn init
  "init will be called once when
   app is deployed as a servlet on
   an app server such as Tomcat
   put any initialization code here"
  []
  (timbre/set-config!
    [:appenders :rolling]
    (rolling/make-rolling-appender {:min-level :info}))

  (timbre/set-config!
    [:shared-appender-config :rolling :path] "logs/hipstr.log")

(defn destroy
  "destroy will be called when your application
   shuts down, put any clean up code here"
  []
  (timbre/info "hipstr is shutting down...")
  (cronj/shutdown! session-manager/cleanup-job)
  (timbre/info "shutdown complete!"))

;; timeout sessions after 30 minutes
(def session-defaults
  {:timeout (* 60 30)
   :timeout-response (redirect "/")})

(defn- mk-defaults
       "set to true to enable XSS protection"
       [xss-protection?]
       (-> site-defaults
           (update-in [:session] merge session-defaults)
           (assoc-in [:security :anti-forgery] xss-protection?)))

(def app (app-handler
           ;; add your application routes here
           [home-routes app-routes]
           ;; add custom middleware here
           :middleware (load-middleware)
           ;; timeout sessions after 30 minutes
           :session-options {:timeout (* 60 30)
                             :timeout-response (redirect "/")}
           ;; add access rules here
           :access-rules []
           ;; serialize/deserialize the following data formats
           ;; available formats:
           ;; :json :json-kw :yaml :yaml-kw :edn :yaml-in-html
           :formats [:json-kw :edn]))

roelof17:02:17

the same with app-routes and session-default

justinlee18:02:55

@roelof what’s the actual error message you are getting? I’m wondering if you’ve added them to your :dependencies in your project.clj. They won’t get installed until you do that. I have to restart my lein when I do that because it does not know to install additional dependencies unless you restart

roelof18:02:10

this one was already added to the dependencies : [com.taoensso/timbre "3.3.1"]

roelof18:02:40

I see cannot resolve errror messages. I have not start up lein ring server so far

roelof18:02:39

when doing so I see this error message : exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: app-routes in this context, compiling:(hipstr/handler.clj:53:10)

seancorfield18:02:52

@roelof Well, you don't have app-routes defined so that error is correct.

roelof18:02:43

hmm, wierd that it worked before. I only added timbre logging

seancorfield18:02:27

You have base-routes -- did you rename something?

roelof18:02:26

nope, I only changed something in the init part

roelof18:02:55

and also here I do not see a app-routes

seancorfield18:02:03

Right, but that has

[home-routes album-routes test-routes base-routes]

seancorfield18:02:40

So you've replaced that with [home-routes app-routes] but you have not defined app-routes.

roelof18:02:24

wierd, that part is not mentioned in the book.

roelof18:02:49

Maybe I have to look for a book which takes first these steps

bronsa19:02:41

destructuring is about.. destructuring data, not constructing

bronsa19:02:12

if you want to assign defaults, (let [m (merge my-defaults-map m)] is usually how it's done

bronsa19:02:25

what about that?

andy.fingerhut19:02:10

The way destructuring works in Clojure, :or can create default values for individual pieces that you extract, but they do not change the result assigned using :as

bronsa19:02:59

right, think of that destructuring as functionally equivalent to (defn [movie] (let [category (get movie :category "Category not found")] (str category))

grierson19:02:19

right, ok. Thank you.

andy.fingerhut19:02:11

It may be surprising to some, of course, but I very strongly suspect it is working as designed.

bronsa19:02:49

it's without a doubt the intended behaviour

bronsa19:02:19

destructuring doesn't describe the input data structure, it just pulls out parts of it

andy.fingerhut19:02:17

Personally, I would only say that if I recalled a CLJ bug report that was declined with such a reason given (which might even exist)

andy.fingerhut19:02:51

But @bronsa has dug much deeper into many of these things than I have.

bronsa19:02:02

"What is Destructuring? Destructuring is a way to concisely bind names to the values inside a data structure"

bronsa19:02:23

i guess that's not authoritative as that's a guide and not the reference

andy.fingerhut19:02:40

There isn't much there explicitly about any kind of interaction when using both :as and :or in the same map destructuring, although this sentence is a good strong hint: "If you need access to the entire map, you can use the :as key to bind the entire incoming value"

grierson19:02:11

If I were to use (let [m (merge my-defaults-map m)] then I would I have to create conditionals for each key that doesn’t exist if I want to default it to some value?

bronsa19:02:26

it depends

bronsa19:02:37

look at the direction of that merge

bronsa19:02:45

you're merging your map into the defaults map

bronsa19:02:11

meaning that every binding in the defaults map that already exists in your map, will be overridden by the value in your map

bronsa19:02:29

so if you write it like this, no conditional is needed

grierson19:02:34

alright, I didn’t spot that. Thank you.

roelof21:02:19

someone knows a good book to learn luminus without the todo example

shaun-mahood21:02:32

@roelof: You're looking for a book to learn ouminus?

roelof22:02:32

@shaun-mahood yep, im looking for a book to learn luminus and not a todo site

shaun-mahood22:02:39

@roelof: You picked a good thing to want a book about - https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition Written by the author of Luminus