Fork me on GitHub
#beginners
<
2016-12-20
>
grounded_sage00:12:37

How to I add a newline to a println?

gdeer8100:12:09

@grounded_sage add the newline character (println "foo\n" "bar\n" "baz")

grounded_sage00:12:18

Cool. I thought it was that. I just used it in the passed and it didnt work. But appears to work now..

Lone Ranger02:12:10

super n00b compojure question. I'm getting <h1>Invalid anti-forgery token</h1> as a response when I try to test an endpoint with Postman. here's my whole app:

(ns demo-clj.core
  (:require [compojure.core :refer :all]
            [compojure.route :as route])
  (:gen-class))

(defroutes app
           (GET "/" [] "<h1>Hello World</h1>")
           (route/not-found "<h1>Page not found</h1>")
           (POST "/intPlus2" [n]
             {:n (+ 2 n)}))

Lone Ranger02:12:01

I'm hoping to get back something along the lines of {"n": 4}

mingp02:12:52

@goomba What middlewares are you using? In particular, are you using the CSRF prevention middleware? If so, then your POST requests, by default, need a CSRF token or they'll be rejected.

Lone Ranger02:12:07

no middleware (I think)

Lone Ranger02:12:07

that's the whole project you're looking at. Dependencies:

:dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/tools.cli "0.3.5"]
                 [compojure "1.5.1"]
                 ]
ran with lein ring server-headless

mingp02:12:30

What confuses me is that the error message you're getting sounds like typical anti-CSRF middleware (I think there's a few available for Ring based apps) but I don't see it being applied anywhere.

Lone Ranger02:12:43

confuses me too šŸ˜‚

mingp02:12:33

It's more or less as I would expect, except I can't see where it's being added to your Ring app.

Lone Ranger02:12:01

do you think it might have something to do with lein...?

mingp02:12:28

Might as well dump your entire project.clj into a pastebin and see.

Lone Ranger02:12:02

oh god I'm an idiot

Lone Ranger02:12:08

completely disregard

mingp02:12:18

For curiosity and/or future reference, what happened?

Lone Ranger02:12:20

was running the wrong project entirely

mingp02:12:35

I see. Well, glad you figured it out.

Lone Ranger02:12:38

was running a similarly named project

Lone Ranger02:12:07

clearly on the other side of balmer's peak

roelofw07:12:31

With selmer how can I use get-in like this :

{% (get-in paintings [0 :tiles]) %} 

roelofw07:12:55

I need to do first and then the :tiles tag to display a image

nur11:12:01

is there something like learn python clojurethehardway

poooogles11:12:16

Not so much, I found http://shop.oreilly.com/product/0636920034292.do to be pretty good having come from LPTHW

nur11:12:20

ah i think this one's more newbie friendly https://github.com/ClojureBridge/curriculum

nur11:12:18

I have the book living clojure by my side... still too fast for me šŸ˜°

yogidevbear13:12:01

On a similar vein to the question above, I bought myself Living Clojure for a Christmas present (5 more sleeps to go!). Can anyone recommend a good "beginners" intro course to spec (as this isn't included in the book)?

roelofw13:12:38

Can someone help me to find orphan tags here :

{% extends "base.html" %}

{% block content %}


<section class="body-content ">

    <div class="page-content">
        <div class="container">
            <div class="row">
                <div class="col-md-8">
                    <!--classic image post-->
                    <div class="blog-classic">
                        <div class="blog-post">
                            <div class="full-width">
                                {{ paintings.tiles )}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

{% endblock %}  

poooogles13:12:15

>{{ paintings.tiles )}

nur13:12:35

@curlyfry yup i borrow the book from the library... install brew leiningen and `| .gitignore | doc | | intro.md āžŠ | project.clj | README.md āž‹ | resources | src | | clojure_noob āžŒ | | | core.clj āž | test | | clojure_noob | | | core_test.clj` lost lol

roelofw13:12:50

@poooogles thanks, the ) must be a }

nur13:12:57

trying http://quil.info/ with clojurebridge

roelofw13:12:17

