Re: Clojure performance question

2014-03-02 Thread Shantanu Kumar


On Sunday, 2 March 2014 12:49:15 UTC+5:30, Shantanu Kumar wrote:



 On Sunday, 2 March 2014 05:32:00 UTC+5:30, bob wrote:


 Good point, Thanks a lot. 

 Shall we improve the str fn in the core lib? From my point of view, the 
 core fns should be performance sensitive.


 If string formation is the bottleneck in your app and if you can come up 
 with a version of `str` function that works in all use-cases, then you can 
 probably `alter-var-root` the str fn with yours as long as you own the 
 responsibility.

 I noticed the following macro (ignore the reflection warnings) can help 
 shave some nanoseconds in a large tight loop, but I leave to you to decide 
 how much worth it really is:


Just to clarify: I meant `some nanoseconds` per invocation for small string 
only. Overall saving would be proportional to the occurrence count and args 
count.

Shantanu

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure performance question

2014-03-02 Thread Luc Prefontaine
I cannot agree with this...
Not at 100% at least.

String manipulations are frequent
enough to mandate some tuning
if the need is obvious.

Looks to me that this is the case here.

Other core fns went through rewrites
to improve performance.

Simplicity has nothing to do with
internal implementations.

If someone comes up with a better
implementation while providing
the same behaviours as the current
str fn, then it should make it's way
maybe in clojure.string.

fast-strings ? Whatever it may be
named.

Luc P.

 Core fns should be simple, unsurprising, and general.
 
 'Improving' str may hurt simplicity, make behavior more surprising and
 unexpected, and less general unless proven otherwise.
 
 On Sat, Mar 1, 2014 at 7:02 PM, bob wee@gmail.com wrote:
 
 
  Good point, Thanks a lot.
 
  Shall we improve the str fn in the core lib? From my point of view, the
  core fns should be performance sensitive.
 
 
 
  On Sunday, March 2, 2014 12:03:21 AM UTC+8, Shantanu Kumar wrote:
 
 
 
  On Saturday, 1 March 2014 15:32:41 UTC+5:30, bob wrote:
 
  Case :
 
  clojure verison:
 
  (time (dotimes [n 1000] (str n another word))) ;; take about
  5000msec
 
  java version
 
  long time = System.nanoTime();
 
  for(int i=0 ; i1000 ;i++){
  String a=i+another word;
  }
System.out.println(System.nanoTime()-time);
 
 
  The java version take about 500 msecs, I thought it might be caused by
  the str implementation which is using string builder, and it might not be
  the best choice in the case of no much string to concat, and then I 
  replace
  another word with 5 long strings as the parameter, however no surprise.
 
  I just wonder what make the difference, or how to find the difference.
 
 
  Others have added useful points to this thread. Java string concatenation
  internally uses StringBuilder, so if you replace (str n another word)
  with the following:
 
  (let [sb (StringBuilder.)]
   (.append sb n)
   (.append sb another word)
   (.toString sb))
 
  ..then the perf improves 1/4 to 1/3. Further, with the following tweak:
 
  (let [sb (StringBuilder. 20)]  ; because StringBuilder allocates only 16
  chars by default on Oracle JRE
   (.append sb n)
   (.append sb another word)
   (.toString sb))
 
  ..the perf improves from 1/3 to less than 1/2. Here we simply avoid
  double allocation in StringBuilder.
 
  Other things I made sure were:
 
  1. I used Criterium to measure
  2. I used `-server` option
  3. Made sure reflection warning was on
 
  Shantanu
 
   --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
--
Luc Prefontainelprefonta...@softaddicts.ca sent by ibisMail!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Can't start repl with Leiningen

2014-03-02 Thread Matej Fröbe
I found the problem more or less. lein repl works if I set iptables rule:
*#iptables -P INPUT ACCEPT*

What I don't understand is, why it worked already in the past with these 
rules:


*#iptables -P INPUT DROP#iptables -A INPUT -m state --state 
ESTABLISHED,RELATED -j ACCEPT*but now it doesn't.

