Fork me on GitHub
#beginners
<
2018-11-22
>
adam00:11:06

@mario.cordova.862 I was able to add some environment variable from the window you mentioned above. Still didn't solve my issue with profiles.clj but at least Cursive REPL is reading my DB credentials now.

Mario C.00:11:14

You can try catting your .lein-env and see if your environment variable is being built

Mario C.00:11:22

how do you run you app e.g lein with-profile dev,user run?

adam00:11:54

I run the webserver using lein ring server or lein ring server-headless. REPL: lein repl or via Cursive

Mario C.00:11:10

In the project directory if you run cat .lein-env

Mario C.00:11:20

does your db environment show up? @somedude314

adam01:11:18

@mario.cordova.862 cat: .lein-env: No such file or directory

adam01:11:37

lein new compojure hello-world didn't create such file for me.

seancorfield01:11:45

.lein-env is specific to the environ library

Mario C.01:11:45

How do your project.clj look like? @somedude314

adam02:11:28

Like this:

(defproject myproject "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [compojure "1.6.1"]
                 [ring/ring-defaults "0.3.2"]
                 [hiccup "1.0.5"]
                 [garden "1.3.6"]
                 [environ "1.1.0"]
                 [com.layerware/hugsql "0.4.9"]
                 [org.postgresql/postgresql "42.2.2"]]
  :plugins [[lein-ring "0.12.4"]
            [lein-garden "0.3.0"]
            [lein-cljfmt "0.6.1"]]
  :garden {:builds [{
                     :id "screen"
                     :source-paths ["src"]
                     :stylesheet myproject.views/screen
                     ;; Compiler flags passed to `garden.core/css`:
                     :compiler {
                                :output-to "resources/public/css/screen.css"
                                :pretty-print? false}}]}
  :ring {:handler myproject.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.2"]]}})

Mario C.01:11:53

Probably someone more experienced can help you. I have never set up a lein project from the ground up.

Mario C.01:11:59

(defproject hello-world "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [compojure "1.6.1"]
                 [ring/ring-defaults "0.3.2"]]
  :plugins [[lein-ring "0.12.4"]]
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [environ "1.0.0"]
                        [org.immutant/web "2.1.9"]
                        [ring/ring-mock "0.3.2"]]
         :env {:example "sample"}
         :plugins [[lein-environ "1.1.0"]]
         :ring {:handler hello-world.handler/app}
         :main hello-world.handler}})

Mario C.01:11:45

handler.clj

Mario C.01:11:51

(ns hello-world.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [environ.core :refer [env]]
            [immutant.web.undertow :as undertow]
            [immutant.web :as web]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (route/not-found "Not Found"))

(def app
  (wrap-defaults app-routes site-defaults))


(defn -main
  "Entry point for the server"
  [& args]
  (if (env :dev-mode)
    (web/run-dmc app {:host (or (env :host) "localhost")})
    (web/run app (undertow/options {:port 3000}))))

Mario C.01:11:02

then run with lein with-profile dev run

Mario C.01:11:30

To me the most difficult part is project set up tbh

adam02:11:28

Like this:

(defproject myproject "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [compojure "1.6.1"]
                 [ring/ring-defaults "0.3.2"]
                 [hiccup "1.0.5"]
                 [garden "1.3.6"]
                 [environ "1.1.0"]
                 [com.layerware/hugsql "0.4.9"]
                 [org.postgresql/postgresql "42.2.2"]]
  :plugins [[lein-ring "0.12.4"]
            [lein-garden "0.3.0"]
            [lein-cljfmt "0.6.1"]]
  :garden {:builds [{
                     :id "screen"
                     :source-paths ["src"]
                     :stylesheet myproject.views/screen
                     ;; Compiler flags passed to `garden.core/css`:
                     :compiler {
                                :output-to "resources/public/css/screen.css"
                                :pretty-print? false}}]}
  :ring {:handler myproject.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.2"]]}})

adam02:11:29

@mario.cordova.862 This semes to be the issue, I will report back after testing. In your example you have :plugins [[lein-environ "1.1.0"]]

adam02:11:43

@mario.cordova.862 worked, thanks so much!

mseddon11:11:22

is there a way to document deftype? I know there wasn't, but I wonder if that's been fixed yet. If not- is there an informal 'standard' on how to do it?

Xavier14:11:20

Hi all, I am trying to convert a first simple scraping project to Clojure and was wondering if anybody know what is the best option to run a headless browser w/ Javascript from Clojure? The projects I found are either unmaintained or haven't been updated from more than a year so I was wondering if there are other more active (using Selenium, Splashr, Pupetteer or something else)? Or do clojurist favor Java libraries via interop? Thanks a lot!

jumar21:11:51

I used etaoin some time ago and it's great.

Xavier19:11:19

Thanks a lot for the answers!

eMko15:11:47

@mseddon Looks there isn't. (deftype ^{:doc "abc"} my-type [my-field]) is OK. (clojure.repl/doc my-type) gives CompilerException java.lang.RuntimeException: Expecting var, but my-type is mapped to class clj_genetic_01.neural_net.my-type, compiling:(C:\Users\madera\AppData\Local\Temp\form-init7285806055912380243.clj:1:1) (meta my-type) gives => nil. If you look at https://clojure.org/reference/metadata, you can see that metadata are supported for symbols and collections. Deftype creates a plain-old-java-class.

mseddon15:11:40

Yep, that's what I feared.

bronsa15:11:55

you can add documentation to the constructor functions

👍 8
bronsa15:11:44

user=> (deftype T [])
user.T
user=> (alter-meta! #'->T assoc :doc "T doc")
{:arglists ([]), :doc "T doc", :line 1, :column 1, :file "NO_SOURCE_PATH", :name ->T, :ns #object[clojure.lang.Namespace 0x5a85c92 "user"]}
user=> (doc ->T)
-------------------------
user/->T
([])
  T doc
nil

mseddon15:11:10

ah, right, that could do it, good idea!

Whiskas17:11:31

Do you guys have some good hotkey cheat-sheet to share regarding parens navigation on repl/IDE ?

Whiskas17:11:42

like for example, i want to go to the end of the expression

Whiskas17:11:08

instead of doing alt + right arrow, how could i just jump to the last paren?

shaun-mahood17:11:26

@mateus.pimentel.w: What program are you using (Cursive, Emacs, Terminal, etc.)?

Whiskas17:11:53

I use VSCode, and i’m curious to know if the REPL has some built-in hotkeys

Whiskas17:11:05

( the clj repl )

shaun-mahood17:11:03

Pretty sure it would mostly be VSCode specific hotkeys - all the ones I use are either specific to my editor (Cursive) or the environment (Mac, Windows and Linux all have a bit different defaults)

shaun-mahood17:11:41

Though both Cursive and Emacs have lots of options for that kind of thing, I haven't looked at what VSCode offers for that

Whiskas17:11:01

But do you guys have this kind of stuff? Paren navigation hotkeys

shaun-mahood18:11:39

Yes - https://cursive-ide.com/userguide/paredit.html has some info on Cursive, and there are different options on Emacs that are similar

schmee18:11:49

@mateus.pimentel.w you might want to check out https://shaunlebron.github.io/parinfer/, it is available for VSCode!

Whiskas18:11:18

Aewsome, i found an extension for paredit

Whiskas18:11:32

I installed parinfer too, i liked it

rohitvvv22:11:11

Beginner question. (let [result []] (conj result 2) (if true result)) How do I retain the value of result I set in the let block?

enforser22:11:00

I think you're trying to treat result as a mutable object. It is not, it is binded to some value in the let binding, and it doesn't change values after that. Every time you reference result in the let, it is still bound to []. If you want to update result to be bound to the new value you need to create a new binding. i.e.

(let [result []]
       result (conj result 2)]
  (if true result))
I find that let bindings are useful when you are using the same value multiple times or if you want to move something complex into a binding for better readability