Which steps did you do exactly

roelofw13:12:32

the page seems to say exactly what you have to do

roelofw13:12:13

someone a example how to make a url with a dynamic url in it with selmer ?

nur13:12:46

i just feel like my setup is not there yet... last time it was codeblock C++ many years ago

nur14:12:16

Nurs-MacBook:clojure-noob nurazhar$ lein repl
nREPL server started on port 51966 on host 127.0.0.1 - 
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_112-b16
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

clojure-noob.core=> 
ok i think i get it terminal = IDE

roelofw14:12:20

yep, your terminal can be your ide

roelofw14:12:44

we use repl a lot for testing ideas or for debugging

dominicm14:12:09

@nur there are plugins for editors which send code from current buffer to the REPL for you

dominicm14:12:23

See: vim-fireplace, CIDER, inf-clojure, protorepl, & more

agile_geek14:12:32

@nur if you really want a full blown IDE there is the Cursive plugin for IntelliJ (there's a license fee for Cursive) or Counterclockwise for Eclipse (although I'm not sure how well that's supported atm). Based on recent survey's the most popular editors in use are Emacs (with CIDER) and IntelliJ (with Cursive) followed by Vim (with Fireplace) and Atom (with proto-repl)

roelofw14:12:01

I use Cursive for some time and l love it

abdullahibra15:12:40

(distinct (take 100 (repeatedly #(.getMillis (DateTime. ))))) (1482246807033)

abdullahibra15:12:18

is there a way to get precision better than milli seconds ?

abdullahibra15:12:55

seems last expression is executed in time less than milli second

abdullahibra15:12:02

rand is amazing

abdullahibra15:12:04

(count (distinct (take 1000000 (repeatedly #(rand 1000000))))) 1000000

poooogles15:12:07

getNanos() ?

abdullahibra15:12:20

i'm not sure it's there

abdullahibra15:12:26

maybe getPicos

joshkh15:12:38

any idea why lein doo is saying there's only one 1 test with 1 assertion?

(deftest class-root
  (testing "Should be able to parse a root path"
    (async done
      (go
        (let [model (<! (fetch/model flymine-beta))]
          (is (= :Gene (path/class model "Gene")))
          (done)))))
  (testing "Should be able to parse a normal path"
    (async done
      (go
        (let [model (<! (fetch/model flymine-beta))]
          (is (= :Organism (path/class model "Gene.organism.name")))
          (done))))))

joshkh15:12:01

(clojurescript!)

joshkh15:12:43

šŸ˜• is it because it's async?

Alex Miller (Clojure team)15:12:33

@abdullahibra you can use (System/nanoTime) for nano-level precision (but not necessarily nano-level resolution) in Java.

Alex Miller (Clojure team)15:12:17

there are a lot of caveats wrt the os that youā€™re on and what that actually does

roelofw16:12:29

no selmer expert here ?

roelofw17:12:48

How can I make this work :

<a href=  (str "/detail/"  {{ data.id }} )> 

roelofw17:12:44

What I try to do is to make a url where the part after the /detail/ is the id which is found by the data.id ?

tom17:12:23

@roelofw I believe you'll need to add a custom filter

roelofw17:12:07

oke, I will read that part of the selmer readme again

seancorfield17:12:21

Use <a href=ā€/detail/{{data.id}}ā€>

roelofw17:12:02

@seancorfield thanks, that worked

roelofw17:12:11

you saved me another time

roelofw17:12:10

@seancorfield how can I debug a css problem. When I open the site in FF with F12 I see a message that the stylesheet cannot be found.

roelofw17:12:16

I can see that it is applied

roelofw17:12:20

the html to load the css looks like this : <link href="/css/style.css">

seancorfield17:12:41

This sounds like the same problem you had before with JS not being loaded. So the solution is going to be to debug it and fix it same way you did with the JS file.

seancorfield17:12:11

(at this point, I think you should be making more effort to debug problems directly yourself, before folks just give you the answer)

roelofw18:12:33

@seancorfield I try but I hope when I do not find it, someone can give me a hint where to look

roelofw18:12:14

but you are right. at some way the css did not get found where I read the readme , it schould be find the css there

gdeer8118:12:20

@roelofw so you have an href to css. you expected the css to be found but it is not finding the css

gdeer8118:12:29

what is your hypothesis?

roelofw18:12:52

I do this in html : {% style "/css/style.css" %}

roelofw18:12:23

so I expect to find the file which is located at /resources/public/css/style.css

gdeer8118:12:53

so when you do that what actually happens?

roelofw18:12:49

it makes at tag like this : ' <link href="/css/style.css"> ` and I did not get found

roelofw18:12:22

also adding /resources/public/ before the css did not take care that the css is found

gdeer8118:12:54

okay, so your hypothesis is that the resource string might be wrong. so to test your hypothesis you change the string

gdeer8118:12:49

how many experiments have you run, what were the inputs, outputs, and what were your observations?

roelofw18:12:55

I run multiple and still the css is not found when I checked it with F12 in FF

roelofw18:12:34

I also tried this : (render "{% style \"/css/screen.css\" %}" {:servlet-context "/"})

roelofw18:12:59

but then I saw the render line instead of a css html tag line

roelofw18:12:44

and {:servlet-context "/resources/public"})

roelofw18:12:49

and the same output

roelofw18:12:32

and a lot of google to find out what I do wrong

iecya18:12:52

hello everyone, got a problem with namespaces and :require šŸ˜ž I have a cljc ns in which i require clojure.core and some other clojure libraries, other than some cljs namespace in my own project. I wrapped the cljs required ns in #?(:cljs ā€¦) but it keeps complaining about a single namespace that cannot be found, showing this error in the repl

java.lang.RuntimeException: No such namespace: schemas, compiling:(.../graph-editor/src_front/graph_editor_front/api.cljc:14:30)

iecya18:12:20

not sure about the other cljs ns, because it complains about this one, which is the first used in my code. can anyone help me to understand what i am doing wrong?

gdeer8118:12:23

@roelofw is this for your paintings project or a different one?

roelofw18:12:21

for my paintings project

roelofw18:12:32

that one is my first try to make a web app

roelofw18:12:41

the other is for 4clojure solutions

roelofw18:12:56

@gdeer81 I have made this class : <div class = "data">

roelofw18:12:23

and this css :

.data {
       border: 1px solid black ;
       border-radius: 10px;
    } 

roelofw18:12:31

and no border to see

gdeer8118:12:13

@roelofw I've pulled down the project and ran it and I'm not getting any errors, so commit and push any changes you have locally so I can see what you've done

roelofw18:12:39

oke, I will do

roelofw18:12:49

it's in progress at the moment

roelofw18:12:19

@gdeer81 everything is pushed now

gdeer8118:12:12

@roelofw you pushed an empty file

roelofw18:12:00

sorry, did the pushing again

roelofw18:12:16

I wanted to do it to fast and forgot to git add .

roelofw19:12:45

@gdeer81 now everything well ?

gdeer8119:12:15

@roelofw I'm not getting any errors

roelofw19:12:13

so you see a border around the naam schilder part ?

gdeer8119:12:33

yep, when I put chrome in emulator mode and make the screen less the 475 width

roelofw19:12:42

when you click on a painting like this url : http://localhost:3000/detail/SK-C-1368

gdeer8119:12:07

that css file is so giant its no wonder you're having problems

gdeer8119:12:01

you assumed that just putting the css class at the bottom of the file would be safe

roelofw19:12:26

I borrowed this layout from a place on the net

roelofw19:12:47

maybe I have to find another one with smaller css files

gdeer8119:12:22

or you could make a separate css file for your custom things

gdeer8119:12:58

but first you need to debug the current one. Why does the data class only work on screens with a max width of 479px?

roelofw19:12:28

aha, I see it @media screen and (max-width: 479px)

roelofw19:12:03

and that is the problem. When I put the data as first everything works fine

gdeer8119:12:45

another bug solved using the scientific method bowtie šŸ”¬

gdeer8119:12:58

I ran the project and went to a detail page, I inspected the page and expected there to be a .data style on the elements with class="data", there actually wasn't. So I asked where is the bug? is it the app, the wrappers, the language, the library, the jvm, the operating system, the hardware, or physics itself? the css file is there and the app found it so it isn't OS, the css is working for every other element so it isn't the language or libraries, the wrappers are turning the resource statements into proper hrefs, so it must be in our css

gdeer8119:12:45

opens css 7k line css file

sveri19:12:43

@roelofw btw. "borrowed" can mean you are actually breaking they copyright. So you should make sure that "borrowing" somebody else css is allowed šŸ˜‰

gdeer8119:12:32

not to mention using a $59 css file for an open source toy web app is a bit of overkill

roelofw19:12:32

yep, I know. IM not a front - end person. Im bad in making layouts in css / html

roelofw19:12:42

Im more a back-end person

roelofw19:12:03

so I look for open source layouts that I can use

gdeer8119:12:22

@roelofw then just use bootstrap

roelofw19:12:09

I worked with bootstrap but did not find it easy to work with

roelofw19:12:28

and still you have to make your own layout

sveri19:12:28

In the end its up to you. Its just that people can get pretty * when they see their layouts used somewhere else.

roelofw19:12:17

that why I only use open source lay outs which you may borrow and change

roelofw19:12:06

but I will look for a better one . im not complete happy with the detail page

roelofw19:12:10

I think I will destroy this project. I cannot make it work that the first page schows multiple images with masonary and a beutifull detail page where I can show one image and some more info about the image

gdeer8119:12:06

@roelofw no, this is a good project, you might just need to take a step back

gdeer8119:12:33

take some hammock time or work on other projects, but as you practice and learn you can always revisit it with new eyes

roelofw19:12:58

o, this was a good project to learn more about clojure

roelofw19:12:16

but not a good project to make and practice with a nice layout

gdeer8119:12:35

I don't see why not, rip out all the custom styling and start with something basic and build up

gdeer8119:12:28

frontend work is not my cup of tea either so I totally feel your pain, but having a simple grid layout with a nice details page for each item is a nice concrete achievable goal for the project.

gdeer8119:12:25

then when you want to explore using Om, Reagent, or Re-frame you can make a branch off master and refactor it to be a SPA

roelofw20:12:37

oke, but first I have to have a idea for a nice layout for the detail page

roelofw20:12:47

oke, I want you to see what I mean but the css files are not send to heroku šŸ˜ž

gdeer8120:12:19

that always depends on the purpose of the details page. for ecommerce you want price, description, specs, swatches, and "buy now" button to be prominent, but for a gallery app you might just want artist details and description to be prominent

roelofw20:12:18

I have now this and I think the line around the details is too promiment

roelofw20:12:29

and the text is not aligned with the name

sveri20:12:36

@roelofw At a first glance I like it, maybe a padding would be nice. But really, its a nice and clean page with the picture in the middle taking the focus where it should be.

gdeer8120:12:51

Yeah the picture location is good, you can fill up the white space around it with details about the painting in a larger point font

roelofw20:12:05

I changed the details a little

sveri20:12:55

@roelofw I am not sure if the border around the text is needed at all, or maybe make it more transparent. That said, this discussion belongs to #off-topic I guess.

roelofw20:12:04

both thanks

roelofw20:12:15

next idea's for this project.

roelofw20:12:38

1) making pagination because there are more paintings then 10

roelofw20:12:18

2) maybe a idea to make it work that the text will be in Englisch or Dutch and the user can choose

roelofw20:12:52

@gdeer81 @sveri thanks , I think I will finisch this project

sveri20:12:17

@roelofw yw..have fun šŸ™‚

roelofw20:12:00

so I get a lot of experience in clojure and web development with clojure

mlev22:12:19

@gdeer81 , the repository for my Luminus guestbook Reagent app in progress is at https://github.com/levinem/guestbook

gdeer8122:12:58

@mlev cool, I'll take a looksey

mlev22:12:33

Thanks šŸ™‚