The call to nrepl.ack/wait-for-ack in repl.clj (
https://github.com/technomancy/leiningen/blob/master/src/leiningen/repl.clj) 
wasn't succesfull with the stricter rules.


Am Mittwoch, 26. Februar 2014 22:10:57 UTC+1 schrieb Matej Fröbe:






 *#apt-get update#apt-cache show openjdk-7-jrePackage: openjdk-7-jreSource: 
 openjdk-7Version: 7u21-2.3.9-5...*

 So if I understand correctly (I'm more or less a Linux newbie), this means 
 that update 21 is the version in distro's repositories.


 Am Mittwoch, 26. Februar 2014 21:36:39 UTC+1 schrieb Zach Oakes:

 Is their a reason your OpenJDK install is only on update 21? I believe 
 the most recent is 51, though I doubt that is the problem. I also doubt 
 it's a memory issue; I can run the REPL just fine on a netbook with 1GB of 
 RAM running Ubuntu x64.

 On Wednesday, February 26, 2014 3:05:53 PM UTC-5, Matej Fröbe wrote:

 I only have 2GB. I tried adding -Xms1024M (and some lower and higher 
 values) to the java command in lein script, but it didn't help.


 Am Mittwoch, 26. Februar 2014 19:52:49 UTC+1 schrieb Armando Blancas:

 I had the same problem with an old box I had around the house. Put 
 Fedora 20 on it with a recent open jdk, but had just 1GB of memory total. 
 I 
 attributed the error to the lower memory since I never have that issue at 
 work or other machines with at least 4GB. If you have more than 2GB, 
 experiment with something like -Xms1024M or more.

 On Wednesday, February 26, 2014 9:28:42 AM UTC-8, Matej Fröbe wrote:

 Debian jessie 32-bit

 Am Mittwoch, 26. Februar 2014 15:50:19 UTC+1 schrieb John Gabriele:

 On Wednesday, February 26, 2014 3:19:43 AM UTC-5, Matej Fröbe wrote:

 It seems that this is independent of where I run the project.



 Matej,

 What OS (and version) are you using?
  



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[ANN] edn-java 0.4.4 released

2014-03-02 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release:

* Provides a pretty printer for edn data [3].
* Recognizes 'foo//' as a symbol [4].
* Provides experimental more readable, but still compact, edn printing [5].

It should be available on Maven Central within a day.

[1] http://edn-java.bpsm.us
[2] https://github.com/edn-format/edn
[3] https://github.com/bpsm/edn-java/issues/13
[4] https://github.com/bpsm/edn-java/issues/30
[5] https://github.com/bpsm/edn-java/pull/37

// Ben

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to get sha1 of a string

2014-03-02 Thread Ben Smith-Mannschott
(- Hello, World! .getBytes create-hash ...)

Will get you the hash of the string encoded to bytes using *some random
encoding*. (Whatever the platform you're currently running on defaults to.)

You should explicitly choose an encoding and stick to it. I'd suggest UTF-8
since that can encode all the code points that might show up in a Java
String.

(- Hello, World! (.getBytes UTF-8) create-hash java.math.BigInteger.)

// Ben


On Sat, Mar 1, 2014 at 7:49 PM, Zach Oakes zsoa...@gmail.com wrote:

 You can use java.security.MessageDigest. For example:

 (defn create-hash
   [data-barray]
   (.digest (java.security.MessageDigest/getInstance SHA1) data-barray))

 It takes and returns a byte array, but converting from/to a string is
 fairly straight-forward:

 (- Hello, World!
  .getBytes
  create-hash
  java.math.BigInteger.
  (format %x)
  println)

 On Saturday, March 1, 2014 11:26:29 AM UTC-5, action wrote:

 do like this:
 (ns clojurewerkz.support.hashing
   (:require [clojurewerkz.support.internal :as i])
   (:import [com.google.common.hash Hashing HashFunction HashCode]))
 but:
 FileNotFoundException Could not locate clojurewerkz/support__init.class
 or cloju
 rewerkz/support.clj on classpath:   clojure.lang.RT.load (RT.java:443)
 how to set the dependencies, or other solution?

 Think you


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to get sha1 of a string

2014-03-02 Thread action
ok,think you!

在 2014年3月2日星期日UTC+8上午12时28分25秒,JPH写道:

 I've had good experiences with https://github.com/xsc/pandect. 

 You can also use Java interop like this: 
 https://gist.github.com/prasincs/827272 

 JPH 


 On 03/02/2014 12:26 AM, action wrote: 
  do like this: 
  (ns clojurewerkz.support.hashing 
(:require [clojurewerkz.support.internal :as i]) 
(:import [com.google.common.hash Hashing HashFunction HashCode])) 
  but: 
  FileNotFoundException Could not locate clojurewerkz/support__init.class 
 or 
  cloju 
  rewerkz/support.clj on classpath:   clojure.lang.RT.load (RT.java:443) 
  how to set the dependencies, or other solution? 
  
  Think you 
  
  



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


I want to parse the POST body twice.

2014-03-02 Thread action
I want to parse the POST body twice,
but in the second place:
org.xml.sax.SAXParseException: Premature end of file.
How should I clone the body render for the second parse?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: case statement and java constants

2014-03-02 Thread Herwig Hochleitner
Created: http://dev.clojure.org/jira/browse/CLJ-1368


2014-03-01 2:58 GMT+01:00 Alex Miller a...@puredanger.com:

 I would appreciate a jira enhancement ticket for this.

 Alex

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to parse the POST body twice.

2014-03-02 Thread James Reeves
Depending on how large the input is, you could either read it all into
memory (e.g. with slurp or similar), or dump it to a temporary file.

- James


On 2 March 2014 16:18, action actioncao2...@gmail.com wrote:

 I want to parse the POST body twice,
 but in the second place:
 org.xml.sax.SAXParseException: Premature end of file.
 How should I clone the body render for the second parse?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to parse the POST body twice.

2014-03-02 Thread Herwig Hochleitner
Copy the body to a byte array or file before parsing (or while parsing it
the first time, if you want to save latency).
Your server doesn't do this, so that it can reuse a few small buffer chunks
instead of allocating the whole content-length, while streaming the body
into your application.

cheers


2014-03-02 17:18 GMT+01:00 action actioncao2...@gmail.com:

 I want to parse the POST body twice,
 but in the second place:
 org.xml.sax.SAXParseException: Premature end of file.
 How should I clone the body render for the second parse?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: case statement and java constants

2014-03-02 Thread Adam Clements
Oops, I already filed http://dev.clojure.org/jira/browse/CLJ-1367. Should
probably link/mark as dupe - I don't appear to be able to do anything other
than comment.


Adam


On Sun, Mar 2, 2014 at 4:35 PM, Herwig Hochleitner
hhochleit...@gmail.comwrote:

 Created: http://dev.clojure.org/jira/browse/CLJ-1368


 2014-03-01 2:58 GMT+01:00 Alex Miller a...@puredanger.com:

 I would appreciate a jira enhancement ticket for this.

 Alex

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Sente - Clojure(Script) + core.async + WebSockets/Ajax

2014-03-02 Thread Mark
Hi Peter -

I'm trying to learn Sente using the LightTable browser connected repl.  I 
try to evaluate the following code:
(let [{:keys [chsk ch-recv send-fn]}
  (sente/make-channel-socket! http://localhost:6100/chsk; ; Note the 
same URL as before
 {})]
  (def chsk   chsk)
  (def ch-chskch-recv)
  (def chsk-send! send-fn))

(put! ch-chsk From client!)

From the JS console, I see repeated, failed attempts to connect the server. 
 The server is running and responding to other http requests.  

Taking a very quick look at the source for the CLJS make-channel-socket!, 
it seems that it tries to resolve the url using the CLJS chsk-url function 
which, in turn, uses encore/get-window-location.  Since my browser window 
location is file://..., I think this is going to generate a bad url.  Am I 
reading the source correctly? Is there some way to make a channel socket by 
providing an absolute url?

On Thursday, February 27, 2014 10:53:08 PM UTC-8, Peter Taoussanis wrote:

 Quick addendum: I've had a few folks ask about various security 
 implementations.

 So first up - as I mention in the REAME, I have had to make some changes 
 to the codebase for the public release so I wouldn't quite trust anything 
 pre-1.0 in production just yet (there's likely at least minor bugs). Having 
 said that, the general model has played out well in practice elsewhere.

 A few specifics that have come up:

  * Tools.reader's read-string is used server-side, so arbitrary code 
 evaluation isn't an issue.
  * It _is_ possible for the server to receive malformed or hostile 
 requests (as it would be via any other protocol). The implementation itself 
 doesn't depend on the accuracy of any information provided by the client, 
 but the usual security measures will apply server-side for code you write: 
 only respond to well-formed requests, ensure users are 
 authenticated+authorised where appropriate, etc. Auth stuff is beyond the 
 scope of Sente, but it won't do anything to get in your way.
  * Ring session information _is_ made available server-side for all 
 requests (including WebSocket requests), so the commonest session-based 
 auth methods basically work out-the-box.
  * The client-side user-id *can* be forged, but it isn't used for anything 
 that's security sensitive. It's there only as an optimisation to disable 
 Ajax long-polling when a user clearly isn't logged in. If someone were to 
 fudge the id, the only negative effect would be an the creation of an 
 unnecessary long-polling connection that is never used (the server will 
 never acknowledge it).
  * HTTPS works seamlessly, even for WebSockets. When the page is served 
 over HTTPS, Sente will work over HTTPS.
  * CSRF protection is baked in, but you need to do a few things on your 
 end to enable it. A client-side warning will be printed when no CSRF code 
 is provided. Recommend checking out the example project for details (it 
 includes CSRF protection).

 So tl;dr - there's a bit going on, but nothing that's fundamentally 
 different from the usual Ring security model. Auth and CSRF are the 
 responsibility of the app as usual, but Sente provides hooks in the 
 appropriate places to plug in whatever you're using.

 Will try update the README later today with the info above.

 Hope that helps, happy Friday! :-)

 - Peter


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to parse the POST body twice.

2014-03-02 Thread action
how to use slurp?
first:
(slurp body)
and second reuse:
 (slurp body)

在 2014年3月3日星期一UTC+8上午12时44分09秒,James Reeves写道:

 Depending on how large the input is, you could either read it all into 
 memory (e.g. with slurp or similar), or dump it to a temporary file.

 - James


 On 2 March 2014 16:18, action action...@gmail.com javascript: wrote:

 I want to parse the POST body twice,
 but in the second place:
 org.xml.sax.SAXParseException: Premature end of file.
 How should I clone the body render for the second parse?
  
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: case statement and java constants

2014-03-02 Thread Herwig Hochleitner
Oh sorry, I should have looked at the newest issues first.

I don't think the tickets are dupes, because yours calls for enabling java
static fields for case constants.
Mine just wants to add language stating how case can be used right now.

IMO enabling case constants is at odds with current doc language about
symbols aswell as not evaluating case constants, hence shoudn't be done,
but I'll leave that decision to maintainers.

cheers


2014-03-02 17:51 GMT+01:00 Adam Clements adam.cleme...@gmail.com:

 Oops, I already filed http://dev.clojure.org/jira/browse/CLJ-1367. Should
 probably link/mark as dupe - I don't appear to be able to do anything other
 than comment.


 Adam


 On Sun, Mar 2, 2014 at 4:35 PM, Herwig Hochleitner hhochleit...@gmail.com
  wrote:

 Created: http://dev.clojure.org/jira/browse/CLJ-1368


 2014-03-01 2:58 GMT+01:00 Alex Miller a...@puredanger.com:

 I would appreciate a jira enhancement ticket for this.

 Alex

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to parse the POST body twice.

2014-03-02 Thread James Reeves
You can't consume an input-stream twice. You need to store the result
somewhere.

For example:

  (defn handler [request]
(let [body-str (slurp (:body request))]
  (do-something-to body-str)
  (do-something-else-to body-str)))

Be aware that in production you'll likely want to limit the maximum size of
the stream to avoid malicious users pushing through large amounts of junk
data and using up all the memory in your app. There's a class in the Apache
Commons I/O called BoundedInputStream that might be of use to you.

- James


On 2 March 2014 17:23, action actioncao2...@gmail.com wrote:

 how to use slurp?
 first:
 (slurp body)
 and second reuse:
  (slurp body)

 在 2014年3月3日星期一UTC+8上午12时44分09秒,James Reeves写道:

 Depending on how large the input is, you could either read it all into
 memory (e.g. with slurp or similar), or dump it to a temporary file.

 - James


 On 2 March 2014 16:18, action action...@gmail.com wrote:

  I want to parse the POST body twice,
 but in the second place:
 org.xml.sax.SAXParseException: Premature end of file.
 How should I clone the body render for the second parse?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com

 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com

 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to parse the POST body twice.

2014-03-02 Thread Herwig Hochleitner
Don't slurp twice. Slurp mutates the stream by reading bytes off of it.

Also, slurping an xml stream isn't a good idea, because the xml header can
change the character encoding like so

?xml version=1.0 encoding=ISO-8859-1?

Try

(let [bufstream (doto (java.io.ByteArrayOutputStream. content-length)
  (clojure.java.io/copy body bufstream))
  buffer (.toByteArray bufstream)]
  (parse-1 (java.io.ByteArrayInputStream. buffer))
  (parse-2 (java.io.ByteArrayInputStream. buffer)))

This way, your parse functions that take an input stream work unchanged.
Be aware, that this allocates memory in the size of the body.


2014-03-02 18:23 GMT+01:00 action actioncao2...@gmail.com:

 how to use slurp?
 first:
 (slurp body)
 and second reuse:
  (slurp body)

 在 2014年3月3日星期一UTC+8上午12时44分09秒,James Reeves写道:

 Depending on how large the input is, you could either read it all into
 memory (e.g. with slurp or similar), or dump it to a temporary file.

 - James


 On 2 March 2014 16:18, action action...@gmail.com wrote:

  I want to parse the POST body twice,
 but in the second place:
 org.xml.sax.SAXParseException: Premature end of file.
 How should I clone the body render for the second parse?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com

 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com

 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Sente - Clojure(Script) + core.async + WebSockets/Ajax

2014-03-02 Thread Peter Taoussanis
Hi Mark,

I'm trying to learn Sente using the LightTable browser connected repl.


Ahh, nice. Haven't tried LightTable yet myself, but I'd think it should
work okay.



 From the JS console, I see repeated, failed attempts to connect the server.


The URL is what's tripping you up here. Is there a reason you specifically
want to provide an absolute URL? At the moment `make-channel-socket!` just
takes a path (like /chsk). The host and port, etc. will all be determined
for you automatically. /chsk is a reasonable choice btw - it's not
user-facing so doesn't need to be particularly meaningful to anyone but you.

Taking a very quick look at the source for the CLJS make-channel-socket!,
 it seems that it tries to resolve the url using the CLJS chsk-url function
 which, in turn, uses encore/get-window-location.


That's correct. It just grabs the host and protocol of whatever page is
serving the JavaScript. HTTPS protocols will be converted to WSS,
everything else goes to WS. You should be fine there, I'd think.

 (put! ch-chsk From client!)

Note that you'll never be putting to the `ch-chsk` yourself, it's for
receiving only. To send events you'll use the `chsk-send!` fn (the API is
described at https://github.com/ptaoussanis/sente#now-what).

I also updated the repo a couple days ago to include a working example
project that you could pull into LightTable to hack on. Otherwise feel free
to open a GitHub issue if you have any other questions - am happy to help.

Cheers :-)

- Peter

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Sente - Clojure(Script) + core.async + WebSockets/Ajax

2014-03-02 Thread Eduard Bondarenko
You are probably hit by CORS, try to open webpage at the same host
http://localhost:6100/, see http://enable-cors.org/index.html
Check Network tab in Chrome dev tools.

Best regards,
Eduard


On Sun, Mar 2, 2014 at 7:16 PM, Mark markaddle...@gmail.com wrote:

 Hi Peter -

 I'm trying to learn Sente using the LightTable browser connected repl.  I
 try to evaluate the following code:
 (let [{:keys [chsk ch-recv send-fn]}
   (sente/make-channel-socket! http://localhost:6100/chsk; ; Note the
 same URL as before
  {})]
   (def chsk   chsk)
   (def ch-chskch-recv)
   (def chsk-send! send-fn))

 (put! ch-chsk From client!)

 From the JS console, I see repeated, failed attempts to connect the
 server.  The server is running and responding to other http requests.

 Taking a very quick look at the source for the CLJS make-channel-socket!,
 it seems that it tries to resolve the url using the CLJS chsk-url function
 which, in turn, uses encore/get-window-location.  Since my browser window
 location is file://..., I think this is going to generate a bad url.  Am I
 reading the source correctly? Is there some way to make a channel socket by
 providing an absolute url?

 On Thursday, February 27, 2014 10:53:08 PM UTC-8, Peter Taoussanis wrote:

 Quick addendum: I've had a few folks ask about various security
 implementations.

 So first up - as I mention in the REAME, I have had to make some changes
 to the codebase for the public release so I wouldn't quite trust anything
 pre-1.0 in production just yet (there's likely at least minor bugs). Having
 said that, the general model has played out well in practice elsewhere.

 A few specifics that have come up:

  * Tools.reader's read-string is used server-side, so arbitrary code
 evaluation isn't an issue.
  * It _is_ possible for the server to receive malformed or hostile
 requests (as it would be via any other protocol). The implementation itself
 doesn't depend on the accuracy of any information provided by the client,
 but the usual security measures will apply server-side for code you write:
 only respond to well-formed requests, ensure users are
 authenticated+authorised where appropriate, etc. Auth stuff is beyond the
 scope of Sente, but it won't do anything to get in your way.
  * Ring session information _is_ made available server-side for all
 requests (including WebSocket requests), so the commonest session-based
 auth methods basically work out-the-box.
  * The client-side user-id *can* be forged, but it isn't used for
 anything that's security sensitive. It's there only as an optimisation to
 disable Ajax long-polling when a user clearly isn't logged in. If someone
 were to fudge the id, the only negative effect would be an the creation of
 an unnecessary long-polling connection that is never used (the server will
 never acknowledge it).
  * HTTPS works seamlessly, even for WebSockets. When the page is served
 over HTTPS, Sente will work over HTTPS.
  * CSRF protection is baked in, but you need to do a few things on your
 end to enable it. A client-side warning will be printed when no CSRF code
 is provided. Recommend checking out the example project for details (it
 includes CSRF protection).

 So tl;dr - there's a bit going on, but nothing that's fundamentally
 different from the usual Ring security model. Auth and CSRF are the
 responsibility of the app as usual, but Sente provides hooks in the
 appropriate places to plug in whatever you're using.

 Will try update the README later today with the info above.

 Hope that helps, happy Friday! :-)

 - Peter

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/5J4L8pbGwGU/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

[ANN] Etsy API library for Clojure

2014-03-02 Thread Daniel Szmulewicz
Hi,

Announcing an early release of a wrapper for the Etsy API in Clojure.

https://github.com/danielsz/etsy-clojure-api

Available from clojars.org. 

Please refer to the README for the details.

Thank you. 

--
Daniel Szmulewicz

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure performance question

2014-03-02 Thread Timothy Baldridge
How are you running these tests? The correct way to benchmark such things
is via a real benchmark framework (such as criterium) then compile your
clojure app to a jar (perhaps via lein uberjar) and finally run it via a
bare java invocation: java -jar my.jar.

Lein for example sometimes uses sub-par JVM settings, trading runtime
performance for startup speed.

Timothy


On Sun, Mar 2, 2014 at 4:59 AM, Luc Prefontaine lprefonta...@softaddicts.ca
 wrote:

 I cannot agree with this...
 Not at 100% at least.

 String manipulations are frequent
 enough to mandate some tuning
 if the need is obvious.

 Looks to me that this is the case here.

 Other core fns went through rewrites
 to improve performance.

 Simplicity has nothing to do with
 internal implementations.

 If someone comes up with a better
 implementation while providing
 the same behaviours as the current
 str fn, then it should make it's way
 maybe in clojure.string.

 fast-strings ? Whatever it may be
 named.

 Luc P.

  Core fns should be simple, unsurprising, and general.
 
  'Improving' str may hurt simplicity, make behavior more surprising and
  unexpected, and less general unless proven otherwise.
 
  On Sat, Mar 1, 2014 at 7:02 PM, bob wee@gmail.com wrote:
 
  
   Good point, Thanks a lot.
  
   Shall we improve the str fn in the core lib? From my point of view, the
   core fns should be performance sensitive.
  
  
  
   On Sunday, March 2, 2014 12:03:21 AM UTC+8, Shantanu Kumar wrote:
  
  
  
   On Saturday, 1 March 2014 15:32:41 UTC+5:30, bob wrote:
  
   Case :
  
   clojure verison:
  
   (time (dotimes [n 1000] (str n another word))) ;; take about
   5000msec
  
   java version
  
   long time = System.nanoTime();
  
   for(int i=0 ; i1000 ;i++){
   String a=i+another word;
   }
 System.out.println(System.nanoTime()-time);
  
  
   The java version take about 500 msecs, I thought it might be caused
 by
   the str implementation which is using string builder, and it might
 not be
   the best choice in the case of no much string to concat, and then I
 replace
   another word with 5 long strings as the parameter, however no
 surprise.
  
   I just wonder what make the difference, or how to find the
 difference.
  
  
   Others have added useful points to this thread. Java string
 concatenation
   internally uses StringBuilder, so if you replace (str n another
 word)
   with the following:
  
   (let [sb (StringBuilder.)]
(.append sb n)
(.append sb another word)
(.toString sb))
  
   ..then the perf improves 1/4 to 1/3. Further, with the following
 tweak:
  
   (let [sb (StringBuilder. 20)]  ; because StringBuilder allocates only
 16
   chars by default on Oracle JRE
(.append sb n)
(.append sb another word)
(.toString sb))
  
   ..the perf improves from 1/3 to less than 1/2. Here we simply avoid
   double allocation in StringBuilder.
  
   Other things I made sure were:
  
   1. I used Criterium to measure
   2. I used `-server` option
   3. Made sure reflection warning was on
  
   Shantanu
  
--
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient with
   your first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/clojure?hl=en
   ---
   You received this message because you are subscribed to the Google
 Groups
   Clojure group.
   To unsubscribe from this group and stop receiving emails from it, send
 an
   email to clojure+unsubscr...@googlegroups.com.
   For more options, visit https://groups.google.com/groups/opt_out.
  
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 --
 Luc Prefontainelprefonta...@softaddicts.ca sent by ibisMail!

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 

Re: [ANN] - purnam 0.4.3 released - Javascript Language Extensions for Clojurescript

2014-03-02 Thread Mark Mandel
Awesome.

Glad to have this complete. I had some pending pull requests I wanted to
drop in.

Mark


On Sun, Mar 2, 2014 at 8:22 AM, zcaudate z...@caudate.me wrote:

 I'm also looking for collaborators as it is getting to a stage where I'm
 having trouble managing it by myself.

  if anybody is interested. Please send me a message

 Chris

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
E: mark.man...@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure performance question

2014-03-02 Thread Shantanu Kumar


On Monday, 3 March 2014 02:18:39 UTC+5:30, tbc++ wrote:

 How are you running these tests? The correct way to benchmark such 
 things is via a real benchmark framework (such as criterium) then compile 
 your clojure app to a jar (perhaps via lein uberjar) and finally run it via 
 a bare java invocation: java -jar my.jar. 

 Lein for example sometimes uses sub-par JVM settings, trading runtime 
 performance for startup speed. 


Relevant bits from my project.clj are below:

  :dependencies [[org.clojure/clojure 1.5.1]
 [criterium 0.4.3]]
  :global-vars {*warn-on-reflection* true
*assert* false
*unchecked-math* true}
  :jvm-opts ^:replace [-server -Xmx1g]

I believe this overrides Lein's default tiered compilation setting. I 
bench'ed both Java and Clojure code using Criterium.

Shantanu



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


clojure lazy-seq caching?

2014-03-02 Thread Andy Smith
Hi,

I understand that lazy-seq caches the computed result as each element is 
read. However, how can is this made to be thread-safe?

Andy

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: use/require/import and quoted form

2014-03-02 Thread Andy Smith
Oh I see, so we are using exactly the right datatype for the purpose... 
thanks :o)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Sente - Clojure(Script) + core.async + WebSockets/Ajax

2014-03-02 Thread Mark
Yep, I was running into the two problems you pointed out:  First, I needed 
to use a relative URL in make-channel-socket! and that necessitated 
delivering my HTML through http-kit rather than the shortcut of reading it 
from the file system using file://...  Once I did that, an assertion nicely 
documented the use of chsk-send! (thanks for that!).  One small thing that 
tripped me up: It seems the event id must be a namespaced keyword.  I 
haven't thoroughly rtfm yet so if that's doc'd, bad on me.  

Thanks for the pointers!

On Sunday, March 2, 2014 11:27:23 AM UTC-8, Peter Taoussanis wrote:

 Hi Mark,

 I'm trying to learn Sente using the LightTable browser connected repl.  


 Ahh, nice. Haven't tried LightTable yet myself, but I'd think it should 
 work okay.

  

 From the JS console, I see repeated, failed attempts to connect the 
 server.


 The URL is what's tripping you up here. Is there a reason you specifically 
 want to provide an absolute URL? At the moment `make-channel-socket!` just 
 takes a path (like /chsk). The host and port, etc. will all be determined 
 for you automatically. /chsk is a reasonable choice btw - it's not 
 user-facing so doesn't need to be particularly meaningful to anyone but you.

 Taking a very quick look at the source for the CLJS make-channel-socket!, 
 it seems that it tries to resolve the url using the CLJS chsk-url function 
 which, in turn, uses encore/get-window-location.


 That's correct. It just grabs the host and protocol of whatever page is 
 serving the JavaScript. HTTPS protocols will be converted to WSS, 
 everything else goes to WS. You should be fine there, I'd think.

  (put! ch-chsk From client!)

 Note that you'll never be putting to the `ch-chsk` yourself, it's for 
 receiving only. To send events you'll use the `chsk-send!` fn (the API is 
 described at https://github.com/ptaoussanis/sente#now-what).

 I also updated the repo a couple days ago to include a working example 
 project that you could pull into LightTable to hack on. Otherwise feel free 
 to open a GitHub issue if you have any other questions - am happy to help.

 Cheers :-)

 - Peter
  

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure lazy-seq caching?

