Parsing and querying binary .fit files in Clojure

2017-04-05 Thread Jan Herich
As an active cyclist, I always wanted to do power-data analysis in my 
favourite language, so I finally put together this little tool: 
https://github.com/janherich/fit-to-edn.
I hope it will be useful for someone else as well, what it does & how to 
use it is pretty well documented in the readme 
(and of 
course code as well).

There are still many things I want to implement there, for example another 
weighted average algorithm (x-power used by golden-cheetah and strava), 
filtering input .fit
files by date and date ranges and also virtual elevation profile for 
accurate Cda estimations by Robert Chung's method 
.

If you have any suggestions or ideas for improvement, just write me here, 
or open a PR.

Cheers
Jan

-- 
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/d/optout.


Re: When to use metadata

2015-01-29 Thread Jan Herich
Solussd is absolutely correct, but maybe even more simplistic (or easier to 
grasp) explanation would be to use metadata if you don't want the 
additional (meta)data to change the equality semantics of the map, for 
example:

(def test-desc1 {:number-of-threads 10})
(def test-desc2 ^{:integration true} {:number-of-threads 10})
(def test-desc3 {:number-of-threads 10 :integration true})

(= test-desc1 test-desc2) ;; returns true
(= test-desc1 test-desc2 test-desc3) ;; returns false, because while the 
first two vars reference equal values, the third one doesn't


Dňa štvrtok, 29. januára 2015 16:10:34 UTC+1 Jonathon McKitrick napísal(-a):

 Is there a rule of thumb or set of use cases when metadata is a more 
 elegant solution than simply adding more entries to a map or record?


-- 
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/d/optout.


Re: Idiomatic clojure on building a sequence

2014-05-21 Thread Jan Herich
Hi Colin,

Have a look at the 'as-' macro, its very helpful in some cases, as:

(- []
 (conj some-element)
 (as- some-seq 
 (if some-condition? (conj some-seq some-element) some-seq)
 (if some-other-condition? (conj some-seq some-other-element) 
some-seq))
 (take some-number-of-elements))

Dňa streda, 21. mája 2014 18:23:06 UTC+2 Colin Yates napísal(-a):

 I often find myself doing the following:

 (let [some-seq []
   some_seq (if some-condition? (conj some-seq some-element) some-seq)
   some_seq (if some-other-condition? (conj some-seq 
 some-other-element) some-seq)
   some_seq etc.])

 In other words building up a sequence which contains the results of 
 predicated elements.  Building up a where clause in SQL for example.

 I experimented with the - and - but that didn't help and just looked 
 messier.

 How do you handle this pretty common use case?

 Thanks!

  


-- 
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/d/optout.


Re: Comparing classes in case statement

2014-02-27 Thread Jan Herich
From official clojure documentation:

The test-constants are not evaluated. They must be compile-time
literals

