Fork me on GitHub
#clojure
<
2017-12-03
>
Bravi09:12:34

I’ve created a new project using chestnut template and when I do lein install, it throws this error:

Cannot run program "sassc": error=2, No such file or directory
once I remove this bit from my project.clj it works:
:sassc [{:src "src/scss/style.scss"
           :output-to "resources/public/css/style.css"}]

  :auto {"sassc" {:file-pattern  #"\.(scss)$"
                  :paths ["src/scss"]}}

Bravi09:12:55

is there something wrong with sassc?

qqq10:12:36

(reduce * (int-array [1 2 3 4])) <-- why does this code work? what is causing the reduce to be able to handle what I believe to be a JVM object

noisesmith16:12:01

to be pedantic, if you are using clojure on the jvm, everything in clojure is a JVM object

noisesmith16:12:45

clojure happens to define its core functions in terms of some basic Interfaces and Classes, including Arrays

rauh11:12:02

@qqq It goes like this: reduce -> coll-reduce -> protocol on type "Object" -> seq the given array -> ArraySeq_int -> Faster internal reduce on it.

rauh11:12:24

@qqq Actually, this is wrong: Check out:

(reduce (fn [_ _]
          (try (throw (Exception.)) (catch Exception ex ex)))
        0 (int-array [0 1]))

rauh11:12:52

It'd would use a faster internal reduce if you seq your array beforehand, it's more than 2x faster with (reduce ... (seq (int-array ...))

bronsa11:12:49

@rauh I don't understand what that snippet is supposed to show

rauh11:12:52

@bronsa It's just a little hack to see get the stacktrace so I could see how the reduce function is called. With (seq (int-array ...) it shows nicely it's called from ArraySeq_int.reduce

bronsa11:12:27

nice hack :)

rauh11:12:59

@bronsa Do you think (reduce ... ... some-array) should also end up in ArraySeq_int.reduce? I could create a ticket for it..

Bravi12:12:03

has anyone ever had a problem with clj-http when using :as :clojure? i.e.

(client/get "" {:as :clojure})
I’m getting the following in my browser
Invalid keyword: .

Bravi12:12:50

and when adding

[org.clojure/tools.reader "1.1.1"]
to my deps, CIDER dumps the following
WARN: org.clojure/clojure version 1.5.1 requested, but 1.8.0 already on classpath.
WARN: org.clojure/tools.reader version 1.1.1 requested, but 1.0.0 already on classpath.
Dependencies not loaded due to conflict with previous jars :
[[org.clojure/clojure "1.5.1"] [org.clojure/tools.reader "1.1.1"]]

dominicm12:12:22

@bravilogy The contents of foo.clj might be up for question

Bravi12:12:50

if I do :as :json then it works fine

Bravi12:12:12

could it be that clojure map just doesn’t like something in there?

dominicm12:12:28

@bravilogy but, valid clojure is not the same as valid json

dominicm12:12:41

Are you requesting a clj file, or a json file?

Bravi12:12:57

it’s a json response from a server

Bravi12:12:15

I thought it would convert automatically, but I guess that’s the issue yes 🙂

dominicm12:12:47

:as :clojure is for taking a clojure string and turning it into a data structure.

dominicm12:12:59

:as :json takes a json string, and turns it into a data structure.

Bravi12:12:11

ah gotcha. thanks!

Bravi12:12:03

and I’m guessing there’s no way to convert json to clj map, right?

scknkkrer12:12:52

@bravilogy can you take a look at this.

dominicm12:12:04

@bravilogy Does :as :json not do that for you already?

Bravi12:12:52

doesn’t seem to be doing so. it returns json string when I do (:body response)

dominicm12:12:10

@bravilogy do you have a dependency on cheshire?

Bravi12:12:14

as I read in clj-http docs, :as :json requires cheshire lib. and when I add that to my deps, I get