2014-03-02 Thread Stephen C. Gilardi

 I understand that lazy-seq caches the computed result as each element is 
 read. However, how can is this made to be thread-safe?

The caching is done within a synchronized method as each element's value is 
realized.

There is an instance of clojure.lang.LazySeq that manages each seq element's 
value. The value is computed within a call to clojure.lang.LazySeq::sval which 
is synchronized. After the first time it's computed, the value is cached (in 
the sv member) and subsequent calls to sval return the cached value.

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java#L37

http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

--Steve

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] - purnam 0.4.3 released - Javascript Language Extensions for Clojurescript

2014-03-02 Thread Chris Zheng
Looking forward to it!

On 03/03/2014, at 7:49, Mark Mandel mark.man...@gmail.com wrote:

 Awesome. 
 
 Glad to have this complete. I had some pending pull requests I wanted to drop 
 in.
 
 Mark
 
 
 On Sun, Mar 2, 2014 at 8:22 AM, zcaudate z...@caudate.me wrote:
 I'm also looking for collaborators as it is getting to a stage where I'm 
 having trouble managing it by myself.
 
  if anybody is interested. Please send me a message
 
 Chris
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 
 
 -- 
 E: mark.man...@gmail.com
 T: http://www.twitter.com/neurotic
 W: www.compoundtheory.com
 
 2 Devs from Down Under Podcast
 http://www.2ddu.com/
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to a topic in the Google 
 Groups Clojure group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/clojure/vQqvs9cBB78/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure performance question

