Prismatic Schema is awesome for describing the (web) apis, does also
validations coersion. Using it in all web projects nowadays. If you are
thinking of json apis, swagger is a great tool to publish out the
documentation. For clojure at least these schema / swagger-aware web libs
do exist:
Be aware that SimpleDateFormat is not threadsafe though.
--
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
2014-04-12 11:40 GMT+02:00 Max Penet m...@qbits.cc:
Be aware that SimpleDateFormat is not threadsafe though.
What should I use instead of SimpleDateFormat then?
--
Cecil Westerhof
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this
I first had the following function:
(defn check-concurrent2 []
(init concurrent2)
(let [c1 (future (do-sequential 1 check-until 4))
c2 (future (do-sequential 2 check-until 4))
c3 (future (do-sequential 3 check-until 4))
c4 (future (do-sequential 4
At the moment I have the following:
(def numbers '(4 6 8 10))
(doseq [number numbers]
(foo number))
The call foo generates some output, but I also want to save the time it
took for the call to complete. At the moment I am thinking about
something like:
(def numbers
Hi Cecil,
For precise timing benchmarks, use criterium [1].
For simple, gross timing, use
(map #(time (foo %)) numbers)
or to convert your code to something more functional (and including defns
for now and foo):
(defn now [] (. System currentTimeMillis))
(def numbers '(4 6 8 10))
(defn
On Apr 12, 2014, at 7:24 AM, Cecil Westerhof cldwester...@gmail.com wrote:
2014-04-12 11:40 GMT+02:00 Max Penet m...@qbits.cc:
Be aware that SimpleDateFormat is not threadsafe though.
What should I use instead of SimpleDateFormat then?
One solution to that facet of the problem is to use
2014-04-12 15:06 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
For precise timing benchmarks, use criterium [1].
For simple, gross timing, use
(map #(time (foo %)) numbers)
That is not going to work, time prints the time instead of giving it back.
or to convert your code to
2014-04-12 15:49 GMT+02:00 Cecil Westerhof cldwester...@gmail.com:
2014-04-12 15:06 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
or to convert your code to something more functional (and including defns
for now and foo):
(defn now [] (. System currentTimeMillis))
I already defined
Hi Cecil,
That's fine, but note that creating new Calendar objects has an overhead,
using System.currentTimeMillis() is a static OS call which your now()
probably uses, as well as object creation. It probably won't be millisecond
sized, but you can measure your (now) using criterium.bench to be
(defn timed-foo [times n]
(let [start (now)]
(foo n)
(conj times [n (- (now) start)])))
(defn format-time [[n t]]
(format %2d threads took %7d milliseconds n t))
(- numbers
(reduce timed-foo [])
(map format-time)
println)
On Sat, Apr 12, 2014 at 3:15 PM, Cecil
2014-04-12 16:18 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
That's fine, but note that creating new Calendar objects has an overhead,
using System.currentTimeMillis() is a static OS call which your now()
probably uses, as well as object creation. It probably won't be millisecond
For storing timing results of expressions, I make use of an agent to store
them in, and a modified time macro.
(def timings (agent []))
(defmacro send-timing
Evaluates expr and prints the time it took. Returns the value of
expr.
{:added 1.0}
[agnt expr]
`(let [start#
I am experimenting with concurrent programming. Is it possible to determine
how many cores there are on a system? Because it is in the case I am
working on at the moment not profitable to use more threads as there are
cores. (That slows the program down.) Can I find out the number of cores of
the
http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java
On Saturday, April 12, 2014 4:43:56 PM UTC+2, Cecil Westerhof wrote:
I am experimenting with concurrent programming. Is it possible to
determine how many cores there are on a system? Because it is in the case I
am
2014-04-12 16:51 GMT+02:00 Patrick Kristiansen patr...@patrkris.dk:
http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java
Thanks. I use now:
(. (. Runtime (getRuntime)) availableProcessors)
On Saturday, April 12, 2014 4:43:56 PM UTC+2, Cecil Westerhof wrote:
I am
I'd recommend running a doall on concurrent-list in order to realize the
futures, if you simply deref as you are, then you're going to delay the
execution of futures down the line as the sequence is realized bit by bit
(except chunking helps you here by accident). You are effectively
preventing
(.. Runtime getRuntime availableProcessors) is a bit cleaner
On Sat, Apr 12, 2014 at 4:18 PM, Cecil Westerhof cldwester...@gmail.comwrote:
2014-04-12 16:51 GMT+02:00 Patrick Kristiansen patr...@patrkris.dk:
http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java
Thanks.
Also, 'doall' is a bad idea if the number of threads is large :-).
You might want more control over the threadpool at that point. Futures
uses
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool()
2014-04-12 17:20 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
(.. Runtime getRuntime availableProcessors) is a bit cleaner
Did not know that one. Definitely better. But I already changed the way I
do it. I think I will use Runtime more often, so I do now:
(def runtime (. Runtime
I am not so far yet that I need it, but it never hurts to look ahead.
When compiling your Clojure program you call it with:
java -classpath *path*/classes:*path*/clojure.jar com.ociweb.talk *args*
But when distributing a program, it would be better to give just one jar
file I would think.
2014-04-12 16:27 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
(defn timed-foo [times n]
(let [start (now)]
(foo n)
(conj times [n (- (now) start)])))
(defn format-time [[n t]]
(format %2d threads took %7d milliseconds n t))
(- numbers
(reduce timed-foo [])
Oh man, please consider using leiningen. It's a whole new world :-)
http://leiningen.org/
On Sat, Apr 12, 2014 at 11:49 AM, Cecil Westerhof cldwester...@gmail.comwrote:
I am not so far yet that I need it, but it never hurts to look ahead.
When compiling your Clojure program you call it
In your case, once you've created a leiningen project, it's as easy as
'lein uberjar'.
On Sat, Apr 12, 2014 at 11:56 AM, Gary Trakhman gary.trakh...@gmail.comwrote:
Oh man, please consider using leiningen. It's a whole new world :-)
http://leiningen.org/
On Sat, Apr 12, 2014 at 11:49 AM,
2014-04-12 17:56 GMT+02:00 Gary Trakhman gary.trakh...@gmail.com:
Oh man, please consider using leiningen. It's a whole new world :-)
http://leiningen.org/
That was on my list. I'll leave this problem for the moment being then,
because it will be solved 'automatically'. :-D
--
Cecil
On Sat, Apr 12, 2014 at 4:55 PM, Cecil Westerhof cldwester...@gmail.comwrote:
(- numbers
(reduce timed-foo [])
(map format-time)
println)
(- numbers
(reduce timed-foo [])
(map format-time)
(map println))
--
Fergal Byrne, Brenter IT
Author, Real Machine
+1 Gary
I'd just run the Leiningen install process, then create a new project with
it, and move your code into that.
Do this right now, I can't imagine doing anything in Clojure that doesn't
begin with lein new your-project. It will save you hours in fewer hours.
Bonus: add Midje, or even
2014-04-12 18:19 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
On Sat, Apr 12, 2014 at 4:55 PM, Cecil Westerhof
cldwester...@gmail.comwrote:
(- numbers
(reduce timed-foo [])
(map format-time)
println)
(- numbers
(reduce timed-foo [])
(map format-time)
2014-04-12 16:18 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
That's fine, but note that creating new Calendar objects has an overhead,
using System.currentTimeMillis() is a static OS call which your now()
probably uses, as well as object creation. It probably won't be millisecond
One of the possibility is to use joda-time DateTimeFormatter (directly or
via one of the clojure wrappers).
On Saturday, April 12, 2014 1:24:22 PM UTC+2, Cecil Westerhof wrote:
2014-04-12 11:40 GMT+02:00 Max Penet m...@qbits.cc javascript::
Be aware that SimpleDateFormat is not threadsafe
Cheers Cecil,
It's always best to see how best to do something, one day it'll make all
the difference.
On Sat, Apr 12, 2014 at 7:03 PM, Cecil Westerhof cldwester...@gmail.comwrote:
2014-04-12 16:18 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
That's fine, but note that creating new
2014-04-12 20:36 GMT+02:00 Fergal Byrne fergalbyrnedub...@gmail.com:
It's always best to see how best to do something, one day it'll make all
the difference.
I agree. Most people call it gold-plating. And of-course you have to be
careful about that, but things like this are good to do is my
2014-04-11 18:12 GMT+02:00 Alex Vzorov alex.vzo...@gmail.com:
You could use a clojure agent http://clojure.org/agents, that would
output your messages on a separate thread, one by one.
(def *logger* (agent 0))
(defn give-message [message]
(send *logger*
(fn [_ [msg]] (println
2014-04-12 17:19 GMT+02:00 Gary Trakhman gary.trakh...@gmail.com:
I'd recommend running a doall on concurrent-list in order to realize the
futures, if you simply deref as you are, then you're going to delay the
execution of futures down the line as the sequence is realized bit by bit
(except
As discovered by Kevin Downey https://github.com/hiredman, (use
[loom.graph] :reload) in tests was causing the namespace to be reloaded,
which redefined the records in loom.graph, but didn't reload loom.attrs ,
so the extends didn't get run again for the new record type breaking all
kinds of
On Sat, Apr 12, 2014 at 5:13 AM, Cecil Westerhof cldwester...@gmail.com
wrote:
But it looks a ‘little’ cumbersome. Is there a better way to do this?
Here's another way. Not the best way, but I offer it to introduce you
to atoms [1] if you're not familiar yet.
[1] http://clojure.org/atoms
(def
Great video! I've looked through Zach's examples, and even started coding a
game myself. But your screencast helped me have a better understanding of
some of the concepts and code that I was having trouble understanding just
by looking at the example games. Thanks!
-Kris
On Thursday, March 27,
Hey,
I have hacked together this code:
// Get the java file io library
(import '(java.io File))
// Get some files
(def f (File. /My/files/))
(def fs (file-seq f))
// Filters for suffixes .mp3
(def get-mp3 (filter #(.endsWith (.getName %) .mp3) fs))
// Get the path of one mp3
(println (take 1
I took a look at the code, but it's not clear to me what it's supposed to
be doing.
But, my suspicion is this algorithm could be expressed as a reduce, which
means you could potentially use reducers on it and get fork/join
concurrency for free.
I think that's the case because it seems like these
39 matches
Mail list logo