[[cheshire "5.8.0"]
 [tigris "0.1.1"]
 [com.fasterxml.jackson.core/jackson-core "2.9.0"]
 [com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.9.0"]
 [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.9.0"]]
Dependencies not loaded due to conflict with previous jars :
[[org.clojure/clojure "1.5.1"]]

Bravi12:12:39

and then the clj-http has that section for jackson thingy

Bravi12:12:04

and it says that it could be in conflict with clj-json but I can’t find this one in my deps

dominicm12:12:39

❯ boot -d clj-http -d cheshire repl
boot.user=> (require '[clj-http.client :as client])
nil
boot.user=> (client/get "" {:as :json})
{:request-time 390, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :chunked? false, :reason-phrase "OK", :headers {"Access-Control-Allow-Origin" "*", "Content-Type" "application/json; charset=ISO-8859-1", "X-Cloud-Trace-Context" "25dfdbec80312f279ee4fa15eb026444", "Date" "Sun, 03 Dec 2017 12:32:57 GMT", "Server" "Google Frontend", "Content-Length" "25", "Connection" "close"}, :orig-content-encoding nil, :status 200, :length 25, :body {:ip "185.65.134.175"}, :trace-redirects []}
Running my repl with cheshire got the body coercion working with :as :json

Bravi12:12:16

[[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.671" :scope "provided"]
                 [ring "1.6.2"]
                 [ring/ring-defaults "0.3.1"]
                 [compojure "1.6.0"]
                 [environ "1.1.0"]
                 [com.stuartsierra/component "0.3.2"]
                 [org.danielsz/system "0.4.0"]
                 [org.clojure/tools.namespace "0.2.11"]
                 [reagent "0.6.0"]
                 [re-frame "0.9.4"]
                 [buddy/buddy-core "1.4.0"]
                 [clj-http "3.7.0"]
                 [cheshire "5.8.0"]]

Bravi12:12:22

these are all the deps I have

Bravi12:12:24

I’m thinking, perhaps there’s a version conflict somewhere

dominicm12:12:39

probably. lein deps :show :tree I think is the way to find out. I think you're cutting off part of the error message I'm afraid.

Bravi12:12:48

Wrong number of arguments to deps task. 
Expected [] or [command]

Bravi12:12:01

lein deps :tree
worked

Bravi12:12:29

ok I’ll go through these exclusion recommendations and will try again thanks 😄

dominicm12:12:07

@bravilogy look for only the one you need. I've noticed the exclusions are very broad.

Bravi12:12:29

ok so I had lein-plz in my ~/.lein/profiles.clj and there were loads of exclusion recommendations for between clj-http and lein-plz. It’s one step to success I think because well, something’s working now 😄 So basically I have this handler

(defn open-orders [req]
  (let [{:keys [sig uri]} (api-sig :open-orders)]
    (client/get uri {:headers {"apisign" sig} :as :json})))
and then when I visit the url, it definitely outputs json because my chrome json plugin recognises it. The json looks something like this:
{
   success: true,
   result: { ... }
}
But if I do something like
(defn open-orders [req]
  (let [{:keys [sig uri]} (api-sig :open-orders)]
    (-> (client/get uri {:headers {"apisign" sig} :as :json}) :body)))) ;; notice the :body in here
then it returns just a text version of the response and therefore I can’t take out the result bit from it anymore. If I do
(defn open-orders [req]
  (let [{:keys [sig uri]} (api-sig :open-orders)]
    (-> (client/get uri {:headers {"apisign" sig} :as :json}) :result)))) ;; notice the :result in here
then it goes to 404 page

Bravi13:12:27

such a simple task is so complicated 😭 gonna have a major breakdown here haha

vemv23:12:13

dream library: code coverage for :pre / :post like: - for each ns, 20% of defns should have preconditions, and there should be at least one pre'd defn in any case - you cannot decrease coverage % pre/post + spec + integration testing = a damn lot of code gets excercised/asserted! better approach than unit tests in certain cases, e.g. a cljs SPA. would love to write that lib sometime in 2018