2014-03-02 Thread Mikera
Some perspectives (as someone who has been tuning this stuff a lot, from a 
core.matrix standpoint in particular)

On Saturday, 1 March 2014 13:02:26 UTC+8, bob wrote:

 Hi,

 Can I ask a newbie question about clojure performance?

 What make clojure performance slow than java?, it seems clojure has the 
 1/4 performance compared to java in general, according to  tests, some 
 cases it might be 1/10. the reasons I can think out are 

 - the byte code is not efficient sometimes

- the byte code might not enjoy the jvm optimization

Sometimes a problem, though Clojure is not too bad at bytecode generation 
and the JIT will do most of the obvious optimisations for you.
 

 - the reflection 

 
This is extremely bad for performance, but luckily it is easy to avoid:
- Always use *warn-on-reflection*
- Eliminate every single reflection warning with type hints
 

 - the immutable data structure

 
This is often a performance *advantage*, especially when you start dealing 
with concurrency and data-driven snapshot.

In the few cases where it is a problem, you can always drop back to using 
mutable Java data structures or arrays - so this isn't ever really an issue.
 

 - the abstract interface design

 
This doesn't actually cost that much. Interfaces on the JVM are extremely 
fast and very well optimised. In many cases, JIT optimisations make them 
just as fast as a static method call.
 


 The abstract interface like seq offers its power, but it is easy to drop 
 in the performance trap.

 
