Fork me on GitHub
#beginners
<
2016-02-05
>
kamuela00:02:41

Ok thanks @jeff.engebretsen

krchia10:02:12

hi, my compojure defroutes return a HTML string generated by enlive

krchia10:02:36

how do i return the session info i.e. for a login?

snowell12:02:35

@krchia You can get the session in each route like so: (GET “/myRoute" [:as {session :session}] (do-a-thing session))

krchia12:02:10

@snowell i don’t get the :session in my request map even though i have wrap-session in my middleware already

snowell12:02:49

Hmm. In the app I’m looking at I’m using wrap-defaults

snowell12:02:08

Specifically (wrap-defaults (assoc api-defaults :session {:flash true :cookie-attrs {:http-only true}}))

snowell12:02:29

Where api-defaults comes from ring.middleware.defaults

snowell12:02:02

Looks like I had been using wrap-session, but ditched it in favor of wrap-defaults

krchia12:02:37

yeah, i just tried that

krchia12:02:45

no other middleware. :session is still not showing up :’(

snowell12:02:20

So if you have a route like mine above, session in your function is assigned nil?

snowell12:02:19

Also, make sure that each of your responses has not just :body, but also :session

krchia12:02:18

uhm, there’s no :session key in the request map

snowell12:02:03

Well some response needs to set the original session

snowell12:02:43

So if you haven’t returned an original session in a response, there would be no stored session

krchia12:02:23

actually, about that, how do i return a request map with session info with enlive?

snowell12:02:12

Grab the request map and use merge?

snowell12:02:25

I don’t know anything about enlive really

krchia12:02:51

@snowell thanks for helping me with my original problem anyways simple_smile

snowell12:02:58

Haha I hope I did

krchia13:02:03

is there a reason why (response “some-string) causes my browser to download the html file instead?

krchia13:02:28

it doens’t download, but it does in my project

krchia13:02:57

tried copying the same middleware functions into my project, but it still downloads for me

pez14:02:55

How do I get the contents of a sequence? If I have (1 2 3 4), how do I get 1 2 3 4?

akiva14:02:36

You want to process them one at a time or do you want a string representation of the entire contents of the sequence?

pez14:02:36

I need it in a vector. Something like so [:foo 1 2 3 4].

pez14:02:10

Actually it is all part of a postwalk. Where something like [:foo “abc” 1 2 3 4] should become [:foo.abc 1 2 3 4]. I’m trying with

[(keyword (subs (str (first %) "." (second %)) 1)) (nthrest % 2)]
But that gives me [:foo.abc (1 2 3 4)].

pez14:02:01

(If someone has a better idea about how to do it, I’m all ears.) 😄

snowell14:02:47

@krchia You may want to try setting the :Content-Type header on your response

snowell14:02:29

@pez Say that make-keyword is what gives you :foo.abc

snowell14:02:44

(into (make-keyword) ‘(1 2 3 4))

krchia14:02:09

@snowell both of them have content-type: nil

krchia14:02:13

both projects i mean

snowell14:02:10

Well, that works in my REPL, clojurebot

snowell14:02:09

@krchia Well if you explicitly set content-type: text/plain, your browser won’t try to download it as HTML

krchia14:02:25

but, why does it download for one and not the other if both have content-type: nil!!

snowell14:02:57

Ah. Because he’s using (wrap-json-response)

snowell14:02:05

Which probably sets content-type to application/json

agile_geek14:02:19

@snowell: smart quotes mess up strings in clojurebot.

krchia14:02:29

yes, but i used wrap-json-response in both projects

snowell14:02:35

Ugh. Well then thanks, IntelliJ

krchia14:02:40

i also copied all the middleware, so i can’t figure out what’s the difference

snowell14:02:51

I think @pez is gone anyway 😞

krchia14:02:51

this thread looks the most promising, but it’s kinda dated

krchia14:02:08

maybe i should post my own thread on google groups for help

snowell14:02:32

Somebody on #C03S1L9DN would probably be more helpful than I

krchia14:02:44

hm? but isn’t this all server side

snowell14:02:13

Try #C0A5GSC6T then? simple_smile

snowell14:02:43

Clojurescript wouldn’t be a bad place. When you’re working with cljs you have to care about server stuff too

snowell14:02:51

At least I’ve had to

krchia14:02:06

ah, i’ll try both channels later on simple_smile thanks

krchia14:02:15

but i can’t help but feel my question is so basic it belongs here

krchia14:02:32

it just stumps me, i’ve tried all combinations of keywords i think might be relevant

krchia14:02:51

and every link in the first 3 pages for each combinations have been clicked on before

agile_geek14:02:39

@krchia: I suggest you try out the requests in the REPL using ring.mock.request to see what the differences are when you send a request to each project. However, it will be the content-type being set to "application/octet-stream" or similar so setting "Content-Type" explicitly will fix it.

krchia14:02:23

@:agile_geek okay. i’ll try it later, thanks

krchia14:02:36

i think i’ve outstayed my welcome in the cafe

krchia14:02:00

i thought i was trying out the requests with ring.util.response

agile_geek14:02:40

You are returning ring.util.response - but if you want to call your ring handler you need to pass it a request

agile_geek14:02:29

you can use ring.mock.request/request to create a mock request you can send to your ring handler

agile_geek14:02:39

which will return a response

agile_geek14:02:37

So for example if I have this:

(ns new-compojure.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.util.response :refer [response content-type]]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))

