#clojure log - Apr 19 2014

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:01 bodie_: this is probably a silly question, but let's say I want to work on a library project (say a DigitalOcean API client), which I'm testing using a project with a -main. how do I include the lib project?

0:01 (using Lein.)

0:01 or uh, where do I need to start looking to understand this, that is?

0:02 I get how to include external deps using lein... would I want to uberjar the subproject and include the jar as a resource?

0:09 owl-v-: how do i chanve :else part so that it runs without error? https://www.refheap.com/77460

0:10 putting elements of v into vv one by one in a recursive-function

0:15 solved my problem. but output is not correct

0:16 how do i get output '(1 2 3) from this code? https://www.refheap.com/77461

0:20 solved!

0:21 https://www.refheap.com/77462

0:21 solved :)

1:26 teltubs: anybody got lighttables to work on linux ?

1:29 exit

2:06 mr-foobar: hi all, need some help I'm followinghttps://github.com/clojure/clojurescript/wiki/Quick-Start but I can't execute `:target: nodejs` code because it is outputting goog... code in the output

3:06 yedi: yesssssssssssss

3:18 owl-v-: why is it hard to debug in clojure?

3:20 oskarkv: owl-v- is it hard? :P

3:22 owl-v-: it's much harder to debug in clojure than in python.

3:22 error prompt is not useful.

3:23 it's not telling what's wrong about my code

3:24 it just points to some line

3:24 oskarkv: owl-v- you mean stacktraces?

3:25 owl-v-: m.. maybe.. yes.

3:25 oskarkv: show me one :p

3:25 example

3:27 owl-v-: https://www.refheap.com/77486

3:28 oskarkv: owl-v- it does tell you what's wrong! "wrong number of args (0)..."

3:29 owl-v-: I can't tell where the # of args don't match

3:29 oskarkv: paste the code too and i'll help you :p

3:30 owl-v-: thanks T.T https://www.refheap.com/77487

3:30 amalloy: i predict that bfs.invoke(add.clj:45) contains a call to (apply max xs), where xs is empty

3:31 owl-v-: it happened when i added (digit3) condition in bfsfun

3:32 oskarkv: owl-v- it's probably what amalloy said

3:33 owl-v-: hm... then (apply max) can't use on empty list/vector...

3:33 amalloy: well, what is the max of an empty list?