ISeq itself isn't too bad (it's just an interface, as above), but some of 
the implementations are a bit expensive.

Lazy seqs for example are not so fast... and often you don't need the 
laziness. However most clojure.core functions produce lazy seqs by default. 

I wrote an eager-map replacement for map in my clojure-utils library to 
get around this problem

 


 And it seems to me that it is easy to write a slow clojure program, I know 
 the efficiency of code depends on coder, you can write the code faster than 
 java sometimes,but  need to know a lot of deep thing and tricky, and 
 clojure is not the funny clojure any more.


 Thanks


There are also a couple of other general issues that are slightly 
problematic performance issues for Clojure that can make it noticeably 
slower than Java for a lot of typical code:

1) Dynamic var lookup - this is expensive because all var accesses need to 
go via a var dereference. This prevents many JVM optimisations, and if 
affects pretty much every non-inlined function call in regular Clojure 
code.  Fixing this would require eliminating the var-based namespace model 
- something I've been experimenting with in my experimental language Kiss, 
which eliminates vars and uses immutable namespaces. This approach looks 
promising, but is a pretty radical change so not sure if it will ever get 
into Clojure itself.

2) Dynamic dispatch: If you look into the details, a lot of Clojure 
functions have an Object argument and end up doing a serious of instance? 
checks or other methods to achieve dynamic dispatch. This is expensive and 
unnecessary in many cases, since you can often prove that the argument must 
be of a specific type (e.g. java.lang.String). This is fixable, but would 
require smarter type inference in the Clojure compiler itself. Again this 
is something I'm experimenting with in Kiss, it might also be fixed in a 
future Clojure-in-Clojure compiler.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure performance question