Dňa štvrtok, 27. februára 2014 14:03:04 UTC+1 Markus Bader napísal(-a):

 Hello,

 if I am not too dumb, it seems that comparing for classes does not work in 
 case statements, like:

 = (class '(1 2 3))
 clojure.lang.PersistentList

 = (case (class '(1 2 3))
 clojure.lang.PersistentList :amazing
 :so-sad)
 :so-sad

 I do not need a workaround - that is already done - and using the List is 
 just for providing a simple example. It originally occurred while comparing 
 Java classes.

 I am just interested if this behavior is intended or a bug.

 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.


Re: Comparing Regular Expression pattens for equality?

2014-02-26 Thread Jan Herich
Clojure re-uses java.util.regex.Pattern objects. This object doesn't 
override equals method, 
so object references are always compared. But you can easily get pattern 
string from compiled
pattern and then compare just them: 

user= (= (.pattern #test) (.pattern #test))
true

Dňa streda, 26. februára 2014 12:55:17 UTC+1 Thomas napísal(-a):

 Hi Everyone,

 I am creating some regular expressions programmatically with re-pattern. 
 In order to avoid creating the same regex pattern again I want to check if 
 it already exists. But comparing regex pattern doesn't seem to be work:

 user= (= #test #test)
 false
 user= (identical? #test #test)
 false

 Not surprised that identical? doesn't work to be honest, but = should 
 have worked IMHO

 Is there a way to do this?

 TIA

 Thomas


-- 
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: Latest web framework for clojure

2014-02-25 Thread Jan Herich
It depends also on your requirements. For example if you want your app to 
work in many 
deployment scenarios (standalone Jetty  or Tomcat, J2EE web containers...) 
and you may 
have to use servlet 3.0 API asynchronous features, nothing beats pedestal 
currently.

The concept of interceptors is little harder to grok then simple ring 
handlers (which are reused
to the greatest possible extent anyway), but they really make sense and 
truly decomplect
execution order, unlike traditional ring wrapping handlers.

The routing systems is also more transparent (data based) then Compojure 
macro routing
and the url generation facility is nice.

Sometimes i hear people say that pedestal is unclojurish and complex, but 
i think they
just don't get the difference between complex and easy. Overall, i think 
that pedestal 
represents core clojure philosophy better then any other clojure server 
side framework.

Dňa streda, 26. februára 2014 2:13:30 UTC+1 Aravindh S napísal(-a):

 Hi All,
I have been reading clojure for sometime now. I am at a point where I 
 want to learn a web framework. I see many options available for clojure 
 where few are built upon others. So if I am to learn one, which framework 
 does the community recommend? 

 Thanks
 Aravindh.S


-- 
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.


Shutting down core.async executors threadpool

2014-02-24 Thread Jan Herich
Hi Folks,

I developed an pedestal application which uses core.async for real-time 
server push.
Everything works fine, except little problem when i run the application as 
the Servlet
in Tomcat (7.0.52).

The problem is, that if i shutdown the tomcat instance with shutdown script 
(default bin/shutdown.sh), it won't quit.

I can see with VisualVM that it is because of the core.async executors 
threadpool 
used to dispatch go blocks which is not properly teared down. 

Any ideas how to solve this ?

Cheers

Jan

-- 
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: Shutting down core.async executors threadpool

2014-02-24 Thread Jan Herich
Thank you much for the hint Jozef, you pointed mi in the right direction.

As you wrote, all core.async thread are daemon threads, but i was using 
another clojure library (pedestal) which uses executors threadpool for SSE
heartbeat functionality, and this was indeed the problem.

I already submitted an pull request to library maintainers: 

https://github.com/pedestal/pedestal/pull/250

Dňa pondelok, 24. februára 2014 19:18:42 UTC+1 Jozef Wagner napísal(-a):

 All threads in default core.async threadpool should be daemon, so they 
 should not block when JVM is about to exit. Maybe it is a tomcat issue.


 On Mon, Feb 24, 2014 at 7:06 PM, Jan Herich jan.h...@gmail.comjavascript:
  wrote:

 Hi Folks,

 I developed an pedestal application which uses core.async for real-time 
 server push.
 Everything works fine, except little problem when i run the application 
 as the Servlet
 in Tomcat (7.0.52).

 The problem is, that if i shutdown the tomcat instance with shutdown 
 script 
 (default bin/shutdown.sh), it won't quit.

 I can see with VisualVM that it is because of the core.async executors 
 threadpool 
 used to dispatch go blocks which is not properly teared down. 

 Any ideas how to solve this ?

 Cheers

 Jan

 -- 
 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: (series of swap! on atom) == single swap!

2014-02-16 Thread Jan Herich
I'm afraid your understanding of atom swap! operations is not quite correct 
- update function must (or should) be pure as well.
See the 
documentationhttp://clojuredocs.org/clojure_core/clojure.core/swap!for swap!, 
update function could be potentially called multiple times if 
there are more threads of execution
updating one atomic reference - there is simple compare and 
sethttp://clojuredocs.org/clojure_core/clojure.core/compare-and-set!mechanism 
involved, which compares the old value of the atom
(input for the update function) and sets the atom to new value (return 
value from the update function) only value of the atom reference
was not changed in between, if yes the compare and set is retried until ti 
succeeds.

Dňa nedeľa, 16. februára 2014 23:35:24 UTC+1 t x napísal(-a):

 I believe that's the STM approach, which has the advanrtage of: 

   * can synchronize across multiple pieces of data 

 but has the disadvantage of: 

   * work must be pure since it can be retried 

   * possibly less efficient due to possibility of retrying 


 In the example I posted above, I only need to: 

   * modify a single atom 

 and the approach I presented above: 

   * can be impure, since it is guaranteed to only run once 

   * is guaranteed to succeed (without retrys) 

 On Sun, Feb 16, 2014 at 2:25 PM, Ramesh ramesh1...@gmail.comjavascript: 
 wrote: 
  You can use a ref instead of an atom. And use dosync with multiple 
 alter, so 
  everything is safely inside a transaction. 
  
  On Feb 16, 2014 2:04 PM, t x txre...@gmail.com javascript: wrote: 
  
  Hi John, 
  
Your solution is perfectly valid and optimal for the problem I 
  described above. 
  
  
Unfortunately, I forgot to mention an additional constraint: 
 sometimes I 
  do: 
  
  (let [ foo (:some-selector @data-atom) ] 
(swap! data-atom update-in [:other-selector] ... )) 
  
  which the - doesn't quite work on, but my ugly hack above does 
 resolve. 
  
  
The problem being -- I want to update one part of the atom, but it 
  depends on another part of the atom. 
  
I ended up with the following hack: 
  
  (defn tswap! [atm func] 
(swap! atm 
   (fn [old] 
 (let [natm (atom old)] 
   (func natm) 
   @natm 
  
  
  On Sat, Feb 15, 2014 at 4:09 PM, John D. Hume 
  duelin@gmail.comjavascript: 

  wrote: 
   On Sat, Feb 15, 2014 at 6:04 PM, t x txre...@gmail.com javascript: 
 wrote: 
   
   
   (defn what-I-want [] 
 (with-atom some-atom 
   assoc-in ... 
   assoc-in ... 
   update-in ...)) 
   
   
   I often do something like this and don't find it too ugly: 
   (swap! my-atom #(- % 
 (assoc-in [:k] v) 
 (update-in [:k2] inc) 
 ,,,)) 
   
   -- 
   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 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 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 
  

Re: (series of swap! on atom) == single swap!

2014-02-16 Thread Jan Herich
Hi t x,

I think, that lock-free approach an it's semantics is more in line with 
other Clojure reference types such as refs.
It also encourages you to only use pure functions for state transitions, 
among other things, such as significant
performance benefits in comparison with lock based approaches, see for 
example this 
articlehttp://mechanical-sympathy.blogspot.sk/2013/08/lock-based-vs-lock-free-concurrent.html
. 
If you really want to update some reference with function which will also 
perform impure actions such as file I/O,
consider using agents http://clojure.org/agents and 
sendhttp://clojure.github.io/clojure/clojure.core-api.html#clojure.core/sendor
 
send-offhttp://clojure.github.io/clojure/clojure.core-api.html#clojure.core/send-off(the
 latter in case of I/O blocking actions), functions given to send 
and send-off are guaranteed to run only once.

Dňa pondelok, 17. februára 2014 2:36:59 UTC+1 t x napísal(-a):

 Hi Jan, 

   You're right. I'm wrong. 

   I'm grateful you pointed this out -- this would have otherwise been 
 impossible to debug. 

 === 

 To everyone: 

   Why can swap! be retried? This confuses me -- to implement swap!, why 
 can't we 

   * have a lock 

   * ensure that only one swap! is in session at any given time 

   * have the given swap! complete before running the next swap! 


 Thanks! 


 On Sun, Feb 16, 2014 at 3:51 PM, Jan Herich jan.h...@gmail.comjavascript: 
 wrote: 
  I'm afraid your understanding of atom swap! operations is not quite 
 correct 
  - update function must (or should) be pure as well. 
  See the documentation for swap!, update function could be potentially 
 called 
  multiple times if there are more threads of execution 
  updating one atomic reference - there is simple compare and set 
 mechanism 
  involved, which compares the old value of the atom 
  (input for the update function) and sets the atom to new value (return 
 value 
  from the update function) only value of the atom reference 
  was not changed in between, if yes the compare and set is retried until 
 ti 
  succeeds. 
  
  Dňa nedeľa, 16. februára 2014 23:35:24 UTC+1 t x napísal(-a): 
  
  I believe that's the STM approach, which has the advanrtage of: 
  
* can synchronize across multiple pieces of data 
  
  but has the disadvantage of: 
  
* work must be pure since it can be retried 
  
* possibly less efficient due to possibility of retrying 
  
  
  In the example I posted above, I only need to: 
  
* modify a single atom 
  
  and the approach I presented above: 
  
* can be impure, since it is guaranteed to only run once 
  
* is guaranteed to succeed (without retrys) 
  
  On Sun, Feb 16, 2014 at 2:25 PM, Ramesh ramesh1...@gmail.com wrote: 
   You can use a ref instead of an atom. And use dosync with multiple 
   alter, so 
   everything is safely inside a transaction. 
   
   On Feb 16, 2014 2:04 PM, t x txre...@gmail.com wrote: 
   
   Hi John, 
   
 Your solution is perfectly valid and optimal for the problem I 
   described above. 
   
   
 Unfortunately, I forgot to mention an additional constraint: 
   sometimes I 
   do: 
   
   (let [ foo (:some-selector @data-atom) ] 
 (swap! data-atom update-in [:other-selector] ... )) 
   
   which the - doesn't quite work on, but my ugly hack above does 
   resolve. 
   
   
 The problem being -- I want to update one part of the atom, but it 
   depends on another part of the atom. 
   
 I ended up with the following hack: 
   
   (defn tswap! [atm func] 
 (swap! atm 
(fn [old] 
  (let [natm (atom old)] 
(func natm) 
@natm 
   
   
   On Sat, Feb 15, 2014 at 4:09 PM, John D. Hume duelin@gmail.com 

   wrote: 
On Sat, Feb 15, 2014 at 6:04 PM, t x txre...@gmail.com wrote: 


(defn what-I-want [] 
  (with-atom some-atom 
assoc-in ... 
assoc-in ... 
update-in ...)) 


I often do something like this and don't find it too ugly: 
(swap! my-atom #(- % 
  (assoc-in [:k] v) 
  (update-in [:k2] inc) 
  ,,,)) 

-- 
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

Re: Example in Joy of Clojure, 2nd edition (MEAP)

2014-02-15 Thread Jan Herich
Hello Eric,

You can rewrite this functionality with key# and r# instead of ~'key and 
~'r and it would work just as well, 
it's only not necessary to use unique symbols here, because you are not 
using them in the function body
anyway, so there is no danger of accidental var capture. 

To be honest, i would rather use underscore symbols (written as ~'_ inside 
macro definition) to indicate 
that i won't use any of the first two parameters in the function body. 

Dňa sobota, 15. februára 2014 9:32:48 UTC+1 Eric napísal(-a):

 Hi,

 I'm reading the second edition of Joy of Clojure (the MEAP), and there is 
 an example that I don't quite get, and I was hoping someone here could help 
 me. It's in chapter 8, talking about macros. There is an example of a macro 
 called def-watched, which prints a message each time the root binding of a 
 var changes:

 (defmacro def-watched [name  value]
   `(do
 (def ~name ~@value)
 (add-watch (var ~name)
 :re-bind
 (fn [~'key ~'r old# new#]
   (println old#  -  new#)

 I understand almost everything, but I don't see why we have to use ~'keyand 
 ~'r rather than simply key# and r#. As I understand it, the first option (
 ~'var-name) would be useful to capture an external var inside the macro, 
 but I don't see the point of doing it here, especially since ~'key is 
 defined in the parameter list, so that it would anyway hide any external 
 var. Could someone please help me understand this?

 Thank you in advance,

 Eric


-- 
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: Handy clojure function to transform prepared statement queries

2014-02-10 Thread Jan Herich
The problem with libraries you mentioned is that those are fully featured 
DSLs for embedding SQL queries
as clojure macros/function calls in your program. 

However, i like the philosophy of Yesql 
libraryhttps://github.com/krisajenkins/yesql, 
which leverages clojure/java.jdbc library but encourages you 
to keep SQL queries in .sql files for many different reasons (all stated in 
README.md https://github.com/krisajenkins/yesql/blob/master/README.md of 
this library). 

There is a whole class of real-world environments, where this approach is 
preferable to full-power DSLs.
My problem is, that i'm forced to abadon Yesql approach whenever my query 
has IN () clause within and
i have to write the query as a String in clojure program (or use some DSLs, 
but that's what i'm trying to avoid).
If there would be some hook to attach in my proposed behavior to either 
clojure/java.jdbc or Yesql, i would
be able to continue writing all of my queries as plain .sql files.

Of course you can argue that whenever someone needs to do this, it's the 
right time to start using DSLs,
i'm not sure on this, that's why i want to discuss this topic.  

Dňa pondelok, 10. februára 2014 0:16:01 UTC+1 Sean Corfield napísal(-a):

 As maintainer of java.jdbc I'd say this is a more appropriate feature 
 for a DSL library like SQLingvo or HoneySQL (which may already support 
 something like this - I haven't checked). 

 Sean 

 On Sun, Feb 9, 2014 at 12:40 PM, Jan Herich jan.h...@gmail.comjavascript: 
 wrote: 
  Hello folks, 
  
  In the last days, i was working with clojure/java.jdbc and yesql 
 libraries 
  (which are both great piece of work), 
  the experience was overall very positive, but one thing bothered me, 
 that i 
  was unable to use plain prepared 
  statements (and sadly, yesql) when working with IN clauses and 
 collection 
  values as arguments for prepared 
  statements. So i created following helper function to help with 
 generating 
  correct prepared statements: 
  
  (ns db-util 
(:require [clojure.string :as str])) 
  
  (def ^:private placeholders-for (comp (partial str/join ,) #(repeat % 
 '?) 
  count)) 
  
  (defn in-statement 
Takes a prepared SQL statement and variable number of arguments, 
 which 
  may be 
 also collection values. Replace all occurences of IN (?) with spliced 
 out 
  values 
 such as IN (?,?,?) where number of placeholder characters is the same 
 as 
  count 
 of elements in corresponding argument which is assumed to be a 
  collection. 
 In case that collection argument has only one element, IN (?) is 
  transformed 
 into more effective = ? form. Placeholders in query which don't 
  corresponds to 
 collection arguments are unnafected. Returns vector, with first item 
 of 
  the 
 vector as transformed prepared SQL statement and rest as spliced out 
  arguments. 
[statement  args] 
(let [in-placeholders-positions (- (re-seq #\?|IN \(\?\) 
 statement) 
 (map vector (iterate inc 0)) 
 (filter #(= (second %) IN (?))) 
 (map first) 
 (set)) 
  in-placeholders-args (- args 
(map vector (iterate inc 0)) 
(filter #(contains? 
  in-placeholders-positions (first %))) 
(map second)) 
  expanded-statement (reduce (fn [acc arg] 
   (str/replace-first acc #IN \(\?\) 
  (if ( (count 
 arg) 
  1) 
(str IN ( 
  (placeholders-for arg) )) 
= ?))) 
 statement in-placeholders-args) 
  unspliced-args (- args 
  (map #(if (coll? %) (seq %) %)) 
  (flatten))] 
  (into [] (cons expanded-statement unspliced-args 
  
  ;; following holds true 
  (= (in-statement id = ? AND user_id IN (?) AND msg_id IN (?) 1 #{2 3 
 4} 
  #{5}) 
 [id = ? AND user_id IN (?,?,?) AND msg_id = ? 1 2 3 4 5]) 
  
  Now my question is, do you think that something in this flavor would be 
 good 
  addition to clojure/java.jdbc 
  or yesql libraries (the latter one is probably more appropriate for 
  inclusion) ? If so, i will try to refine and 
  generalize my solution, think about how to integrate it and then issue 
 an 
  pull request. 
  
  Cheers Jan 
  
  -- 
  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

Re: Handy clojure function to transform prepared statement queries

2014-02-10 Thread Jan Herich
Thank you for your explanation Kris, i will test this functionality in 
Yesql.

Dňa pondelok, 10. februára 2014 14:40:18 UTC+1 Kris Jenkins napísal(-a):

 Actually, Yesql already supports this, albeit unofficially. Here's an 
 example, but please read the caveat at the end before you use it...

 Define an IN-query with one parameter:

 -- name: find-by-age
 SELECT *
 FROM person
 WHERE age IN (:age)

 Call it, supplying a vector for age:

 (find-by-age db-spec [18 21 35])

 The query will get expanded to

 [SELECT * FROM person WHERE age IN (?,?,?) 18 21 35]

 ...for the underlying jdbc call, and behave as you hope.

 So what's the caveat? I haven't tested it 
 sufficientlyhttps://github.com/krisajenkins/yesql/blob/master/test/yesql/named_parameters_test.clj#L54-56.
  
 And until I do, I'm not going to document it, or make it official. But it's 
 there in v0.3.0, so if you want to field-test it, do let me know your 
 experiences. :-)

 (And, FWIW, I completely agree with Sean. This kind of thing definitely 
 belongs in a layer above clojure.java.jdbc.)

 On Monday, 10 February 2014 10:41:55 UTC, Jan Herich wrote:

 The problem with libraries you mentioned is that those are fully 
 featured DSLs for embedding SQL queries
 as clojure macros/function calls in your program. 

 However, i like the philosophy of Yesql 
 libraryhttps://github.com/krisajenkins/yesql, 
 which leverages clojure/java.jdbc library but encourages you 
 to keep SQL queries in .sql files for many different reasons (all stated 
 in README.mdhttps://github.com/krisajenkins/yesql/blob/master/README.mdof 
 this library). 

 There is a whole class of real-world environments, where this approach is 
 preferable to full-power DSLs.
 My problem is, that i'm forced to abadon Yesql approach whenever my query 
 has IN () clause within and
 i have to write the query as a String in clojure program (or use some 
 DSLs, but that's what i'm trying to avoid).
 If there would be some hook to attach in my proposed behavior to either 
 clojure/java.jdbc or Yesql, i would
 be able to continue writing all of my queries as plain .sql files.

 Of course you can argue that whenever someone needs to do this, it's the 
 right time to start using DSLs,
 i'm not sure on this, that's why i want to discuss this topic.  

 Dňa pondelok, 10. februára 2014 0:16:01 UTC+1 Sean Corfield napísal(-a):

 As maintainer of java.jdbc I'd say this is a more appropriate feature 
 for a DSL library like SQLingvo or HoneySQL (which may already support 
 something like this - I haven't checked). 

 Sean 

 On Sun, Feb 9, 2014 at 12:40 PM, Jan Herich jan.h...@gmail.com wrote: 
  Hello folks, 
  
  In the last days, i was working with clojure/java.jdbc and yesql 
 libraries 
  (which are both great piece of work), 
  the experience was overall very positive, but one thing bothered me, 
 that i 
  was unable to use plain prepared 
  statements (and sadly, yesql) when working with IN clauses and 
 collection 
  values as arguments for prepared 
  statements. So i created following helper function to help with 
 generating 
  correct prepared statements: 
  
  (ns db-util 
(:require [clojure.string :as str])) 
  
  (def ^:private placeholders-for (comp (partial str/join ,) #(repeat 
 % '?) 
  count)) 
  
  (defn in-statement 
Takes a prepared SQL statement and variable number of arguments, 
 which 
  may be 
 also collection values. Replace all occurences of IN (?) with 
 spliced out 
  values 
 such as IN (?,?,?) where number of placeholder characters is the 
 same as 
  count 
 of elements in corresponding argument which is assumed to be a 
  collection. 
 In case that collection argument has only one element, IN (?) is 
  transformed 
 into more effective = ? form. Placeholders in query which don't 
  corresponds to 
 collection arguments are unnafected. Returns vector, with first 
 item of 
  the 
 vector as transformed prepared SQL statement and rest as spliced 
 out 
  arguments. 
[statement  args] 
(let [in-placeholders-positions (- (re-seq #\?|IN \(\?\) 
 statement) 
 (map vector (iterate inc 0)) 
 (filter #(= (second %) IN 
 (?))) 
 (map first) 
 (set)) 
  in-placeholders-args (- args 
(map vector (iterate inc 0)) 
(filter #(contains? 
  in-placeholders-positions (first %))) 
(map second)) 
  expanded-statement (reduce (fn [acc arg] 
   (str/replace-first acc #IN 
 \(\?\) 
  (if ( (count 
 arg) 
  1) 
(str IN ( 
  (placeholders-for arg

Handy clojure function to transform prepared statement queries

2014-02-09 Thread Jan Herich
Hello folks,

In the last days, i was working with clojure/java.jdbc and yesql libraries 
(which are both great piece of work), 
the experience was overall very positive, but one thing bothered me, that i 
was unable to use plain prepared 
statements (and sadly, yesql) when working with IN clauses and collection 
values as arguments for prepared
statements. So i created following helper function to help with generating 
correct prepared statements:

(ns db-util
  (:require [clojure.string :as str]))
 
(def ^:private placeholders-for (comp (partial str/join ,) #(repeat % '?) 
count))
 
(defn in-statement
  Takes a prepared SQL statement and variable number of arguments, which may be
   also collection values. Replace all occurences of IN (?) with spliced out 
values
   such as IN (?,?,?) where number of placeholder characters is the same as 
count
   of elements in corresponding argument which is assumed to be a collection.
   In case that collection argument has only one element, IN (?) is transformed
   into more effective = ? form. Placeholders in query which don't corresponds 
to
   collection arguments are unnafected. Returns vector, with first item of the
   vector as transformed prepared SQL statement and rest as spliced out 
arguments.
  [statement  args]
  (let [in-placeholders-positions (- (re-seq #\?|IN \(\?\) statement)
   (map vector (iterate inc 0))
   (filter #(= (second %) IN (?)))
   (map first)
   (set))
in-placeholders-args (- args
  (map vector (iterate inc 0))
  (filter #(contains? in-placeholders-positions 
(first %)))
  (map second))
expanded-statement (reduce (fn [acc arg]
 (str/replace-first acc #IN \(\?\)
(if ( (count arg) 1)
  (str IN ( 
(placeholders-for arg) ))
  = ?)))
   statement in-placeholders-args)
unspliced-args (- args
(map #(if (coll? %) (seq %) %))
(flatten))]
(into [] (cons expanded-statement unspliced-args
 
;; following holds true
(= (in-statement id = ? AND user_id IN (?) AND msg_id IN (?) 1 #{2 3 4} #{5})
   [id = ? AND user_id IN (?,?,?) AND msg_id = ? 1 2 3 4 5])

Now my question is, do you think that something in this flavor would be good 
addition to clojure/java.jdbc
or yesql libraries (the latter one is probably more appropriate for inclusion) 
? If so, i will try to refine and 
generalize my solution, think about how to integrate it and then issue an pull 
request.

Cheers Jan  

-- 
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: Idiomatic way to construct potentially time bound target channel in core.async

2014-02-03 Thread Jan Herich
Ok, so i'm thinking about such one-shot detachable input pipe channels...

(ns async-util.input-pipe
  (:require [clojure.core.async.impl.protocols :as impl]
[clojure.core.async :refer [! close! go-loop]]))
 
(defprotocol InputPipe
  (detach* [p]))
 
(defn input-pipe
  Creates and return input pipe of supplied channel with attached input 
channel.
  [ch ch-i]
  (let [i (atom ch-i)
p (reify
impl/Channel
(close! [_] (impl/close! ch))
(closed? [_] (impl/closed? ch))
 
impl/ReadPort
(take! [_ fn1] (impl/take! ch fn1))
 
impl/WritePort
(put! [_ val fn1] (impl/put! ch val fn1))
 
InputPipe
(detach* [_]  (if (impl/closed? ch)
false
(do (reset! i nil) true]
(go-loop [val (! @i)]
  (if-let [i-c @i]
(if (nil? val)
  (close! p)
  (recur (! i-c)))
(reset! i nil)))
p))
 
(defn detach-input
  Detaches input from input-pipe channel, returns false
   if input-pipe channel is closed, true otherwise
  [p]
  (detach* p))


Dňa piatok, 31. januára 2014 19:18:37 UTC+1 Jan Herich napísal(-a):

 Hello Folks,

 I need to construct core.async channel with following semantics:

 1. When the channel is created, timeout is attached to channel
 2. After timeout passes out, channel is closed
 3. It's possible to detach timeout from the channel before it passes out

 Now i implemented it with something like this:

 (defn create-cancel-channel
   [channel-to-notify timeout-ms]
 (let [cancel-channel (async/chan)
   timeout-channel (async/timeout timeout-ms)]
   (async/go
 (let [[_ c] (async/alts! [cancel-channel timeout-channel])]
   (when (= c timeout-channel)
 (async/close! cancel-channel)
 (async/close! channel-to-notify
   cancel-channel))
  
 ;; transport channel
 (def transport-channel (async/chan))
  
 ;; cancel-channel
 (def cancel-channel (create-cancel-channel transport-channel 2000))
  
 ;; to cancel the transport channel timeout, just close the cancel-channel
 (async/close! cancel-channel)


 But i'm rather unsatisfied with this solution because it seems little bit 
 clunky and what's worse, 
 i need to explicitly keep track of those cancel channels. 
 Obviously core.async pipe would greatly simplify this, but it seems, that 
 there's no way to disconnect
 piped channels. Maybe mult/tap/untap, even if i won't use broadcasting 
 semantic of those constructs.
 Any other ideas ?  



-- 
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: Idiomatic way to construct potentially time bound target channel in core.async

2014-02-02 Thread Jan Herich
If anyone is interested, that's roughly what i'm currently thinking about...

(ns async-util.input-pipe
  (:require [clojure.core.async.impl.protocols :as impl]
[clojure.core.async :refer [! close! go-loop]]))
 
(defprotocol InputPipe
  (attach* [p ch])
  (detach* [p]))
 
(defn input-pipe
  Creates and return input pipe of supplied channel.
  [ch]
  (let [i (atom nil)
p (reify
impl/Channel
(close! [_] (impl/close! ch))
(closed? [_] (impl/closed? ch))
 
impl/ReadPort
(take! [_ fn1] (impl/take! ch fn1))
 
impl/WritePort
(put! [_ val fn1] (impl/put! ch val fn1))
 
InputPipe
(attach* [_ ch-i] (if (impl/closed? ch)
false
(do (reset! i ch-i) true)))
(detach* [_]  (if (impl/closed? ch)
false
(do (reset! i nil) true]
(go-loop []
  (when-let [i-v @i]
(let [val (! i-v)]
  (if (nil? val)
(close! p)
(recur)
p))
 
(defn attach-input
  Attaches channel to input-pipe channel, returns false
   if input-pipe channel is closed, true otherwise.
  [p ch]
  (attach* p ch))
 
(defn detach-input
  Detaches input from input-pipe channel, returns false
   if input-pipe channel is closed, true otherwise
  (detach* p))


Dňa piatok, 31. januára 2014 19:18:37 UTC+1 Jan Herich napísal(-a):

 Hello Folks,

 I need to construct core.async channel with following semantics:

 1. When the channel is created, timeout is attached to channel
 2. After timeout passes out, channel is closed
 3. It's possible to detach timeout from the channel before it passes out

 Now i implemented it with something like this:

 (defn create-cancel-channel
   [channel-to-notify timeout-ms]
 (let [cancel-channel (async/chan)
   timeout-channel (async/timeout timeout-ms)]
   (async/go
 (let [[_ c] (async/alts! [cancel-channel timeout-channel])]
   (when (= c timeout-channel)
 (async/close! cancel-channel)
 (async/close! channel-to-notify
   cancel-channel))
  
 ;; transport channel
 (def transport-channel (async/chan))
  
 ;; cancel-channel
 (def cancel-channel (create-cancel-channel transport-channel 2000))
  
 ;; to cancel the transport channel timeout, just close the cancel-channel
 (async/close! cancel-channel)


 But i'm rather unsatisfied with this solution because it seems little bit 
 clunky and what's worse, 
 i need to explicitly keep track of those cancel channels. 
 Obviously core.async pipe would greatly simplify this, but it seems, that 
 there's no way to disconnect
 piped channels. Maybe mult/tap/untap, even if i won't use broadcasting 
 semantic of those constructs.
 Any other ideas ?  



-- 
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.


Idiomatic way to construct potentially time bound target channel in core.async

2014-01-31 Thread Jan Herich
Hello Folks,

I need to construct core.async channel with following semantics:

1. When the channel is created, timeout is attached to channel
2. After timeout passes out, channel is closed
3. It's possible to detach timeout from the channel before it passes out

Now i implemented it with something like this:

(defn create-cancel-channel
  [channel-to-notify timeout-ms]
(let [cancel-channel (async/chan)
  timeout-channel (async/timeout timeout-ms)]
  (async/go
(let [[_ c] (async/alts! [cancel-channel timeout-channel])]
  (when (= c timeout-channel)
(async/close! cancel-channel)
(async/close! channel-to-notify
  cancel-channel))
 
;; transport channel
(def transport-channel (async/chan))
 
;; cancel-channel
(def cancel-channel (create-cancel-channel transport-channel 2000))
 
;; to cancel the transport channel timeout, just close the cancel-channel
(async/close! cancel-channel)


But i'm rather unsatisfied with this solution because it seems little bit 
clunky and what's worse, 
i need to explicitly keep track of those cancel channels. 
Obviously core.async pipe would greatly simplify this, but it seems, that 
there's no way to disconnect
piped channels. Maybe mult/tap/untap, even if i won't use broadcasting 
semantic of those constructs.
Any other ideas ?  

-- 
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: side-effect only function with map-like syntax (again)

2014-01-27 Thread Jan Herich
How about doseq http://clojuredocs.org/clojure_core/clojure.core/doseq ? 

Dňa utorok, 28. januára 2014 5:28:04 UTC+1 Mars0i napísal(-a):

 Back in 2007 (
 https://groups.google.com/forum/#!searchin/clojure/mapc/clojure/x0PDu_D6mP0/3A7CZe-ZDWAJ),
  
 Henk Boom raised the possibility of including in Clojure a function with 
 syntax like map, but semantics more like Common Lisp's mapc (or Scheme's 
 for-each, I believe).  It works just like Clojure map, but applies the 
 function to items in a sequence (sequences) only for side-effects.  A 
 sequence of results isn't generated, so there's no need for laziness.  
 There was discussion, and at one point Rich Hickey seemed to say that he 
 had added this kind of function, under the name 'scan'.  It looks like scan 
 was subsequently renamed to 'dorun' (http://clojure.org/old_news), but 
 dorun doesn't do what mapc does.  As far as I can tell, there is no such 
 function at present in Clojure.  Is that correct?

 There are other ways to get the same functionality, and it's easy to 
 define a simple version of mapc (or whatever it should be called).  
 However, I like the map syntax, even for side-effects, and don't want to 
 reinvent the wheel.  Even for small sequences, in which producing a 
 sequence as output isn't costly, using mapc tells readers of your code that 
 you're iterating over the list solely for side-effects.

 (defn mapc [f coll] (doseq [x coll] (f x)))

 For example, creating a mutable vector using core.matrix:

 = (def a (zero-vector :ndarray 5))
 #'popco.core.popco/a
 = a
 #NDArray [0.0 0.0 0.0 0.0 0.0]
 = (mapc #(mset! a % -1) [0 2 4])
 nil
 = a
 #NDArray [-1 0.0 -1 0.0 -1]



-- 
-- 
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: Read file contents as map

2014-01-26 Thread Jan Herich
And if you are not sure about that, just use edn-only reader:

(require '[clojure.tools.reader.edn :as edn])

(edn/read-string (slurp file))

Dňa nedeľa, 26. januára 2014 17:12:32 UTC+1 mynomoto napísal(-a):

 If you are sure that the file doesn't contain malicious code you can use:

 (read-string (slurp file))

 On Sunday, January 26, 2014 11:24:30 AM UTC-2, Paul Smith wrote:

 Hi,

 I have a config file that contains a Clojure map. If I slurp that file it 
 obviously returns a string. 

 Is it possible to return that read file as a map (its original data 
 structure) and not a string?

 Thanks

 Paul



-- 
-- 
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: core.async count in a channel

2014-01-21 Thread Jan Herich
Hello Paul,

Why not just adjust the number of workers based on actual workload instead 
of monitoring the source channel for average depth ?

Have a look at this 
codehttps://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj#L254-287from
 clojure-conj presentation about core.async, it's just a simple 
thread-pool service, where you can
specify source-channel, maximal number of threads (workers), function to be 
performed by each worker and timeout. Timeout 
means, for how long each thread will be waiting if there is no data on 
input before it will shut-down. 

The service starts with minimal amount of threads able to handle the 
workload and then progressively scales up to max specified
number of threads if there are no free threads able to take items from 
the source channel. 

Maybe i misunderstood your description of the problem, but for me, it seems 
like a perfect fit.

Jan

Dňa utorok, 21. januára 2014 17:56:56 UTC+1 Paul Viola napísal(-a):

 I think this is all well and good for a particular use of channel.

 So perhaps I am misusing channels??  

 To repeat: in one case I have workers pulling from a channel of *real 
 work*. For various reasons this channel might get filled rather deeply. 
 In this case I would want to add additional workers or get a bigger 
 machine. I was wondering if monitoring the channel for things like average 
 depth (or 99 percentile) would give me the information I needed.

 I could of course just skip the channel business, and use a java queue 
 is a fine proposal.  

 But since the producers of this work are truly asynchronous (attached to 
 the real world) I thought it best to keep the channel methodology.






 On Tue, Jan 21, 2014 at 5:11 AM, Aaron France 
 aaron.l...@gmail.comjavascript:
  wrote:

 On 21/01/14 14:09, Moritz Ulrich wrote:

 On Tue, Jan 21, 2014 at 9:43 AM, Aaron France 
 aaron.l...@gmail.comjavascript: 
 wrote:

 Since channels yield nil when they are devoid of items, surely this is 
 enough to know when the channel is empty?

 That's not correct. Take-Operations block on empty channels. They
 yield nil when they're closed. You could add a timeout to the take
 operation to see if no item arrived in a specific time.

  Much appreciated for the clarification. It's the same in Go.

 I can imagine this pattern (take on a possibly closed channel being 
 useful) being useful but I'm not convinced knowing the count of channel is 
 a safe thing to know/care about.

 My $0.02, perhaps Clojure does this differently.


 -- 
 -- 
 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 a topic in 
 the Google Groups Clojure group.
 To unsubscribe from this topic, visit https://groups.google.com/d/
 topic/clojure/zD2jl-bIFXI/unsubscribe.
 To unsubscribe from this group and all its topics, 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.


Servlet adapter for ring handlers with support for asynchronous processing

2014-01-18 Thread Jan Herich
Hi Folks,

Is someone aware of servlet adapter (other then pedestal-service) for ring 
based handlers with support for 
asynchronous processing as specified in Servlet 3.0+ api ?

Given that ring core was already refactored to support such solutions 
(middleware had been split into wrapping 
and request modifying functions) it should be not so hard to combine it 
with core.async go macros to assemble 
handler chain which supporting async processing and write an adapter to 
connect it with Servler 3.0+ API -
HttpServletRequest.startAsync(), AsyncContext.complete() and so on... 

If you assembled something similar yourself, or you now about such project 
(even in development, immature, alpha),
please let me know, thank you very much.

Jan

-- 
-- 
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: Servlet adapter for ring handlers with support for asynchronous processing

2014-01-18 Thread Jan Herich
Hello Shantanu,

Thank you for this hint, i will definitely look at your lein-servlet 
project. 
In the meantime, i'm taking inspiration from prototype of pedestal 
core.async based interceptor 
chainhttps://github.com/pedestal/pedestal-service-channels/blob/master/src/channels/core.clj,
 
looks very interesting.

Jan

Dňa sobota, 18. januára 2014 20:32:19 UTC+1 Shantanu Kumar napísal(-a):

 Hi Jan,

 This not directly related, but i thought it might be useful in some way. 
 In case you do the java interop stuff on your own to implement the servlet 
 3.0 methods, you might want to use lein-servlet to run the servlet using 
 Jetty 9 maybe.

 https://github.com/kumarshantanu/lein-servlet

 Shantanu

 On Saturday, 18 January 2014 16:01:02 UTC+5:30, Jan Herich wrote:

 Hi Folks,

 Is someone aware of servlet adapter (other then pedestal-service) for 
 ring based handlers with support for 
 asynchronous processing as specified in Servlet 3.0+ api ?

 Given that ring core was already refactored to support such solutions 
 (middleware had been split into wrapping 
 and request modifying functions) it should be not so hard to combine it 
 with core.async go macros to assemble 
 handler chain which supporting async processing and write an adapter to 
 connect it with Servler 3.0+ API -
 HttpServletRequest.startAsync(), AsyncContext.complete() and so on... 

 If you assembled something similar yourself, or you now about such 
 project (even in development, immature, alpha),
 please let me know, thank you very much.

 Jan



-- 
-- 
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: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Another way of doing that:

(def data {:b--name B, :a--id 1, :b--id 2, :a--name A})
 
(defn transform [data delimiter]
  (reduce (fn [acc [k v]]
(let [[f-k s-k] (- k (name) (str/split delimiter))]
  (assoc-in acc [(keyword f-k) (keyword s-k)] v))) {} s))
 
(transform data #--) ;; {:a {:name A, :id 1}, :b {:id 2, :name B}}


Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James Conroy-Finn napísal(-a):

 Hello all,

 I've found myself stuck trying to move matching keys in a hash into a 
 nested hash.

 For example,:

 {:a--id 1 :a--name A :b--id 2 :b--name B} ;= {:a {:id 1 :name A} :b 
 {:id 2 :name B}}

 I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and 
 using `apply`. I honestly feel like I'm missing something really obvious, 
 like something with group-by.

 Any tips would be greatly appreciated. I'll keep hammering away.


-- 
-- 
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: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
My solution would work only for fixed 2 level deep maps, but it would be 
not so hard to modify it that it will be much more generic :)

Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a):

 Hello all,

 I've found myself stuck trying to move matching keys in a hash into a 
 nested hash.

 For example,:

 {:a--id 1 :a--name A :b--id 2 :b--name B} ;= {:a {:id 1 :name A} :b 
 {:id 2 :name B}}

 I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and 
 using `apply`. I honestly feel like I'm missing something really obvious, 
 like something with group-by.

 Any tips would be greatly appreciated. I'll keep hammering away.


-- 
-- 
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: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Here we go, more generic solution:

(defn transform [data delimiter]
  (reduce (fn [acc [k v]]
(let [key-strs (- k (name) (str/split delimiter))]
  (assoc-in acc (mapv keyword key-strs) v))) {} s))


Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a):

 Hello all,

 I've found myself stuck trying to move matching keys in a hash into a 
 nested hash.

 For example,:

 {:a--id 1 :a--name A :b--id 2 :b--name B} ;= {:a {:id 1 :name A} :b 
 {:id 2 :name B}}

 I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and 
 using `apply`. I honestly feel like I'm missing something really obvious, 
 like something with group-by.

 Any tips would be greatly appreciated. I'll keep hammering away.


-- 
-- 
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: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Oh, yes, my mistake, it should be data instead of s

Dňa štvrtok, 16. januára 2014 15:56:18 UTC+1 James napísal(-a):

 Thank you for sharing.

 I think the final `s` needs to be `data`, right?

 On 16 Jan 2014, at 14:53, Jan Herich jan.h...@gmail.com javascript: 
 wrote:

 Here we go, more generic solution:

 (defn transform [data delimiter]
   (reduce (fn [acc [k v]]
 (let [key-strs (- k (name) (str/split delimiter))]
   (assoc-in acc (mapv keyword key-strs) v))) {} s))


 Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a):

 Hello all,

 I've found myself stuck trying to move matching keys in a hash into a 
 nested hash.

 For example,:

 {:a--id 1 :a--name A :b--id 2 :b--name B} ;= {:a {:id 1 :name A} 
 :b {:id 2 :name B}}

 I've tried `clojure.walk`, I've tried building the args to `assoc-in`, 
 and using `apply`. I honestly feel like I'm missing something really 
 obvious, like something with group-by.

 Any tips would be greatly appreciated. I'll keep hammering away.


 -- 
 -- 
 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 javascript:
 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 a topic in the 
 Google Groups Clojure group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/clojure/vvs5uAWYrBE/unsubscribe.
 To unsubscribe from this group and all its topics, 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: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
I have been using Clojure for something more then 2 years, something more 
then 1 year intensive... 
But i think those feelings of frustration are absolutely OK, when i started 
with Clojure for the very first
time, i was so frustrated (years of OOP mind-bending...) that i gave up for 
some time and only later
i collected my courage and approached Clojure again. Determination and 
patience is very important.

Dňa štvrtok, 16. januára 2014 15:54:47 UTC+1 James napísal(-a):

 Wow, I feel like a clumsy fool bashing parens together.

 Have you been using Clojure for a long time Jan? I ask because I often 
 don't know where to begin when approaching a problem with Clojure, and it 
 can be quite frustrating.

 On Thursday, January 16, 2014 2:45:48 PM UTC, Jan Herich wrote:

 Another way of doing that:

 (def data {:b--name B, :a--id 1, :b--id 2, :a--name A})
  
 (defn transform [data delimiter]
   (reduce (fn [acc [k v]]
 (let [[f-k s-k] (- k (name) (str/split delimiter))]
   (assoc-in acc [(keyword f-k) (keyword s-k)] v))) {} s))
  
 (transform data #--) ;; {:a {:name A, :id 1}, :b {:id 2, :name B}}


 Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James Conroy-Finn 
 napísal(-a):

 Hello all,

 I've found myself stuck trying to move matching keys in a hash into a 
 nested hash.

 For example,:

 {:a--id 1 :a--name A :b--id 2 :b--name B} ;= {:a {:id 1 :name A} 
 :b {:id 2 :name B}}

 I've tried `clojure.walk`, I've tried building the args to `assoc-in`, 
 and using `apply`. I honestly feel like I'm missing something really 
 obvious, like something with group-by.

 Any tips would be greatly appreciated. I'll keep hammering away.



-- 
-- 
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] incise 0.1.0 - An extensible static site generator

2014-01-14 Thread Jan Herich
Hello Ryan,

Thank you for the project, i was always missing a good static site 
generator written in clojure ! 
You took some interesting design decisions with extensibility. I'm 
currently working on the 
similar project https://github.com/janherich/gutenberg, even if my design 
is very different, because my needs are different - i want to 
have templates in pure html and be able to declaratively specify specific 
areas, because of that
my project is based on enlive html library.


Dňa utorok, 14. januára 2014 8:35:33 UTC+1 Ryan McGowan napísal(-a):

 Hi all!

 After consuming quite a bit of my spare time for the past several months, 
 I have finally released version 0.1.0 https://clojars.org/incise of 
 incise. It is a static site generator written in Clojure (of course). I 
 like it quite a bit and I think others might benefit from it too.  I am 
 very open to contributions, suggestions or criticisms (just open an 
 issue)https://github.com/RyanMcG/incise/issues
 .

 Necessary links:

- https://clojars.org/incise
- http://www.ryanmcg.com/incise/ - README generated into website using 
itself (it's called being meta).
- https://github.com/RyanMcG/incise
- https://github.com/RyanMcG/lein-incise - Yes there is a plugin
- 
http://www.ryanmcg.com/2014/1/13/static-website-generation-with-incise/ - 
Very short post about it. Basically points to the README and makes the 
disclaimer that it's not a big deal.
- https://github.com/RyanMcG/incise-example-project - super simple 
example project
- http://www.ryanmcg.com/incise-example-project/ - and its generated 
output

 Thanks,

 Ryan McGowan


-- 
-- 
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: A question about lazy seq with io

2014-01-13 Thread Jan Herich
As Mauricio already mentioned, map is not meant to be used for 
side-effects, if you want to need to evaluate a sequence for side-effects, 
use doseq http://clojuredocs.org/clojure_core/clojure.core/doseq instead.
Regarding your first question about explicit loop-recur, i think it's 
reasonable way to write the functionality you want to achieve, even if the 
for macro is maybe
little more idiomatic and shorter/more concise, here is the comparison:

(def url-sequence (map #(str http://www.mysite.com/list.php?pageID=; %) 
(range)))
 
(def download
  (loop [urls url-sequence lst []]
(let [u (first urls)
  r (rest urls)
  resp (client/get u)
  next (re-find #(s?)title=\next page\Next gt;gt; (:body resp))
  segments ((html2data (:body resp)) :segment)
  data (map segment2data segments)]
  (if next 
(recur r (conj lst data))
(conj lst data)
 
(def download
  (- (for [url url-sequence
 :let [body (:body (client/get url))
   next-pages (re-find #(s?)title=\next page\Next gt;gt; 
body)]
 :while next-pages]
 (map segment2data (- body (html2data) :segment
   (into []))

Also note that i didn't use local binding named next, but instead i named it 
next-pages, because next
local name could lead to surprise if you forget that you aliased something to 
next and try to use clojure
core next function :)


Dňa pondelok, 13. januára 2014 15:49:50 UTC+1 Kashyap CK napísal(-a):

 Hi,
 I've been dabbling with Clojure for a bit and I am really loving it!!!

 I am trying to write a clojure program to download a bunch of URLs and I 
 was wondering what is the right way to do it - 
 My current implementation is as follows

 (def url-sequence (map #(str http://www.mysite.com/list.php?pageID=; %) 
 (range)))

 (def download
   (loop [urls url-sequence lst []]
 (let
 [
  u (first urls)
  r (rest urls)
  resp (client/get u)
  next (re-find #(s?)title=\next page\Next gt;gt; (:body 
 resp))
  segments ((html2data (:body resp)) :segment)
  data (map segment2data segments)
  ]
   (if next 
 (recur r (conj lst data))
 (conj lst data)

 I was wondering if I could replace the loop thingy with a map - that is 
 when I experimented with a simple piece of code and found something that 
 was not intuitive.
 I'd really appreciate it if someone could tell me what's going on when I 
 do the following -

 user (defn xx [] (map println [1 2 3 4 5 6]))
 #'user/xx
 user (take 2 (xx))
 (1
 2
 3
 4
 5
 6
 nil nil)
 user 

 Regards,
 Kashyap


-- 
-- 
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: Adding query customization to Ring-based REST APIs

2014-01-12 Thread Jan Herich
Hello Alexander,

I did some work in this area some time ago, and the result was service-hub 
library https://github.com/ITEdge/service-hub - created to simplify basic 
CRUD services. 
It's designed to allow more then one type of data-store, currently it 
supports SQL databases (i use my own fork of korma here), 
simple in-memory data-stores and datomic. 
I built it around a set of handler protocols which define what basic and 
more advanced data-store implementations can do, 
you can see those 
herehttps://github.com/ITEdge/service-hub/blob/master/core/src/itedge/service_hub/core/handlers.clj
.
Furthermore, the library tries to also simplify validations, authorizations 
and wrapping those ready-to-be-exposed-to-outer-world
services behind another set of services protocols, see 
herehttps://github.com/ITEdge/service-hub/blob/master/core/src/itedge/service_hub/core/services.clj
.
You can then simply use library web layer to automatically expose those 
instances over web via ring  compojure libraries.
Regarding translating requests maps to data-structures for data-store 
implementations, see for example korma util 
namespacehttps://github.com/ITEdge/service-hub/blob/master/persistence-korma/src/itedge/service_hub/persistence_korma/util.clj
or datomic util 
namespacehttps://github.com/ITEdge/service-hub/blob/master/persistence-datomic/src/itedge/service_hub/persistence_datomic/util.clj
.
There are also some examples of such CRUD based web-services in project 
service-hub-examples https://github.com/ITEdge/service-hub-examples.

I hope it will help you, or at least provides some clues

Dňa pondelok, 13. januára 2014 3:25:40 UTC+1 Alexandr Kurilin napísal(-a):

 I'm investigating adding query options to my Ring app's GET requests for 
 the more boring CRUD routes.

 I'd like to allow the caller to specify a set of SQL-level query 
 customizations such as sorting, paging, counting, distinct ons, limits, 
 some basic constraints etc. across all of my resources, ideally in such a 
 way that I only have to write this once and it will magically just work 
 across the board.

 First of all, there's the hard question of elegantly designing the API 
 itself and how a caller will be able to specify query details. I have some 
 experience with how Parse.com does this with their JSON requests (they 
 pretty much allow you to specify the whole query in there), but I've heard 
 Stack Overflow's and Elastic Search's APIs mentioned as good examples as 
 well. Any other ones you'd recommend?

 Second, there's the whole business of translating those maps into 
 requests. As far as I can tell, Korma is the right fit here, but I might be 
 also missing out on another good SQL-generation library that I should know 
 of, something I might integrate directly with clojure.jdbc. This doesn't 
 sound like an unsolved problem.

 Folks, I could use words of wisdom on the subject. Have you done this kind 
 of work on your APIs before? What did you use for reference? Anything 
 clojure-specific I could leverage here to make it as elegant and concise as 
 possible?

 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.


Re: HttpKit, Enlive (html retrieval and parsing)

2014-01-11 Thread Jan Herich
I don't recommend using java's built in HTTP retrieval (by passing 
java.net.URL object to enlive html-resource function).
Not only is it significantly slower then using clj-http (which uses 
apache-http client under the hood), but it's also unreliable
when issuing more parallel requests. 
Current enlive library supports plug-able parsers, the default one is 
TagSoup, but you can switch it very easily for example
for JSoup by setting *parser* dynamic var. 
You can have a look at one of my little projects where i used enlive for 
html scraping 
herehttps://github.com/janherich/lazada-quest/blob/master/src/lazada_quest/scrapper.clj
 , 
in this case, i used clj-http as 
http client:

(ns lazada-quest.scrapper
  (:require [clojure.string :as string]
[clj-http.client :as client]
[net.cgrand.enlive-html :as html]))


(defn fetch-url
  Given some url string, fetch html content of the resource served under url 
adress and return
   it in the form of enlive nodes
  [url]

  (html/html-resource (:body (client/get url {:as :stream}

It would be straightforward to replace use of clj-http with http-kit 
synchronous api, or asynchronous api with some changes

Dňa nedeľa, 12. januára 2014 0:24:48 UTC+1 Dave Tenny napísal(-a):

 I'm just playing around with tool kits to retrieve and parse html from web 
 pages and files that I already have on disk (such as JDK API documentation).

 Based on too little time, it looks like [http-kit 2.1.16] will retrieve 
 but not parse html, and [enlive 1.1.5] will retrieve AND parse html.

 Or is there a whole built-in parse capability I'm missing in http-kiit?

 Also, http-kit doesn't seem to want to retrieve content from a file:/// 
 url, whereas enlive is happy with both local and remote content.

 I'm just messing around, I wanted to have some REPL javadoc logic that 
 didn't fire up a browser or use the swing app (whose fonts are unreadable 
 for me, and half a day spent trying to change it was not fruitful).

 Any tips or suggestions?  Just don't want to make sure I'm missing obvious 
 things.

 Thanks!





-- 
-- 
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: Sorting Nested Vectors and filter out some

2014-01-04 Thread Jan Herich
Hello Jeff,

This https://gist.github.com/janherich/8255881#file-gistfile1-clj should 
do the trick, at least it worked with data set you provided :)

Dňa sobota, 4. januára 2014 11:31:07 UTC+1 Jeff Angle napísal(-a):

 Hi...I get my nested vector from a database, then map a function that 
 formats it and computes the deviation, actual data looks like below..so 
 I don't have any keys within the the vector, ..would like to sort by 
 index 5 in in each vector descending and if index 5 is N/A (not e.g a 
 percentage)remove it from the list
 [[151819 ANTI HUMAN GLOBULIN SERUM 5ML  6.0 0 0 N/A N/A] 
 [151090 ANTI SERUM A 10ML  6.0 0 0 N/A N/A] [151094 ANTI SERUM 
 AB 10ML  6.0 0 0 N/A N/A] [151092 ANTI SERUM B 10ML  6.0 0 0 
 N/A N/A] [151095 ANTI SERUM D 10ML  6.0 0 0 N/A N/A] 
 [151825 BLOOD GLUCOSE GLUCOMETER-CONTOUR  0 0 0 N/A N/A] [151829 
 BLOOD GLUCOSE STRIPS(50 STRIPS)-CONTOUR  12.0 360.0 0 3000.00 % 
 N/A] [151828 BLOOD GLUCOSE STRIPS(50 STRIPS)-SURESTEP 0 360.0 0 N/A 
 N/A]]
 Thanks again

 On Friday, January 3, 2014 9:33:42 PM UTC+3, john walker wrote:

 You can do something like this.

 https://gist.github.com/johnwalker/8243534

 On Friday, January 3, 2014 12:37:07 PM UTC-5, Jeff Angle wrote:

 Hi guys! this has made me pull quite a load of hair new to clojure..

 have a nested vector say [[salt 0 0  %deviation 00] [sugar 5 10 
 %deviation 5$10] [milk 1 2 %deviation 12 ] [bread] ...] where % 
 deviation is the actual figure of evaluting the deviation between e.g 5 and 
 10 for sugar, I want to sort using % deviation and also filter out those 
 with deviations of 0. Please help, will revenge when I master functional 
 programing with clojure



-- 
-- 
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: Parallel http requests

2013-12-31 Thread Jan Herich
Maybe it's not exactly what you need, but i did similar thing once - i 
needed to scrape many linked html resources to extract tree data structure, 
each request/parse operation took considerable time - around 2 seconds - i 
was using clj-http/enlive combo (which is actualy Apache HttpClient/ 
TagSoup under the hood). Therefore i needed to parallelize this operations 
as much as possible and clojure pmap function provides exactly that (with 
futures and threads under the hood). Many times i stumbled upon people 
complaining that use of the pmap actually sloves down rather then speeds 
the code, but this is because the coordination overhead for managing 
threads is substantional, so it's probably not useful for tasks where the 
actual mapping function runs very fast, but in my case, the speedup in 
comparison to normal map function was massive - here is the 
codehttps://github.com/janherich/lazada-quest/blob/master/src/lazada_quest/scrapper.clji'm
 talking about.

Dňa utorok, 31. decembra 2013 9:46:53 UTC+1 chinmoy debnath napísal(-a):

 I am a newbie in clojure. I need to send multiple http requests in 
 parallel and need to have a call back when response for each request come 
 back. What will be the idiomatic way of doing it in clojure?
 Thanks in advacne



-- 
-- 
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: Akka-like framework in Clojure ?

2013-12-27 Thread Jan Herich
Hi Eric,

Maybe pulsar https://github.com/puniverse/pulsar is what you are looking 
for, but i recommend you to also discover the other way of doing 
concurrency in clojure instead of the actor model - have a look at 
CSPhttp://en.wikipedia.org/wiki/Communicating_sequential_processes and 
its clojure implementation the the form of the core library called 
core.async

Dňa piatok, 27. decembra 2013 9:54:16 UTC+1 Eric Le Goff napísal(-a):


 Hi,

 After a long background with imperative languages such as Java, I recently 
 spent some time learning functionnal programming, starting with Scala. I 
 had the opporrtunity to build a demo project based on the Akka framework.

 Now I am starting learning Clojure, and would be curious to know if there 
 was some clojure based framework available which could implement rather 
 similar features to Akka. 

 In particular, I would be interested in an implementation of the Actor 
 Model [1]

 Thanks.

 Eric


 [1] http://en.wikipedia.org/wiki/Actor_model
  

-- 
-- 
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] Component: dependency injection and state management

2013-11-21 Thread Jan Herich
This is simple brilliant... The approach proposed and the component 
framework implementing it finally solves the issue with the necessary 
evil (start/stop interactions with statefull components in any bigger 
Clojure app) by cleverly taking only the best ideas (like using inferred 
dependency graph to automatically start/stop components in the correct 
order) from Java DI frameworks like Spring, which i have a lot of 
experience with. Thank you very much for this work.

Dňa štvrtok, 21. novembra 2013 3:01:19 UTC+1 Stuart Sierra napísal(-a):

 This is a small library/framework I've been working on for a few months.

 https://github.com/stuartsierra/component

 I use this to manage runtime state in combination with my reloaded 
 workflow using tools.namespace.[1]

 I've started using this on some personal and professional projects and it 
 seems to be working fairly well.


 [1]: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded



-- 
-- 
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] Service-hub - Library for building service-oriented applications

2013-11-11 Thread Jan Herich
https://github.com/ITEdge/service-hub

Service-hub is a modular library for building service-oriented applications 
with fine grained authentication, authorization and validation rules.
The library is centered around idea of handlers as light-weight 
abstractions to CRUD interactions and services as something exposed to 
the outer world,
which is authenticated, authorized and validated - one service could be 
composed of many handlers if needed. 

The core library containing abstractions of handlers, services, 
authorizators, validators and convertors along with some util namespaces and
simple in-memory implementation is packaged in the sub-project core:

https://github.com/ITEdge/service-hub/tree/master/core

When you need to implement sql-handlers, Service-hub provides the 
sub-project persistence-korma, which depends on library korma-enhanced 
0.3.1:

https://github.com/ITEdge/service-hub/tree/master/persistence-korma

For datomic-handlers, just use the sub-project persistence-datomic:

https://github.com/ITEdge/service-hub/tree/master/persistence-datomic

And finally to expose your service-oriented application through http, use 
sub-project http-ring, which depends on ring and compojure libraries:

https://github.com/ITEdge/service-hub/tree/master/http-ring

I also created some simple examples showing how to use service-hub: 
https://github.com/ITEdge/service-hub-examples

Note that i designed and implemented the library a while ago (even if it 
was constantly upgraded and most dependencies are not obsolete), 
when i needed a tool to prototype and create relatively simple data 
exposing services in the most declarative and easy way possible, 
so it's probably not the best tool to build services requiring the data to 
be persisted with complicated transaction strategies, or to implement
asynchronous communication in the effective fashion out of the box, 
libraries like pedestal-service are much better at those kind of tasks.

I still think it could be useful to people, so i decided to announce it.

Feedback welcomed,
Jan 



-- 
-- 
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.