3:33 owl-v-: ,(apply max '())

3:33 clojurebot: #<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: core/max>

3:33 owl-v-: !

3:33 amalloy: owl-v-: should it invent a number? how can you get the max?

3:34 owl-v-: hehe empty list

3:35 oskarkv: owl-v- Once you get more used to Clojure debugging is not that hard. Don't be discouraged! :p

3:36 owl-v-: thanks for your encouragement!

3:37 amalloy: it's true. i only needed to look at that stacktrace for about five seconds before i predicted the mistake. you can get there too

3:39 owl-v-: funny, the stack points to (for) where the actual problem happens on (max)

3:39 or does it points to the argument of (max)?

3:41 amalloy: maybe you have the line numbers wrong. it should be pointing to apply

4:40 owl-v-: i have no idea where (recur) goes to in this case. https://www.refheap.com/77488

4:41 i thought it (recur) to bfsfun with (pup u) but it shows the same value after iteration

4:41 something fishy about (let)...

4:50 the value is not equals to expected value: https://www.refheap.com/77494

4:52 is the problem from (let) or (recur)?: https://www.refheap.com/77494

5:04 in a recursive-function, (let) value don't change after (recur) ?

5:10 omg! i simply replaced (pop) to (rest) and it worked!: https://www.refheap.com/77494

5:11 what was i thinking ...

5:41 where would u recommend clojure over python? data-base? ai? embedded-system?

5:52 penthief: Is there a way to stop a blocking socket read without taking down the whole process when in a cider repl?

5:53 coventry`: owl-v-: I've used python since the 90s. I would say python still has the edge in scientific programming and visualization, and may be superior in other areas where it has very mature libraries. However as general programming languages, clojure's thoughtful state management policies give it a clear edge.

6:28 owl-v-: coventry`: thanks.

6:52 still.. lips way is un-natural to me, but it's interesting as hell :-)

6:57 (question "can clojure have an infinite loop?")

6:58 (question "will clojure eat up all memory if (recur) used for infinite loop?")

7:03 AimHere: owl-v-, yes. no.

7:03 At least, as far as I'm aware

7:04 owl-v-: cool!

7:05 AimHere: Use this knowledge for good, not evil

7:07 owl-v-: um... (def good ..) (def evil ..)

7:11 how do I define good and evil?

7:12 is it global (def) or local (def)?

7:13 it would be interesting to see implementation of good/evil in artificial-intelligence .

9:28 is there way to add map? {:a 1} + {:a 2} = {:a 3}

9:29 is there way to add map? {:a 1, :b 2} + {:a 2, :b 1} = {:a 3, :b 3}

9:29 jkj_: interesting... is there map vals or so

9:29 Bronsa: ,(merge-with + {:a 1 :b 2} {:a 2 :b 1})

9:29 clojurebot: {:b 3, :a 3}

9:30 owl-v-: lol. i don't see (merge-with) in this website: http://clojuredocs.org/clojure_core/1.2.0/clojure.core/map

9:32 AimHere: That's because that's an (outdated) page on the 'map' function, not the map data structure

9:32 owl-v-: and this too: http://clojuredocs.org/clojure_core/clojure.core/map

9:32 jkj_: clj-kitchensink might do it: https://github.com/puppetlabs/clj-kitchensink/blob/master/src/puppetlabs/kitchensink/core.clj#LC315

9:33 deeply... merge-with is nice if no deep required

9:33 Bronsa: owl-v-: map is a function that operates on seqs, it has nothing to do with merge-with

9:33 AimHere: I like the clojure cheatsheet meself. Try looking up the section 'Maps' in in here: http://clojure.org/cheatsheet

9:34 owl-v-: hm... actually... it does not work on "tryclj.com"

9:34 (merge-with {:a 1} {:a 1} ) -> {:a 1}

9:35 ops! forgot to put "+"

9:38 so.. clojuredocs.org is way out dated.

9:38 it's updated up to 1.3.0

9:54 cddr: What's the easiest way in clojure to override part of an interface (e.g. override the `write` method of an output stream)

9:59 Ah, maybe proxy

10:00 malyn: cddr: I use this for such questions -- https://github.com/cemerick/clojure-type-selection-flowchart

10:01 owl-v-: what's 2^3=8 in clojure?

10:03 cddr: Hm, I think the flowchart leads me to reify. What I want is a writer that instead of writing to the console, collects messages into an array so they can be verified in a test

10:05 malyn: cddr: Isn't that just with-out-str?

10:05 &(doc with-out-str)

10:05 lazybot: ⇒ "Macro ([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls."

10:06 cddr: Maybe that would work

10:11 owl-v-: clojure needs MATH!

10:12 don't tell me to loop

10:12 because that's like looping (+) to do (*)

10:21 cddr: malyn: Thanks for being my duck. I was totally overthinking it

10:21 owl-v-: still can't find math

10:25 :-(

10:27 where is scientific mind in clojure?

10:29 T.T

10:39 oh, clojure. give me MATH

10:40 clojure, let me do (= 8 (^ 2 3))

10:41 weavejester: owl-v-: (Math/pow 2 3)

10:41 invasmani: owl-v-: https://github.com/clojure/math.numeric-tower

10:43 owl-v-: weavejester: OMG!!!! big.THANK.u

10:44 i was going to give up and use python to solve math problem.

10:44 I had to use (int (Math/pow 2 3) to get integer.

12:13 bbloom: i really want an auto-splicing sequence data type

12:13 (conj [1 2 3] (splice 4 5)) => [1 2 3 4 5]

12:17 conj is already polymorphic for maps additions:

12:17 ,(conj {} nil [:x 1] {:y 2 :z 3})

12:17 clojurebot: {:z 3, :y 2, :x 1}

12:17 bbloom: need a non-polymorphic conj for vectors, something like "append"

12:18 then conj can auto splice :-)

12:18 jkj: concat too slow?

12:21 owl-v-: bbloom: what's (splice 4 5) ?

12:23 bbloom: owl-v-: some thing i just made up

12:24 jkj: slow is not the issue, i want to be able to move the decision to concatenate from the receiver of the value to the generator of the value

13:08 owl-v-: bbloom: how does (splice) works?

13:08 bbloom: how does (splice) work?

13:16 TravisD: I am implementing some experiments where the goal is to compare different algorithms for solving the same problem. Right now, I am planning to make a protocol that defines the interface each algorithm should have, so that I can write the rest of the experiment code against these protocols. Is this abuse?

13:21 apricots: If I type “lein cljsbuild auto &” to background the command in my shell, instead of backgrounding, it replies with “[1]+ Stopped lein cljsbuild auto”. It’s a minor annoyance, but is there a way to around that?

13:28 Jaood_: apricots: no idea, maybe you should try screen/tmux

13:30 ismaelvc: Hello everyone! I'm reading the clojure introduction at clojure-doc, I'm currently on "namespaces", and after reading about (require '[clojure.string :as str]), I tried to do (require '[javax.swing.JOptionPane :as Pane]), but I get: user=> (require '[javax.swing.JOptionPane/showMessageDialog :as Diag]) FileNotFoundException Could not locate showMessageDialog__init.class or showMessageDialog.clj on classpath: clojure.lang.RT.

13:30 I only know Python, I'm trying to do something analogous to this in Jython: >>> from javax.swing.JOptionPane import showMessageDialog as Diag >>> Diag(None, "Hello Jython!")

13:31 JohnJ: noob here, I have this result from a function => ({: 1}) , what is this? A map with a empty string as key?

13:32 ismaelvc: I would say you need a require in the project.clj, do you have it?

13:32 dbasch: apricots: lein cljsbuild auto < /dev/null &

13:32 mpenet: ,(import 'javax.swing.JOptionPane)

13:32 clojurebot: #<ExceptionInInitializerError java.lang.ExceptionInInitializerError>

13:33 dbasch: apricots: and you probably want to redirect the output to a file

13:33 mpenet: ismaelvc: meh should work, in short java stuff gets imported with "import" not require

13:34 ,(import '(javax.swing JOptionPane))

13:34 clojurebot: #<NoClassDefFoundError java.lang.NoClassDefFoundError: Could not initialize class javax.swing.JOptionPane>

13:37 mpenet: ismaelvc: then (JOptionPane/showMessageDialog nil "meh")

13:39 r00k: Hi all, I'm trying to insert a record in a postgres db using korma. I'm calling (insert clients (values {:date_of_birth "1980-01-01"})). This gives me "ERROR: column "date_of_birth" is of type date but expression is of type character varying" from QueryExecutorImpl.java. This seems an odd error since pg happily accepts strings for that column in the psql console. Any thoughts?

13:40 (I realize that I'm touching pg and java here, and this might not be a clojure thing at all.)

13:44 ismaelvc: <JohnJ> No I don't have a require in project.clj, I just started using the REPL

13:45 zamaterian: r00k, try converting your string to a java.sql.Date

13:46 ismaelvc: <mpnet> Thanks that is closer to what I wnated, but still how can I make an alias for showMessageDialog?

13:49 r00k: zamaterian: Thanks! Giving that a shot.

13:49 ismaelvc: I want to write just (Diag nil "meh") instead of (JOptionPane/showMessageDialog nil "meh")

13:52 JohnJ: guys which data structure is this: {: 1} ?

13:52 bhauman: ismaelvc: (defn diag [a b] (JOptionPane/showMessageDialog a b))

13:54 r00k: zamaterian: So when I convert my string to a java.sql.Date, it includes a time portion, so it's certain day at midnight at UTC. When I insert that in pg, it's storing it an one day prior, presumably because I'm in -5 UTC. Think I should specify a time zone on the java.sql.Date? I'd really rather avoid timezones entirely.

13:54 s/an one/as one

14:03 ismaelvc: bhauman: Thanks that works as I intended! So there's no alias when importing, only while requiring, right?

14:04 owl-v-: oh.. man. how do i sum prime numbers in between 1 and 2000000 ?

14:04 i'm using brute force

14:04 bhauman: ismaelvc: you can only alias the namespace not the definitions (functions) within the space

14:05 owl-v-: it's taking a lot of time...

14:05 honza: is there a list of built-in clojure functions that return chunked seqs?

14:05 owl-v-: and it's still calculating...

14:06 zamaterian: r00k, I would look into using clj-time

14:07 r00k, https://github.com/clj-time/clj-time

14:09 r00k: zamaterian: Thanks, but I actually have been using that. Still having issues. I'll keep struggilng.

14:17 ismaelvc: bhauman: Then what would be the advantege of first importing and then defining a function, I think it is better and less code just in one go like this: user=> (defn dialog [message] (javax.swing.JOptionPane/showMessageDialog nil message)) #'user/dialog user=> (dialog "Hello Clojure!") nil. Is there any drawback from doing it this way? Thanks so much! :)

14:19 bhauman: ismaelvc: there are no drawbacks that I see to either, case by case

14:21 creese: I'm wondering what is best practice for app-level configs in a leiningen project. I want to store info like database-url, redis, etc. but somewhere I can keep out of version control. Is the ability built-in?

14:21 mpenet: creese: https://github.com/weavejester/environ is nice for this kind of things

14:22 or just read an edn file that you pass as argument to your app -main

14:22 many ways to do this (yaml comes to mind too)

14:24 bhauman: creese: look at the functions: slurp and read-string , it’s pretty tirvial to read a clojure data structure from a file

14:25 mpenet: http://clojure.github.io/clojure/clojure.edn-api.html this read-string, not the one from core preferably...

14:25 ,(doc read-string)

14:25 clojurebot: "([s]); Reads one object from the string s. Note that read-string can execute code (controlled by *read-eval*), and as such should be used only with trusted sources. For data structure interop use clojure.edn/read-string"

14:27 creese: mpenet: I've used yaml before, seems like edn is a better choice here

14:27 * bhauman mpenet: is the one in core unsafe or outdated?

14:28 bhauman: mpenet: ok got it

14:29 don’t know why I ignore clojurebot so much, he seems to know what he’s talking about

14:29 mpenet: I like edn better too, but if you need to expose it to ppl who are not familiar yaml (or something else) can be a better choice

14:39 sm0ke: i can see a cljs/core.js in the :output-dir, but still my browser complains "goog.require could not find: cljs.core "

14:40 i was just trying to get the brepl working

14:40 https://github.com/cemerick/piggieback#browser-repl

14:44 amalloy: honza: well, the main ones are like...range, and seq on a vector. then there are the functions that preserve chunkiness, and the ones of those that i remember are for, map, filter/remove

14:44 bhauman: sm0ke: in that tutorial index.html is in the root of your project and so is the out/ directory

14:44 honza: amalloy: cool

14:45 ,(chunked-seq? (seq [1 2 3]))

14:45 clojurebot: true

15:14 mpenet: anyone knows if its possible to hide a protocol from codox generated doc?

15:17 nm

15:26 yedi: so i have a git repo that has my webapp in it, i gitignore resources/public/out.

15:27 to deploy my app, I pull the git repo and run lein uberjar from the remote server

15:28 however when i run lein uberjar, it seems that my resources/public/out isn't getting generated. so i get errors like GET http://reasonedrhymer.com/out/goog/base.js 404 (Not Found)

15:28 dbasch: yedi: it’s usually not a good idea to build things in a production server anyway

15:29 yedi: hm, so I guess I should just somehow get the uberjar to the server during the deploy process? would it make sense to put the uberjar in source control?

15:29 dbasch: yedi: what I do is I have deploy scripts that scp the uberjar to the server

15:30 yedi: btw, have you checked the uberjar to make sure the resources are in it?

15:30 yedi: well it ran fine on my vm when I scped the uberjar over for testing

15:31 is there a way to inspect uberjars for specific resources?

15:31 dbasch: yedi: jar tvf file.jar |grep resources

15:31 yedi: and yea, looks like i'll just do the scp strat, i was tryna avoid that since i'm generally on shitty internet so it might be slow, but if that's the best way i'll do it

15:31 cool thanks dbasch

15:53 mpenet: if you use emacs you can just open/browse/modify it with dired

17:33 coventry: Anyone here used double-check? I'm getting "WARNING: No such namespace: math.seedrandom at line 1 file:.../pprng-0.0.2.jar!/cemerick/pprng.cljs" from cljsbuild, then "Undefined nameToPath for math.seedrandom" from javascript. Where should I be pulling in math.seedrandom from? Is it this? https://github.com/davidbau/seedrandom

17:33 cemerick: coventry: follow the directions in the readme re: :libs

18:07 coventry: cemerick: Thanks.

18:11 eraserhd_: So, I've just written some more threading macros. This is usually a bad idea, I imagine.

18:12 First, I wrote (in-> v a-fn & forms)

18:14 where, if a-fn is a keyword, is equivalent to (update-in v [a-fn] (fn [s] (-> & forms))).

18:14 and if a-fn is a function, is equivalent to (a-fn v (fn [s] (-> & forms)))

18:14 for "lifting" sub-state.

18:16 Then I wrote ->' , which is like -> except that it treats if and if-not specially, threading the value through the then and else clauses.

18:16 * eraserhd_ is doing it wrong.

18:41 atlasblade: https://www.youtube.com/watch?v=bcuqxj5YTA8

18:41 https://www.youtube.com/watch?v=bcuqxj5YTA8

18:53 ToBeReplaced: is there a function to do (zero 1.0) => 0.0, (zero 1) => 0, etc.?

18:54 Bronsa: ToBeReplaced: (defn zero [n] (- n n))

18:57 coventry: With cemerick.austin, what am I likely doing wrong if the browser repl connection string gives the error 'Cannot write "http://localhost:8001/out/goog/useragent/useragent.js" after document load'?

19:00 dbasch: coventry: what’s your version of clojurescript?

19:00 coventry: eraserhd_: You may want to take a look at synthread. It is a library of threading macros which the authors motivated in terms of monads.

19:00 Never used it myself.

19:08 tempeh: Hi

19:08 I'm looking for a good book or resource on functionally oriented algorithms/patterns

19:08 Any ideas?

19:32 waynr: howdy folks

19:33 anyone have advice for figuring out why this clojure program i am working with takes so long to load?

19:33 nightfly: Is it much longer than any other Java/Clojure program?

19:33 waynr: it's generally around 5 seconds

19:34 nightfly: that sounds pretty normal

19:34 waynr: ah wait i just measured it's more like 15 seconds

19:37 i added an aleph tcp port to the program which added 10 seconds to the load time compared to what it was previously

19:39 i mean, an aleph tcp server

19:49 amalloy: waynr: aleph is pretty big. it takes a while to compile all that stuff

19:52 mr-foobar: hi all, I am trying to integrate grunt and cljs https://github.com/harsha-mudi/grunt-contrib-cljs I am getting a "goog not defined" when I run a compiled main.js script.

19:53 This what I am executing in the grunt `cljsc app/cljs '{:target :nodejs :optimization :none :output-to "generated/js/deps.js" :output-dir "generated/js/"}'`

19:58 dbasch: mr-foobar: how do you run your script?

19:59 mr-foobar: dbasch: `node generated/js/main,js` https://github.com/clojure/clojurescript/wiki/Quick-Start (hello world code)

20:01 dbasch: see “Notes on optimization settings"

20:04 coventry: With test.check, I can I make a generator like gen/any, which goes at least n levels deep before it starts including simple types? I need some way for sized-container to know how deep in the structure it's being called.

20:05 mr-foobar: dbasch: require("./generated/js/goog/bootstrap/nodejs") fails because there is not bootstrap folder

20:06 satshabad: Hi, I've run into a frusterating problem with lein ring server, when I have a dir under /resources/public with a few web fonts ( .eot .svg, .tff and .woff files) lein ring server will auto refresh my browser forever

20:08 hmm looks like there is a stylesheet.css in there and when I rm it, the problem stops...

20:10 mr-foobar: dbasch: oops typo, :optimizations :none gives me the bootstrap folder

20:20 owl-v-: assume that the function call is very expensive, how one can remove (recur) tail-recursion?

20:21 tempeh: that seems entirely context dependent

20:22 owl-v-: breath-first-search and depth-first-search?

20:23 and iterating through list and update values?

20:29 ok ok, if i increment a value through loop and append it to a list/vector, this is going to eat up my memory faster than mutable-list/vector.

20:32 if there is a way to remove old values(throw them into garbage collector) then I can happily use immutable list/vector

20:39 crocket: Is clojure going to win on the server side?

20:41 beamso: why not?

20:42 mr-foobar: dbasch: thanks ! the grunt task is working now with :simple need to polish it further.

20:43 tempeh: @owl-v- not sure what you mean by your latter comments, but why do you want to get rid of recur?

20:43 Can anyone recommend a good book/resource on functional algorithms/design patterns?

20:44 amalloy: tempeh: well, SICP is free and is amazing. Purely Functional Data Structures has some seriously good stuff but is pretty challenging

20:45 tempeh: @amalloy I've looked into SICP and was turned off by it's use of Sceme. Is it not a problem?

20:45 *scheme

20:45 amalloy: language doesn't matter so much. you asked about algorithms and design

20:46 and like, it's hard to find a language closer to clojure than scheme anyway

20:46 tempeh: Right, I meant is it a problem if I've never used Scheme

20:46 amalloy: no

20:46 tempeh: did you read it without knowing scheme?

20:46 amalloy: not for long!

20:46 pretty soon i knew scheme

20:46 tempeh: ha, okay

20:47 thanks, i'll look into getting it then

20:47 amalloy: you can learn scheme in like...an hour, if you're familiar with programming and with lisp especially. the language is so small

20:47 tempeh: in what way is purely functional data structures challenging?

20:47 okay

20:48 amalloy: it's a very dense book covering difficult concepts in a way that feels like a mathematics textbook

20:48 tempeh: that might be more what I'm looking for actually

20:48 amalloy: tempeh: you can find some free papers by okasaki and read those, if you want to evaluate whether you want to buy PFDS

20:49 actually maybe PFDS is free too? not sure

20:49 http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf looks like his thesis - i don't know if the book is identical or just closely related

20:50 agarman: the thesis is more about his framework for analysis of persistent datastructures

20:50 tempeh: ah, okay

20:50 agarman: the book is more about implementations and practical usage

20:51 both are aws=esmom

20:51 tempeh: I found a directory of his papers, i'll check out one of those

20:51 thanks for you help guys, i know what i'm doing tonight

20:51 amalloy: http://www.westpoint.edu/eecs/SiteAssets/SitePages/Faculty%20Publication%20Documents/Okasaki/jfp98sixth.pdf is probably the first thing by him i read

20:51 nice and short

20:52 tempeh: oh christ

20:52 i hope the answer to "why would anyone ever want to use a 6th order function" is "no one, ever"

20:52 agarman: his thesis is the first thing of his I read

20:53 flattening combinators is good

20:54 http://www.westpoint.edu/eecs/SiteAssets/SitePages/Faculty%20Publication%20Documents/Okasaki/jfp03flat.pdf

20:55 amalloy: i should add his disclaimer as my email signature: The views expressed in this [email] are those of the author and do not reflect the official policy or position of the United States Military Academy, the Department of the Army, the Department of Defense, or the U.S. Government.

20:56 TimMc: ooo, ligature

20:56 amalloy: Heck, use that as your IRC signature.

20:57 amalloy: TimMc: maybe my AIM buddy profile

20:57 TimMc: You never know when some statement of yours might be misunderstood as an official position of the US gov't.

21:05 owl-v-: tempeh: i want to have some optimization

21:20 it's interesting to see creating a function in a loop in a function have different reference for each iteration: https://www.refheap.com/77755

21:24 xcthulhu: How do I lazily read lines from a gzipped file?

21:29 dbasch: xcthulhu: use line-seq on a java gzipinputstream

21:30 xcthulhu: Trying that, running out of heap :(

21:30 (defn populate-from-json-gz

21:30 "Populate the database using a GZIPPED JSON file of chemical reactions"

21:30 [json-gz]

21:30 (with-open [data (io/reader

21:30 (java.util.zip.GZIPInputStream.

21:30 (io/input-stream json-gz)))]

21:30 (first (line-seq data))))

21:30 (populate-from-json-gz “really_big.json.gz")

21:30 hehe, should have killed the docstring

21:31 dbasch: xcthulhu: use refheap

21:32 xcthulhu: https://www.refheap.com/77756

21:32 Checking now to make sure that I’m actually writing seperate lines...

21:33 Since if I don’t have newlines in that huge JSON it would make sense that this is falling over

21:43 Okay, that was it. Sorry for bothering everyone :(

22:23 Frozenlock: SVG showing as a broken image with compojure. Any ideas why? (All the other types are fine... jpg, png...)

22:24 jdkealy: how am i supposed to get payload params in a post request with compojure ?

22:25 Frozenlock: jdkealy: are you using the params middleware?

22:25 https://weavejester.github.io/compojure/compojure.handler.html

22:26 jdkealy: i am requiring compojure.handler

22:27 agarman: you need to wrap your routes in wrap-params

22:27 or api or site

22:27 Frozenlock: But are you using it? (-> my-awesome-app-routes <and now the middleware --->> handler/site)

22:29 jdkealy: no i don't think i am

22:30 i will try to add the middleware to my awesome app routes :)

22:34 dbasch: Frozenlock: how are you serving the file?

22:35 Frozenlock: [:img {:src "/img/some-image.svg"}]

22:35 dbasch: Frozenlock: ok, how are you serving /img

22:36 jdkealy: when you use wrap-params, can you still start server with "lein ring server" or do you need to write a custom start/stop method ?

22:36 Frozenlock: dbasch: You mean like text/html? I let compojure deal with it :p

22:36 dbasch: Frozenlock: I mean, are you using route/resources ?

22:37 Frozenlock: Ah! I'm using the wrap-resource middleware

22:37 Like I said, everything else seems to work.

22:38 JS, CSS, images (jpg png)... but not svg

22:38 owl-v-: how do i call java function in myjavacode.java?

22:39 dbasch: Frozenlock: svg is being served as “"image/svg+xml"

22:39 beamso: (package.Class/staticMethod args)

22:39 dbasch: https://github.com/mmcgrana/ring/blob/master/ring-core/src/ring/util/mime_type.clj

22:39 beamso: (instanceMethod instance args)

22:39 Frozenlock: dbasch: Isn't it what it's supposed to be?

22:40 dbasch: Frozenlock: should be, you may want to check

22:41 Frozenlock: uh, my browser says it's being sent with text/xml

22:42 dbasch: Frozenlock: there’s your problem

22:42 Frozenlock: try using route/resources instead of wrap-resource

22:47 Frozenlock: dbasch: I would expect them to be quite similar... But will try anyway. Thanks :-)

22:47 dbasch: Frozenlock: I was just looking at the source, route/resources tries to guess the mime type

22:48 Frozenlock: I coudn’t find the same thing in wrap-resource

22:48 Frozenlock: if you request other file types, what mime-type do you get?

22:48 Frozenlock: I’m curious if you get text but the browser recognizes the extension and renders it anyway

22:49 “be liberal in what you accept"

22:51 Frozenlock: Hmm... unless my browser is lying, there's image/png and image/jpeg. Local JS is text/plain however...

22:51 Weird

23:02 Yay, now my javascript is send with text/javascript.

23:02 But my svg is still with text/xml

23:06 dbasch: Frozenlock: btw, what browser are you using?

23:06 Frozenlock: chromium

23:08 dbasch: Frozenlock: are you sure the file is proper svg? Chromium renders svg just fine for me even without a mime-type in the response

23:09 Frozenlock: what does your main handler look like?

23:09 Frozenlock: Yes, taken directly from wikipedia.

23:10 https://www.refheap.com/77766

23:10 I think wrap-content-type middleware isn't added anywhere... O_o

23:10 dbasch: the wikipedia file doesn’t render for me either

23:11 Frozenlock: dbasch: You get improper SVGs from wikipedia?

23:11 But anyhow, I can see it normaly, but not when I use it on my app.

23:11 dbasch: no, it’s fine

23:11 but the wikipedia server serves it with Content-Type:image/svg+xml

23:13 Frozenlock: I'm an idiot

23:13 resources fixed it alright

23:13 dbasch: If I add (route/resources "/") to my routes, it works

23:13 Frozenlock: It was cached...

23:13 dbasch: and it’s for that reason: wrap-resource does’t guess the mime type, and route-resources does

23:13 doesn't

23:14 Frozenlock: F5 instead of shift-F5

23:14 dbasch: You successfully found and solved my problem, thank you very much! :-)

23:15 dbasch: Frozenlock: np, I wonder if that’s a bug in wrap-resource or the intended behavior

23:15 Frozenlock: Any point in keeping 'wrap-resource' if just 'resources' works?

23:17 dbasch: Frozenlock: resources only works for a specific path, wrap-resource falls back on a handler if no resource is found

23:20 Frozenlock: If it can't find the file, how would falling back on the handler help?

23:21 amalloy: Frozenlock: the point is you use it like (wrap-resource (handle-non-resources))

23:22 Frozenlock: amalloy: Like generating a file on the fly?

23:22 amalloy: so first it tries finding a resource corresponding to the request, and if no such resource exists then it assumes the request must be for something else (eg, one of your dynamically generated pages) and calls your "main" handler

23:22 Frozenlock: I see. Thanks

23:23 amalloy: (wrap-resources foo handler) is a lot like (routes (resources foo) handler)

23:23 dbasch: amalloy: do you think not attempting to guess the mime-type is just an omission?

23:24 amalloy: *shrug*

23:24 dbasch: amalloy: probably, I see no reason to do it in resources and not in wrap-resource

23:25 amalloy: dbasch: i'm pretty sure weavejester has thought about it a lot more than you or i have, and hundreds of people before you have used this function. if it behaves a particular way, there's probably a reason that's deeper than "i see no reason not to"

23:25 but i don't have any special knowledge there, so who knows

23:30 dbasch: amalloy: resources is in compojure, wrap-resource is from ring

23:30 there was this issue: https://github.com/ring-clojure/ring/issues/21

23:31 but no mention of mime-type

23:31 amalloy: then it's not an omission at all! it's just a feature that's outside of ring's scope, probably

23:31 dbasch: amalloy: makes sense

23:32 Frozenlock: So 'resources' is like wrap-resources, but with a little more sugar

23:36 dbasch: and content-type is too specific for ring, there’s no reason to assume a resource is going to be rendered by a browser at that level

Logging service provided by n01se.net