This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-05
Channels
- # aatree (2)
- # admin-announcements (15)
- # announcements (2)
- # aws (8)
- # beginners (160)
- # boot (290)
- # braid-chat (28)
- # cider (8)
- # clara (1)
- # cljsrn (3)
- # clojure (154)
- # clojure-czech (7)
- # clojure-russia (162)
- # clojurebridge (2)
- # clojurescript (128)
- # cursive (29)
- # datomic (30)
- # emacs (7)
- # events (1)
- # hoplon (5)
- # jobs (1)
- # ldnclj (7)
- # leiningen (3)
- # off-topic (11)
- # om (82)
- # onyx (68)
- # overtone (1)
- # parinfer (57)
- # portland-or (1)
- # proton (18)
- # re-frame (8)
- # reagent (32)
- # ring-swagger (3)
- # yada (5)
Ok thanks @jeff.engebretsen
@krchia You can get the session in each route like so:
(GET “/myRoute" [:as {session :session}] (do-a-thing session))
@snowell i don’t get the :session in my request map even though i have wrap-session in my middleware already
Specifically (wrap-defaults (assoc api-defaults :session {:flash true :cookie-attrs {:http-only true}}))
So if you haven’t returned an original session in a response, there would be no stored session
is there a reason why (response “some-string) causes my browser to download the html file instead?
when i tried just returning a string or response in this project https://github.com/ochronus/ring-compojure-session-example/blob/master/src/compojure_sessions/handler.clj#L22
tried copying the same middleware functions into my project, but it still downloads for me
You want to process them one at a time or do you want a string representation of the entire contents of the sequence?
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)]
.@krchia Well if you explicitly set content-type: text/plain, your browser won’t try to download it as HTML
@snowell: smart quotes mess up strings in clojurebot.
Clojurescript wouldn’t be a bad place. When you’re working with cljs you have to care about server stuff too
@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.
You are returning ring.util.response - but if you want to call your ring handler you need to pass it a request
you can use ring.mock.request/request
to create a mock request you can send to your ring handler
which will return a response
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))
I could open a REPL in the project and switch ns to my ns and then eval this:
(app (mock/request :get "/"))
where I've run (require '[ring.mock.request :as mock])
in the REPL first
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"}
in the REPL
Can I remove forms during a postwalk
? I have only succeeded with replacing them with nil
...
has anyone had this error when trying to launch a repl (emacs+CIDER)? error in process sentinel: Could not start nREPL server:
i nuked all the downloaded emacs packages under ~/.emacs.d/elpa/
and relaunched emacs and let it set itself up again.
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
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
What does the anon fn look like?
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.
got it jeff thanks, if i can’t wrap in a do i’ll convert that function to fn rather than # notation
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!”)
@jeff.engebretsen: converting it to (fn [arg] … form worked
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
Perhaps laziness is biting you?
(i.e., if you don’t consume the result of the map
call then it won’t call the function argument)
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
@lastnerdftw what driver/ORM are you using?
sqljdbc_4.2 for the jar and the actual driver issssss sec
com.microsoft.sqlserver.jdbc.SQLServerDriver
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
I would like to use the JDBC as that is what Im familiar with so this is what I have come with so far:
:dependencies [[org.clojure/java.jdbc "0.3.4"] [sqljdbc4/sqljdbc4 "4.0"]]
however the jdbc is outdated
i just copy and pasted that from the tutorial
[org.clojure/java.jdbc "0.4.2"] [[sqljdbc4/sqljdbc4 "4.0"]]] is what I have atm
for deps
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?
I have no idea what you just said LOL. I'm using the Intellji IDE so I dont have any macros set up\
I think it was a different question.
gotcha LOL
@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.
@lockdown, yep. It loads the requires but it doesn’t attach them to the REPL until you tell it so.
@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/)
@nkraft and what I mean by that when I click refresh on my lein deps it throws this error
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
spoiler alert: i want to see the output of clojure.java.shell/sh
call on the command line when i run my jar
It'll print whatever the fn returns
I dunno what sh returns though.
So yes. It'll evaluate the sh call and pass the map to println
example from clojure docs:
(sh "pwd" :dir "/home/ics/icsdev")
{:exit 0, :out "/home/ics/icsdev\n", :err “"}
@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>
Or use the jTDS driver instead of the Microsoft driver.
Use [net.sourceforge.jtds/jtds "1.3.1"]
instead.
as a dep?
welp LOL
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).
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.
Here’s an example db-spec
for the jTDS driver https://github.com/clojure/java.jdbc/blob/master/src/test/clojure/clojure/java/test_jdbc.clj#L88-L91
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?
and thanks @nkraft & @seancorfield
No idea about IntelliJ, sorry.
Do you have the mvn
command installed?
Dont believe that I do lol
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
(hmm, I need to build a version of that for Boot)
I have everything set up on Spring Boot for MS SQL 2012
I can dm with you the exact specs if you didnt want to go through the hassel
Not sure who you’re addressing?
Oh, you’re confusing Boot the Clojure build tool with Spring Boot… I see now…
(turns out Boot can already do what lein-localrepo
does out of the box — I should have known!)
This is the Boot I’m talking about http://boot-clj.com
ahhhh gotcha
I left Java-land long before Spring Boot appeared 😸