Fork me on GitHub
#clojure
<
2016-06-30
>
vandr0iy00:06:29

Hi, clojurists! Has anyone ever used immutant? Trying to import it spits mad stacktraces in Messages emacs buffer, starting with:

Caused by: java.io.FileNotFoundException: Could not locate immmutant/web/middleware__init.class or immmutant/web/middleware.clj on classpath., compiling:(reversi/server.clj:1:1)

tcrawley00:06:39

@vandr0iy: weird. What version do you have listed in :dependencies?

josh_tackett00:06:36

Does anyone know what the command in selenium is to press the enter key when on a browser?

josh_tackett00:06:23

nvm found it: (submit "input#password")

vandr0iy00:06:55

@tcrawley: [org.immutant/immutant "2.1.5"]

max02:06:28

I’m trying to do a GET request against a site that uses SNI. Is it correct that neither clj-http nor http-kit will work for me?

max02:06:48

weird thing is that I seem to be able to talk to other SNI sites with both libraries, but not this one

tcrawley02:06:09

@vandr0iy: what other dependencies do you have? What other errors are emitted? What namespace are you trying to require?

vandr0iy02:06:29

and I was trying to require: [immutant.web :as web] [immutant.web.async :as async] [immutant.web.middleware :as web-middleware]

vandr0iy02:06:55

among the other things (default in chestnut, btw)

tcrawley02:06:35

@vandr0iy: hmm, that looks fine. Would you be willing to provide a sample project that recreates the issue?

vandr0iy02:06:41

yes, in a moment... anyways, as long as I do not require immutant.web.middleware everything works smoothly

gordon05:06:27

@vandr0iy: immmutant/web/middleware.clj has 3 ms - could it be a typo?

vandr0iy05:06:08

Oh... totally overlooked that! thank you

unni08:06:48

Does wrap-reload work on http-kit and bidi ? Can’t seem to get it working.

niquola09:06:10

Hi, how to construct java 8 lambda function in clojure (for interop)?

Rachel Westmacott09:06:04

I think the lambda functions are just syntactic sugar for specific concrete classes

niquola09:06:33

tnx, i've found

(reify Function (apply [this arg]  ....))

Rachel Westmacott09:06:02

(of course the lambda stuff should work with any class/interface that has a single method, not just the ones in that package)

urbanslug11:06:50

hey, when using compojure, how can I define a rule that will apply to all routes in a context? Because a let block doesn’t work.

urbanslug11:06:31

In this case I want something like

(let [foo (lowercase pre-foo)]
(<route>)
(<route>)
)

tap11:06:44

Maybe it’s achievable through middleware?

hlolli13:06:53

I was attempting to use Compojure instead of bidi a bit. But Im not getting my transit params, could be chance someone here see quickly why lein-transit middleware is not making :transit-params in the incoming request?

(defroutes app-routes
  (GET "/"
       []
       {:body {:hello "world"}})
  (POST "/"
        {:keys [headers params body transit-params] :as request}
        {:status 200 :headers {"Content-Type" "application/transit+json"}
         :body (write transit-params)}))