(defroutes app-routes
  (GET "/" [] (-> (response "Hello Chris") ;;(content-type "text/plain")
                  ))
  (GET "/hello" [] (-> "Hello"))
  (route/not-found "Not Found"))

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

agile_geek14:02:04

I could open a REPL in the project and switch ns to my ns and then eval this:

(app (mock/request :get "/"))

agile_geek14:02:43

where I've run (require '[ring.mock.request :as mock]) in the REPL first

agile_geek14:02:47

which would result in this

{:status 200,
 :headers
 {"X-Content-Type-Options" "nosniff",
  "X-Frame-Options" "SAMEORIGIN",
  "X-XSS-Protection" "1; mode=block",
  "Content-Type" "application/octet-stream",
  "Set-Cookie" ("ring-session=c9329a7e-c583-42cd-8574-18b94b3c330f;Path=/;HttpOnly")},
 :body "Hello Chris"}

pez15:02:35

@snowell: thanks! into worked like a charm for me.

pez15:02:27

Can I remove forms during a postwalk? I have only succeeded with replacing them with nil...

snowell15:02:36

Well you could always (remove nil? postwalked-form)

snowell15:02:52

Seems less…functional that way though

pez15:02:01

I might resort to less functional =)

chadhs15:02:49

has anyone had this error when trying to launch a repl (emacs+CIDER)? error in process sentinel: Could not start nREPL server:

chadhs15:02:01

😞 just started out the of the blue

snowell15:02:45

You could always try asking in #C0617A8PQ

snowell15:02:57

(If nobody here knows. I know I don’t)

chadhs15:02:22

i nuked all the downloaded emacs packages under ~/.emacs.d/elpa/ and relaunched emacs and let it set itself up again.

chadhs15:02:26

must have been a fluke

snowell15:02:32

¯\(ツ)

chadhs15:02:56

oh… it’s project specific

chadhs15:02:00

dun dun dun

chadhs15:02:04

yeah i’ll ask in cider

chadhs16:02:05

it was a bug i my code… i had a (System/exit 0) call

chadhs16:02:22

that was eval’d when the repl was launched -.-

chadhs20:02:17

when playing around with clojure.tools.logging the example is pretty straightforward and i got some basics working, having an issue when running it in the midst of mapping an anon function

chadhs20:02:59

my goal in english is: map this function across all items in this vector… oh but also print out what you’re doing with log/info

jeff.engebretsen20:02:55

What does the anon fn look like?

jeff.engebretsen20:02:33

If it's a normal fn you can do (fn [...] (log/info ...) (normal-stuff)) In an anon you may have to wrap it in a do #(do (log/info ...) (normal-stuff)) I'm just stabbing blindly though.

chadhs20:02:11

got it jeff thanks, if i can’t wrap in a do i’ll convert that function to fn rather than # notation

chadhs20:02:52

in the mean time i was playing with warning levels:

(log/info "ninjas could be in your area.")
(log/debug "a ninja is walking around the park in your neighborhood.")
(log/warn "ninja behind you!”)
(log/error "ninja attacking you!”)

chadhs20:02:29

yeah… easily amused am i

chadhs20:02:47

@jeff.engebretsen: converting it to (fn [arg] … form worked

chadhs21:02:56

hmm, looks like the log/info function doesn’t output when nested in a map call… it worked when i was using println with that function

seancorfield21:02:30

Perhaps laziness is biting you?

seancorfield21:02:58

(i.e., if you don’t consume the result of the map call then it won’t call the function argument)

chadhs21:02:32

i think so, talking about it in #C03S1KBA2 atm thnx sean!

lastnerdftw21:02:20

I have a question! I am trying to connect my project with Microsoft SQL Server 2012 and I cannot figure out for the life of me how to do it. The two things I've found on Stack and on the MS SQL website itself aren't very forthcoming

nkraft21:02:03

@lastnerdftw what driver/ORM are you using?

lastnerdftw21:02:30

sqljdbc_4.2 for the jar and the actual driver issssss sec

lastnerdftw21:02:45

com.microsoft.sqlserver.jdbc.SQLServerDriver

nkraft21:02:11

Clojure can set up the connections a variety of ways. JDBC has one way, an ORM like SQLKorma has another: http://www.sqlkorma.com/docs#db

lastnerdftw21:02:19

I would like to use the JDBC as that is what Im familiar with so this is what I have come with so far:

lastnerdftw21:02:09

:dependencies [[org.clojure/java.jdbc "0.3.4"] [sqljdbc4/sqljdbc4 "4.0"]]

lastnerdftw21:02:16

however the jdbc is outdated

lastnerdftw21:02:24

i just copy and pasted that from the tutorial

lastnerdftw21:02:02

[org.clojure/java.jdbc "0.4.2"] [[sqljdbc4/sqljdbc4 "4.0"]]] is what I have atm

lockdown21:02:36

when you do in-ns in a repl to switch to an existing ns, the ns macro of that ns is not parsed right? you have to use ns functions to in the repl to replicate the ns macro?

lastnerdftw21:02:00

I have no idea what you just said LOL. I'm using the Intellji IDE so I dont have any macros set up\

jeff.engebretsen21:02:25

I think it was a different question.

nkraft21:02:44

@lastnerdftw: Not sure what problem you're having. Is lean deps not working? Can't make a connection in code? I think I thought you were farther along than you are.

akiva21:02:25

@lockdown, yep. It loads the requires but it doesn’t attach them to the REPL until you tell it so.

lastnerdftw21:02:25

@nkraft: So when I add my deps I'm getting Error Synchronising mysql:0.1.0-SNAPSHOT: Could not find artifact sqljdbc4:sqljdbc4:jar:4.0 in central (https://repo1.maven.org/maven2/)

lastnerdftw21:02:39

@nkraft and what I mean by that when I click refresh on my lein deps it throws this error

chadhs21:02:46

so here’s a goofy question… if you have a function that “does an operation” and you call it wrapped in (println) it will still do it’s thing but you’ll see the output as well

chadhs21:02:29

spoiler alert: i want to see the output of clojure.java.shell/sh call on the command line when i run my jar

jeff.engebretsen21:02:58

It'll print whatever the fn returns

jeff.engebretsen21:02:06

I dunno what sh returns though.

chadhs21:02:17

it returns a map

chadhs21:02:21

exit status

chadhs21:02:28

and std err i believe

jeff.engebretsen21:02:01

So yes. It'll evaluate the sh call and pass the map to println

chadhs21:02:04

example from clojure docs:

(sh "pwd" :dir "/home/ics/icsdev")
{:exit 0, :out "/home/ics/icsdev\n", :err “"}

chadhs21:02:09

cool thnx!

nkraft21:02:44

@lastnerdftw: Ah! You need to get the jar into your Maven .m2 repository. This line will get that done: mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

nkraft21:02:03

Just complete the variables with the usual stuff from a Java pom.xml

seancorfield22:02:02

Or use the jTDS driver instead of the Microsoft driver.

seancorfield22:02:55

Use [net.sourceforge.jtds/jtds "1.3.1"] instead.

seancorfield22:02:09

For the sqljdbc4 driver, you have to go download it from the Microsoft website and then install it into your local Maven repo cache somehow (either via mvn as @nkraft showed or via the lein-localrepo plugin for Leiningen).

seancorfield22:02:00

I have it installed in a local repo because I have to test java.jdbc against SQL Server while I’m working on it. But everything else I test it with is just a regular dependency on Maven Central.

lastnerdftw22:02:31

I've got the sqljdbc4 downloaded already..I have everything set on the java side....now for the command that you both suggested I can do this for terminal inside of my intellij Im assuming?

lastnerdftw22:02:48

and thanks @nkraft & @seancorfield

seancorfield22:02:51

No idea about IntelliJ, sorry.

seancorfield22:02:10

Do you have the mvn command installed?

lastnerdftw22:02:37

Dont believe that I do lol

lockdown22:02:46

akiva: thanks

seancorfield22:02:48

If not, take a look at https://github.com/kumarshantanu/lein-localrepo as an easy way to get random JAR files into your local repo

seancorfield22:02:04

(hmm, I need to build a version of that for Boot)

lastnerdftw22:02:49

I have everything set up on Spring Boot for MS SQL 2012

lastnerdftw22:02:42

I can dm with you the exact specs if you didnt want to go through the hassel

seancorfield22:02:55

Not sure who you’re addressing?

seancorfield22:02:29

Oh, you’re confusing Boot the Clojure build tool with Spring Boot… I see now…

seancorfield22:02:41

(turns out Boot can already do what lein-localrepo does out of the box — I should have known!)

seancorfield22:02:59

This is the Boot I’m talking about http://boot-clj.com

seancorfield22:02:09

I left Java-land long before Spring Boot appeared 😸