2014-03-02 Thread bob
Cool, Kiss.

From my 2 cent, the solid is important to the clojure, and the core team is 
making any change carefully, but looks to me that the `radical` idea is 
important to the community and clojure as well, might that we need a branch 
of clojure to do some `radical` attempt and experiment, it is the clojure's 
incubator. 


On Monday, March 3, 2014 10:06:33 AM UTC+8, Mikera wrote:



 2) Dynamic dispatch: If you look into the details, a lot of Clojure 
 functions have an Object argument and end up doing a serious of instance? 
 checks or other methods to achieve dynamic dispatch. This is expensive and 
 unnecessary in many cases, since you can often prove that the argument must 
 be of a specific type (e.g. java.lang.String). This is fixable, but would 
 require smarter type inference in the Clojure compiler itself. Again this 
 is something I'm experimenting with in Kiss, it might also be fixed in a 
 future Clojure-in-Clojure compiler.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


New Functional Programming Job Opportunities

2014-03-02 Thread Functional Jobs
Here are some functional programming job opportunities that were posted

recently:



functional software developer at OpinionLab

http://functionaljobs.com/jobs/8685-functional-software-developer-at-opinionlab



Cheers,

Sean Murphy

FunctionalJobs.com


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Sente - Clojure(Script) + core.async + WebSockets/Ajax

2014-03-02 Thread Peter Taoussanis


 and that necessitated delivering my HTML through http-kit rather than the 
 shortcut of reading it from the file system using file://...  


Yes, good catch - sorry, forgot to mention that.
 

 Once I did that, an assertion nicely documented the use of chsk-send! 
 (thanks for that!).  One small thing that tripped me up: It seems the event 
 id must be a namespaced keyword.  I haven't thoroughly rtfm yet so if 
 that's doc'd, bad on me.


It's documented but easy to miss - I'll add an extra assertion to print on 
malformed event ids (thanks for the feedback!).

Cheers :-)

  

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.