(defonce server
  (jetty/run-jetty
   (-> #'app-routes
       wrap-transit-response
       wrap-transit-params
       (wrap-cors :access-control-allow-origin [#""]
                  :access-control-allow-methods [:get :put :post :delete]))
   {:port 8080 :join? false}))

sashton13:06:11

I just realized that defining regex inline in a function using the #”” reader macro somehow caches the regex so it’s only created once. When I first thought about it, I mistakenly assumed a new regex would be created every time the function was called. Is there some compiler magic which puts the regex Patterns in a static variable somewhere? I was looking through the LispReader source, but nothing jumped out at me. Example, where each unique object gets a different hashCode:

(defn foo []
  (.hashCode #"123”))  ;; this seems to create a Pattern object which is shared across invocations. How?
=> #'user/foo
(do
  (println (foo))
  (println (foo)))
664791687    ;; I previously assumed these two would be unique objects, but they are actually the same!
664791687
=> nil
(do 
  (println (.hashCode #"123"))
  (println (.hashCode #"123")))
438713871     ;; different objects, as expected
1176080321
=> nil

Alex Miller (Clojure team)13:06:20

The reader reads the pattern and the compiler stashes it as a constant in the compiled class

sashton13:06:03

thanks @alexmiller , is that done through registerConstant()?

sashton13:06:20

well, on second thought, maybe registerConstant is for numbers and such, maybe the regex gets put in VARS?

octahedrion13:06:58

is there any disadvantage to generating large numbers of keywords at runtime ?

manutter5113:06:29

I’ve heard they use up permgen space in the JVM

ddellacosta14:06:47

anyone here using vinyasa? I'm having trouble getting it to bend to my will…in particular, the "pull" command doesn't seem to be doing what I'm expecting

ddellacosta14:06:09

in a fresh project, in a cider repl:

43│  user> (./pull '[org.clojure/data.csv "0.1.3"])
 44│  nil
 45│  user> (require '[clojure.data.csv :as csv])
 46│  FileNotFoundException Could not locate clojure/data/csv__init.class or clojure/data/csv.clj on classpath.  clojure.lang.RT.load (RT.java:456)
 47│  user>

ddellacosta14:06:14

am I doing something obviously wrong? The .lein/profiles.clj set up is more or less vanilla taken from the vinyasa README: https://github.com/zcaudate/vinyasa#installation

zcaudate14:06:23

@ddellacosta: what version are you using?

zcaudate14:06:35

I need to fix the readme… right now it’s 0.4.4

zcaudate14:06:40

and it should be 0.4.7

ddellacosta14:06:38

ah okay, let me try that

ddellacosta14:06:50

@zcaudate: other than that, should it work as described in the README?

zcaudate14:06:41

@ddellacosta: yeah give it a go

ddellacosta14:06:05

@zcaudate: cool, that seems to be what I needed. Thanks!

zcaudate14:06:56

@ddellacosta: thanks for picking that up. readme fixed.

ddellacosta15:06:10

sure thing. Glad I could help by being the guinea pig 😄

ddellacosta15:06:18

seriously though, excited to integrate this into my repl flow

zcaudate15:06:20

let me know if you find anything usual

ddellacosta15:06:23

lots of useful stuff.

ddellacosta15:06:25

gotcha, will do!

zcaudate15:06:48

my personal favorites are the reflection macros https://github.com/zcaudate/vinyasa#reflection

zcaudate15:06:44

ultra has them too (both use hara.reflect) but you type less using the . syntax

Alex Miller (Clojure team)15:06:16

@sashton: I’d have to dig through code to tell you the mechanics, don’t know offhand

ddellacosta15:06:19

that could be very useful…not infrequently do I find myself poking at stuff by running it through some variation on (-> thing clojure.reflect/reflect …do stuff…)

ddellacosta15:06:30

thanks zcaudate, will check those out further

zcaudate15:06:59

@ddellacosta: i think you’ll like it 😃

Alex Miller (Clojure team)15:06:32

@octo221: @manutter51 keywords will be on the heap (not permgen). the downside of generating many is that they use memory, but they will get gc’ed if no longer in use. permgen doesn’t exist anymore in Java 1.8+ either.

manutter5115:06:16

Did they used to use permgen? I seem to remember something about that from a while ago. Then again I might just be imagining things again

octahedrion15:06:55

@alexmiller: presumably they use about the same memory as strings ?

Alex Miller (Clojure team)15:06:41

@manutter51: in the past (not for the last couple releases) they interned strings

Alex Miller (Clojure team)15:06:29

@octo221: a Keyword has a Symbol, which has either one (for unqualified) or two (for qualified) strings + a pre-cached hashcode, so heavier than a string

fabrao16:06:21

Hello all, why when I run in lein run the program is ok but when I run in java -jar from uberjar is getting "org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for http://schemas.xmlsoap.org/wsdl/soap12/" error? Is there something I missing? I´m using apache cfx serivce to access soap stuff

Alex Miller (Clojure team)16:06:16

there might be something set up in one of the jar manifests that’s not getting transferred into the uberjar manifest properly

fabrao16:06:27

I´ve checked and I saw missing 2 files, maybe is this the problem?

fabrao16:06:45

is there any way to include this files?

fabrao16:06:10

or include one jar file into compiling even this is not used?

Alex Miller (Clojure team)16:06:24

usually stuff like that is in resources

Alex Miller (Clojure team)16:06:41

lein probably has some way to do what you want, but I don’t know it off the top of my head

fabrao16:06:07

ok, thanks I´ll try to find it, best regards

Alex Miller (Clojure team)16:06:40

lein sample will show you a sample project.clj with all the options and that may lead you in useful directions

manutter5116:06:00

@alexmiller: Ok, that makes sense, thanks for the clarification.

blance18:06:55

I just read about clojure.spec and it seems like a great tool for testing with test.check. To utilize it for unit testing, should I specify a spec for every functions using fdef in my application so that I just call clojure.spec.test/test to do unit testing?

blance18:06:31

I've never used schema before so I'm not sure which function I should specify those and which not to

timgilbert18:06:55

I'm assuming it's maybe a syntax error in a namespace that isn't loaded in test or run but I can't seem to find one in the code

timgilbert18:06:21

Anyone have any hints on what I should look for? My own namespaces aren't anywhere in the tracebacks above

akiva18:06:12

Sometimes I have to do a lein clean before I can get a REPL spun up. It coughs up some stacktrace although I’m pretty sure it’s not that. Just a thought, though.

timgilbert18:06:37

Thanks @akiva, I did try that but it didn't make a difference

timgilbert18:06:16

The other weird thing is that the app is a web server which fires up an nrepl, and I can connect to the nrepl without any problems. It's just lein repl that won't work

henriklundahl18:06:11

@timgilbert: Have you checked the contents of /private/var/folders/c1/fczp131x18z0s29w7bhwkqgc0000gn/T/form-init2259462831070490027.clj? Perhaps that can give you some clues.

lvh18:06:05

I’m getting an exception:

actual: java.lang.IllegalArgumentException: No matching method found: crypto_secretbox_easy for class caesium.binding.Sodium$jnr$ffi$0
 at clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
    clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:28)
… which goes away when I annotate with the respective types. Is that necessarily a bug, or just maybe?

lvh18:06:35

The annotation is ^ByteBuffer, but the problem appears to only occur with java.nio.DirectByteBuffers, not with java.nio.ByteBuffer or java.nio.MappedByteBuffer

lvh18:06:46

I’m adding some debug statements to figure that out now

timgilbert19:06:03

Hmm, thanks @henriklundahl, it somehow didn't occur to me that the file would actually exist on my filesystem

uwo20:06:46

I’m trying to dry up some queries that all use the same query shape with different attributes.

(defn simple-search-query [attrs]
  [:find '?e
   :in '$ '?term
   :where
   (apply list 'or-join '[?e ?term]
          (map (fn [attr]
                 (let [sym (gensym)]
                   (list 'and ['?e attr sym]
                         [(list 'some.fn/match? '?term sym)])))
               attrs))])

(simple-search-query [:some/name :some/code])
This returns the correct data structure, but I need to quote the result of the simple-search-query fn. My macro/quoting fu is weak. Any suggestions?

fadrian21:06:14

I'm trying to use clojure and the clojure.java.jdbc library to talk to an Oracle database server. Both clojure and the database server are Windows machines. Anyone have any idea where/how would I install/reference the oracle ODBC driver JAR to allow this to work?

wei22:06:24

what’s a good way to format a date as a human-friendly interval, e.g. “5 hours from now”?

wei22:06:52

wondering if anyone’s written a convenient function for that

danlebrero22:06:18

@fadrian: assuming you are using maven or lein, you will need to download the Oracle jar from the Oracle site and install it in your local maven repo

danlebrero22:06:03

@wei never tried it, but http://www.ocpsoft.org/prettytime/ seems like what you are looking for