Re: How to use a Java SDK from Amazon?

2016-01-09 Thread Allen Johnson
I'm not sure if this helps but a quick glance at the github project you
linked to contains a pom file which uses the following maven coordinates:


  com.amazon.alexa
  alexa-skills-kit
  1.1.1


You may want to try that in leiningen instead.

:dependencies [[org.clojure/clojure "1.6.0"]
 [com.amazon.alexa/alexa-skills-kit "1.1.1"]]

If that doesn't transitively pull in the other dependencies you need then
you could try to list them manually -- refer to the sample pom file[1].

[1]:
https://github.com/amzn/alexa-skills-kit-java/blob/master/samples/pom.xml

Good luck!

AJ


On Sat, Jan 9, 2016 at 5:39 PM Laws  wrote:

> Damn. I tried localrepo, just like I have in the past:
>
> lein localrepo install alexa-skills-kit-1.1.jar alexa-sdk 1.1
>
> and then in project.clj:
>
>   :dependencies [[org.clojure/clojure "1.6.0"]
>  [alexa-sdk "1.1"]
>
> but I still ran into configuration issues:
>
> Compiling salesvoice.core
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/slf4j/LoggerFactory, compiling:(query.clj:1:1)
>
> Have others dealt with this issue, when using an SDK that uses slf4j? Is
> there an obvious way to configure this?
>
>
>
> On Saturday, January 9, 2016 at 5:17:00 PM UTC-5, Laws wrote:
>>
>> Nevermind. I just noticed they offer a Jar:
>>
>>
>> https://github.com/amzn/alexa-skills-kit-java/tree/master/repo/alexa-skills-kit/alexa-skills-kit/1.1
>>
>> I'll just use that.
>>
>> Ignore this post.
>>
>>
>> On Saturday, January 9, 2016 at 5:14:51 PM UTC-5, Laws wrote:
>>>
>>> I'm not sure if this is a Clojure question, but I'm not sure where else
>>> to ask. I've been working on an app for the Amazon Echo. I'm trying to deal
>>> with this requirement, which I must deal with if I am to get the app into
>>> the Amazon app store:
>>>
>>> Check the request signature to verify the authenticity of the request.
>>> Alexa signs all HTTPS requests.
>>>
>>>- The Java library does this verification in the SpeechletServlet class.
>>>If you do not use the Java library, you must do this verification 
>>> yourself.
>>>- If you use the Java library without using the SpeechletServlet class,
>>>you can use theSpeechletRequestSignatureVerifier class to do this.
>>>
>>>
>>> For some bizarre reason, Amazon does not make its SDK available via the
>>> main Maven repository. Many developers have asked Amazon to change this,
>>> but for now, we have to:
>>>
>>> git clone g...@github.com:amzn/alexa-skills-kit-java.git
>>>
>>> I thought I could then:
>>>
>>> cp -r ../../alexa-skills-kit-java/src/* src/java/
>>>
>>> In my project.clj file I have:
>>>
>>>   :source-paths  ["src/clojure"]
>>>   :java-source-paths ["src/java"]
>>>   :main salesslick.core
>>>   :aot :all
>>>
>>> So all of alexa-skills-kit-java/src is now in my src/java directory.
>>>
>>> I still end up with these kinds of dependency issues:
>>>
>>> Compiling 47 source files to
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/target/classes
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/speechlet/Session.java:16:
>>> error: package org.apache.commons.lang3 does not exist
>>> import org.apache.commons.lang3.Validate;
>>> ^
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/slu/Intent.java:17:
>>> error: package org.apache.commons.lang3 does not exist
>>> import org.apache.commons.lang3.Validate;
>>> ^
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/slu/Slot.java:13:
>>> error: package org.apache.commons.lang3 does not exist
>>> import org.apache.commons.lang3.Validate;
>>> ^
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/speechlet/authentication/ApplicationIdVerifier.java:17:
>>> error: package org.slf4j does not exist
>>> import org.slf4j.Logger;
>>> ^
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/speechlet/authentication/ApplicationIdVerifier.java:18:
>>> error: package org.slf4j does not exist
>>> import org.slf4j.LoggerFactory;
>>> ^
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/speechlet/authentication/ApplicationIdVerifier.java:29:
>>> error: cannot find symbol
>>> private static final Logger log =
>>> LoggerFactory.getLogger(ApplicationIdVerifier.class);
>>> ^
>>> symbol: class Logger
>>> location: class ApplicationIdVerifier
>>> /Users/lkrubner/projects/salesvoiceapp/salescricket/src/java/com/amazon/speech/speechlet/IntentRequest.java:15:
>>> error: package org.apache.commons.lang3 does not exist
>>> import org.apache.commons.lang3.Validate;
>>> ^
>>>
>>> [shortened to avoid boredom]
>>>
>>>
>>> What would I have to do to get a line such as this to resolve:
>>>
>>> import org.apache.commons.lang3.Validate;
>>>
>>> ???
>>>
>>> I know there are many Clojure developers who also do a great deal of
>>> Java development, but I am not one of them. I love Clojure/Leinengen
>>> beca

Re: unusual question: how do you get morale?(or moral support)

2013-05-15 Thread Allen Johnson
I've recently been wondering about this. I'd say that I'm coming out of a
burnout period that I've been in for at least the last few months. Also,
reading things like hacker news gives me this feeling that I'm not doing
enough with my time -- which adds to the weight that I already feel on my
shoulders.

Lately, I have been coming out of this slump and have begun looking at work
as fun again instead of as a chore. Of course there are still chore aspects
but overall it's become very enjoyable. I don't receive any moral support
from friends or family since they are not familiar with programming and
most of them aren't tech savvy.

I've recently made some life style changes which might have contributed to
my personal turn around. My primary life style change is sleep. Instead of
treating sleep as a luxury that I can skimp on -- I have given it equal
importance to eating healthy and exercise. I used to stay up late after a
long day of work to catch up on all of the fun/interesting things that
continue to be developed in this field. After all, that is part of why I
enjoy this line of work. But now I limit that activity to go no later than
10pm. I've also relaxed on the drinking. While alcohol can help you fall
asleep, I believe the quality of sleep you have is greatly diminished.

Now I'm an early-to-bed / early-to-rise type which is a huge change for me.
I find myself excited to start the day and am more productive at work. The
curiosity, creativity, and motivation has returned. :-)

Allen



On Sun, May 12, 2013 at 3:34 PM, AtKaaZ  wrote:

> Hi. I've been meaning to ask (all of)you, how do you get moral support?
> How do you put yourself into that mood so that you're happy/willing to
> program? What motivates you to do it? Is it the people you surround
> yourself with or the financial support? Are they enough to subconsciously
> motivate you? What if you had no friends/contacts but you had time?
>
>  Unusual question for this ML, I know, so I won't expect (m)any answers.
> 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.
>
>
>

-- 
-- 
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: Overtone - Actual Music!

2012-08-15 Thread Allen Johnson
Awesome.  Sounds very Nine Inch Nails like.  Time for Trent Reznor to
get on some Clojure/Overtone ;-)

AJ

On Wed, Aug 15, 2012 at 6:50 AM, Sam Aaron  wrote:
> Hey everyone,
>
> sorry, I couldn't resist posting this, but I'm getting real close to making 
> decent music with Overtone now, and I just wanted to share with you where I'm 
> at:
>
> https://vimeo.com/47578617
>
> I think the coolest thing about this is that what you see in the screencast 
> is something you can clone from Github *now* and play with today. That music 
> is an instrument that you can control - and trust me, it's more fun to play 
> with than it is to listen to :-)
>
> Let me know if you like it.
>
> Sam
>
> ---
> http://sam.aaron.name
>
> --
> 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 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


Re: Buggy FP behavior with Clojure 1.3

2012-06-26 Thread Allen Johnson
When I run the repl from leiningen (v2.0.0-preview6) I get the
Infinity exception.  But when I run the repl straight from the
clojure.jar it works without error.

java -jar ~/.m2/repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar

AJ

On Tue, Jun 26, 2012 at 11:25 AM, Armando Blancas  wrote:
> I don't get the exception on 1.4.0:
>
> ~ $ clj
> Clojure 1.4.0
> user=> 1e309
> Infinity
> user=>
>
>
> On Monday, June 25, 2012 11:09:14 PM UTC-7, Sean Corfield wrote:
>>
>> On Mon, Jun 25, 2012 at 10:30 PM, dennis zhuang 
>> wrote:
>> > Added a postfix "M" to make the number as BigDecimal or "N" as a
>> > BigInteger:
>>
>> Yes...
>>
>> user=> 1e309M
>> 1E+309M
>>
>> The "Infinity" exception seems wrong but clearly using BigDecimal makes it
>> work.
>> --
>> Sean A Corfield -- (904) 302-SEAN
>> An Architect's View -- http://corfield.org/
>> World Singles, LLC. -- http://worldsingles.com/
>>
>> "Perfection is the enemy of the good."
>> -- Gustave Flaubert, French realist novelist (1821-1880)
>
> --
> 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 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


Re: Doseq, map-style

2012-06-08 Thread Allen Johnson
Combine map with dorun and you get the same effect:

(dorun (map println logs))

http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/dorun

Allen

On Thu, Jun 7, 2012 at 11:32 PM, David Jacobs  wrote:
> I would love to have a version of doseq that works like map (similar to
> "each" in other dynamic languages). In other words, instead of (doseq [log
> logs] (println log)), I would say something like (each println logs).
>
> Is there a built-in Clojure method that works like this?
>
> --
> 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 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


Re: deps.js in cljsbuild?

2012-05-14 Thread Allen Johnson
I think the current fix is to add this JS declaration before you
import your cljs generated js file.  IIRC, this is only needed when
building without advanced optimizations.


  var CLOSURE_NO_DEPS = true;



AJ

On Mon, May 14, 2012 at 9:21 AM, Murtaza Husain
 wrote:
> Hi,
>
> I am using lein-cljsbuild to compile the cljs code. I see reference to a
> deps.js file that is added after the tag in which I have included the
> generated js file. The browser naturally fails to find the file as it does
> not exist.
>
> What is the deps.js file and how do I resolve its 404 error?
>
> Thanks,
> Murtaza
>
> --
> 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 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


Re: why can i not shut-down my pc from Java?

2012-05-07 Thread Allen Johnson
The function passed to (defmulti) must take the same args as (defmethod).

Try this:

(defmulti halt
  (fn [_ _]
(let [os (System/getProperty "os.name")]
  (if (.startsWith os "Mac OS") :Linux  (keyword os)

AJ

On Mon, May 7, 2012 at 4:53 PM, Jim - FooBar();  wrote:
> Following my earlier post, i tried converting the working shutdown
>  function into a multi-method in order to make it cleaner to read... However
> for some reason the compiler is complaining and i can't pinpoint wheere the
> problem is! This is the multi-method:
> 
> (defmulti halt
> (fn []
> (let [os (System/getProperty "os.name")]
>   (if (.startsWith os "Mac OS") :Linux  (keyword os)
>
> (defmethod halt :Linux [root-pwd minutes-after]
>    (clojure.java.shell/sh
>    "sudo" "-S" "shutdown" (str "+" minutes-after) :in (str root-pwd "\n")))
>
> (defmethod halt :Windows [_ minutes-after]
>    (clojure.java.shell/sh "shutdown" "-s" "-t"  (str minutes-after)))
>
> (defmethod halt :Solaris [root-pwd seconds-after]
>    (clojure.java.shell/sh "shutdown" "-S" "-y" (str "-g" seconds-after) "-i"
> "S" :in (str root-pwd "\n")))
>
> (defmethod halt :default [] (println "Unsupported operating system!"))
> -
>
> when calling (halt "some-password" 1) i'm getting this:
>
> java.lang.IllegalArgumentException: Wrong number of args (2) passed to:
> user$eval664$fn (NO_SOURCE_FILE:0)
>
> the same happens no matter how many args i pass in! this is very strange!
>
> thanks in advance...
>
> Jim
>
>
>
>
>
>
>
>
> On 07/05/12 19:52, Jim - FooBar(); wrote:
>
> Good stuff... :-)
>
> Jim
>
> On 07/05/12 19:51, Armando Blancas wrote:
>>
>> Can someone please verify that it works on windows as well???
>>
>
> It works on XP.
>
> --
> 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 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 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


Re: apply a function to every item in a sequence without realizing the sequence

2012-05-02 Thread Allen Johnson
My example included a use of `map`. It is lazy and will work but you
have to be sure that you aren't using it in a way that would hold onto
the head of the sequence.

When experimenting in a repl it might not seem that it is lazy since
the repl will attempt to print the result of calling map when that is
the only expression.

AJ

On Wed, May 2, 2012 at 4:06 AM, Baishampayan Ghose  wrote:
> On Wed, May 2, 2012 at 12:01 PM, Sean Neilan  wrote:
>> I don't think so.
>
> Of course it is. The problem is not in laziness, but in holding on to the 
> head.
>
> Regards,
> BG
>
> --
> Baishampayan Ghose
> b.ghose at gmail.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To 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


Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Allen Johnson
Do you have example code that is failing?

You should be able to use some of the items you listed as "problems".
Try something like this:

(->> (file-seq (io/file "/some/dir"))
  (map println)
  (dorun))

AJ

On Wed, May 2, 2012 at 12:26 AM, Sean Neilan  wrote:
> I forgot to mention:
> (nth (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) 20)
> works great because nth doesn't realize the sequence!
>
> For now, I'll look at nth's source code to see how it iterates.
>
> On Tue, May 1, 2012 at 11:24 PM, Sean Neilan  wrote:
>>
>> Hi,
>>
>> I'm sure this has been discussed to death but I can't figure it out.
>>
>> I've got a file-seq sequence from
>> (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) that will
>> cause an out of memory error if realized.
>>
>> I want to call a function such as println on every element in the
>> sequence.
>>
>> I understand that naming the sequence will cause it to be realized.
>>
>> The problems
>>
>> I can't use map as in (map println (file-seq (java.io.File.
>> "/DirectoryWithMillionsOfFiles"))). Map realizes the sequence.
>> I can't use for as in (for [x (files)] (println x)). For realizes the
>> sequence.
>> I can't use dorun because even though dorun doesn't realize the sequence,
>> it can't execute a function on every element.
>> I can't use loop recur because it also realizes the sequence: (loop [a
>> (files) b (first a)] (println b) (recur (rest a) (first a)))
>> I can't use refs because even though they provide state, they can't save
>> the state of the sequence without realizing the sequence.
>>
>> My question
>> Should I try the new stream library?
>>
>> Thank you for your time.
>>
>> -Sean
>>
>
> --
> 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 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


[ANN] WabbitMQ update v0.2.1

2012-04-28 Thread Allen Johnson
This update should fix all reflection warnings.

Leiningen:
[com.mefesto/wabbitmq "0.2.1"]

Github:
https://github.com/mefesto/wabbitmq

Thanks,
Allen

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


Re: New release of Domina (now with reworked eventing)

2012-04-27 Thread Allen Johnson
I received the following error when performing a `lein deps` for this
version [domina "1.0.0-beta4"]

Could not find artifact org.clojure:clojurescript:pom:0.0-1069 in
central (http://repo1.maven.org/maven2)
Could not find artifact org.clojure:clojurescript:pom:0.0-1069 in
clojars (http://clojars.org/repo/)
Could not find artifact org.clojure:clojurescript:jar:0.0-1069 in
central (http://repo1.maven.org/maven2)
Could not find artifact org.clojure:clojurescript:jar:0.0-1069 in
clojars (http://clojars.org/repo/)
java.lang.RuntimeException:
org.sonatype.aether.resolution.DependencyResolutionException: Could
not find artifact org.clojure:clojurescript:jar:0.0-1069 in central
(http://repo1.maven.org/maven2)
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)
at 
cemerick.pomegranate.aether$resolve_dependencies.doInvoke(aether.clj:406)
at clojure.lang.RestFn.invoke(RestFn.java:1096)
at leiningen.core.classpath$get_dependencies.doInvoke(classpath.clj:107)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:604)
at 
leiningen.core.classpath$resolve_dependencies.doInvoke(classpath.clj:123)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at leiningen.deps$deps.invoke(deps.clj:24)
at leiningen.deps$deps.invoke(deps.clj:20)
at clojure.lang.Var.invoke(Var.java:401)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.core$apply.invoke(core.clj:602)
at leiningen.core.main$resolve_task$fn__699.doInvoke(main.clj:66)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.lang.AFunction$1.doInvoke(AFunction.java:29)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:602)
at leiningen.core.main$apply_task.invoke(main.clj:88)
at leiningen.core.main$_main$fn__731.invoke(main.clj:140)
at leiningen.core.main$_main.doInvoke(main.clj:140)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:401)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.core$apply.invoke(core.clj:600)
at clojure.main$main_opt.invoke(main.clj:323)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:436)
at clojure.lang.Var.invoke(Var.java:409)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: org.sonatype.aether.resolution.DependencyResolutionException:
Could not find artifact org.clojure:clojurescript:jar:0.0-1069 in
central (http://repo1.maven.org/maven2)
at 
org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:30)
... 37 more
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException:
Could not find artifact org.clojure:clojurescript:jar:0.0-1069 in
central (http://repo1.maven.org/maven2)
at 
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
at 
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
at 
org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:358)
... 43 more
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException:
Could not find artifact org.clojure:clojurescript:jar:0.0-1069 in
central (http://repo1.maven.org/maven2)
at 
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:946)
at 
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:940)
at 
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
at 
org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(Thr

[ANN] WabbitMQ v0.2.0 release

2012-04-06 Thread Allen Johnson
WabbitMQ v0.2.0 has been pushed to clojars.

[com.mefesto/wabbitmq "0.2.0"]

This release contains the following updates:
  * Updated RabbitMQ Java Client (v2.8.1)
  * Updated Cheshire JSON library (v3.1.0)
  * `consuming-seq` no longer depends on the deprecated QueueingConsumer class

Tested against RabbitMQ server v2.2.0 and v2.8.1. All versions in
between are assumed to work as well ;-)

https://github.com/mefesto/wabbitmq

Thanks,
Allen

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


Re: idiomatic list-ify

2012-03-08 Thread Allen Johnson
> So I've ended up writing the function with a conditional, like so.  Is there
> a tidier way?
>
> (defn ls [x] (cond (list? x) (apply list x)
>                    (nil? x)  '()
>                    :else (list x)))

If `x` is a list then is the call to `(apply list x)` necessary?

(defn ls [x]
  (cond
(list? x) x
(nil? x) ()
:else (list x)))

Allen

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


Re: add records in mysql????

2012-01-06 Thread Allen Johnson
You'd want to use one of the insert functions for that:

(defn add-user [user]
  (sql/with-connection db
(sql/insert-record :books user)))

http://clojure.github.com/java.jdbc

Allen

On Fri, Jan 6, 2012 at 3:13 PM, jayvandal  wrote:
> i am using leinningen  and mysql example. I can select records as:
>
> (defn list-ausers []
>  (sql/with-connection db
>    (sql/with-query-results rows
>
>      ["SELECT * FROM books WHERE BOOK_ID = '1'"]
>      (println rows
>
> but I can't insert records,i doesn't like the query as:
>
> (defn add-ausers []
>  (sql/with-connection db
>    ;(sql/with-query-results rows
>
>         sql  ["INSERT INTO books(BOOK_ID, BOOK_NAME, BOOK_PRICE,
> BOOK_AUTHOR) VALUES('2','joe','12', 'siley')"]
>      (println rows)
>
> why or?
>          ;)
>          ))
>
> --
> 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 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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Allen Johnson
Although now I see that this usage is breaking the "side-effect free"
rule. So actually this is probably not what you want to do. :)

Now I'm with you and thinking that atoms are not a proper fit for
PersistentQueue. Maybe someone from the conj can shed some light on
this.

Allen

On Wed, Nov 9, 2011 at 8:56 PM, Allen Johnson  wrote:
> In your example yes, but you could make it atomic by placing the
> functionality in a function of it's own:
>
> ;; queue processing actions
> (defn process-item [queue]
>  (println "Processed item:" (peek queue))
>  (pop queue))
>
> ;; usage
> (let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
>  (swap! queue process-item) ; prints 1
>  (swap! queue process-item) ; prints 2
>  (swap! queue process-item)) ; prints 3
>
> Probably better examples but that's the basic idea.
>
> Allen
>
> On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi  wrote:
>> Hi,
>>
>> To avoid peeking same element of a queue, I think PersistentQueue must
>> be stored in ref not atom.
>> Is this correct?
>>
>> ;;Ref: safe
>> (dosync
>>  (let [item (peek @r)]
>>    (alter r pop)
>>    item))
>>
>> ;Atom: unsafe
>> (let [item (peek @a)]
>>  (swap! a pop)
>>  item))
>>
>> 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 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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Allen Johnson
In your example yes, but you could make it atomic by placing the
functionality in a function of it's own:

;; queue processing actions
(defn process-item [queue]
  (println "Processed item:" (peek queue))
  (pop queue))

;; usage
(let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
  (swap! queue process-item) ; prints 1
  (swap! queue process-item) ; prints 2
  (swap! queue process-item)) ; prints 3

Probably better examples but that's the basic idea.

Allen

On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi  wrote:
> Hi,
>
> To avoid peeking same element of a queue, I think PersistentQueue must
> be stored in ref not atom.
> Is this correct?
>
> ;;Ref: safe
> (dosync
>  (let [item (peek @r)]
>    (alter r pop)
>    item))
>
> ;Atom: unsafe
> (let [item (peek @a)]
>  (swap! a pop)
>  item))
>
> 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 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


Re: clojure.contrib.base64

2011-10-06 Thread Allen Johnson
Just wanted to add the Apache commons codec has a base64
encoder/decoder. With a quick test I was able to encode a ~100MB file
in 2.3sec. Example code below:

In leiningen: [commons-codec "1.4"]

(require '[clojure.java.io :as io])
(import '[org.apache.commons.codec.binary Base64OutputStream])

(defn encode [src dest]
  (with-open [in (io/input-stream src)
   out (-> dest (io/output-stream) (Base64OutputStream.)))]
(io/copy in out :buffer-size 8192)))

(.length (io/file "/tmp/blob"))
=> 99667238

(time (encode "/tmp/blob" "/tmp/output"))
=> "Elapsed time: 2254.521259 msecs"

org.apache.commons.codec.binary.Base64 has helper methods as well.

Allen

On Thu, Oct 6, 2011 at 1:27 PM, Aaron Bedra  wrote:
> This actually introduces an opportunity for a much larger set of utilities.
>
> clojure.data.crypto
>
> base64 is part of this idea anyways, and putting it in place along with
> nice wrappers around the messy java crypto bits I think could provide a
> significant win.  I have had to do this several times now and it would
> be great to have in the future. The thing that always pushed me away was
> relying on sun.misc when all of the jdks don't have it.
>
> Cheers,
>
> Aaron Bedra
> --
> Clojure/core
> http://clojure.com
>
> On 10/06/2011 08:07 AM, Stuart Halloway wrote:
>>> I use Base64 encoding a lot and the slow implementation is hurting a
>>> lot. It's slower than Sun misc encoder/decoder
>>> and that one is very very slow. I was using Sun's implementation a bit
>>> and it took 80 seconds to encode a 56 MB file.
>>> Then I found this: http://migbase64.sourceforge.net/
>>> It loaded from a disk drive and encoded the same file in 0.3 seconds!
>>> Would it be possible to have Clojure contrib use an implementation
>>> like this and thus enable all Clojure developers to have lightning
>>> fast Base64 encoding/decoding? I know having everything implemented in
>>> clojure is a big thing around here but in case of Base64 encoding and
>>> regular expressions I think the language would benefit greatly by
>>> having implementations which are orders of magnitude faster than
>>> default implementations in java. Did I say regular expressions?
>>> http://www.tusker.org/regex/regex_benchmark.html
>>> Like Rich Hickey said: why should we reinvent file streams and sockets
>>> in each language?
>>> I think the same principle applies to Base64 and regular expressions,
>>> especially when in Clojure we have an opportunity to replace standard
>>> java implementations with ones that are orders of magnitude faster.
>>> What are your views on this?
>> I too would like a fast base64. There are a few different things we could do:
>>
>> 1. Vet the best Java one and link it from contrib.base64 (and possibly 
>> deprecate the contrib as well).
>>
>> 2. Approve a base64 lib for inclusion by reference in contribs.
>>
>> 3. Write a fast clojure one (possibly a direct port of the project you link, 
>> if it is the best).
>>
>> I have several Clojure projects that ship with no binary dependencies. This 
>> is a maintenance virtue, which is why I think #3 is important.
>>
>> If somebody writes a good one I will fast track getting it into contrib.
>>
>> Stu
>>
>>
>
> --
> 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 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


Re: Currently recommended CSV client, again ?

2011-10-04 Thread Allen Johnson
In addition, there is org.clojure/data.csv which says it works with
Clojure 1.2 and 1.3.

https://github.com/clojure/data.csv

Allen

On Tue, Oct 4, 2011 at 2:42 PM, Laurent PETIT  wrote:
> Self answer : either clojure-csv for full NIH clojure solution (
> http://github.com/davidsantiago/clojure-csv, the one I took :-) ), or
> java based OpenCSV
>
> There is also a csv lib in Incanter, but I did not try to see if it is
> sufficiently decoupled from the rest to be used in isolation (still
> having it tied to the "Incanter" name is not a good sign, IMHO).
>
> 2011/10/4 Laurent PETIT :
>> Hello all,
>>
>> What would be the currently recommended CSV client, please ?
>>
>> Not necessarily already upgraded to 1.3 support.
>>
>> Thanks in advance,
>>
>> -- Laurent
>>
>
> --
> 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 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


Re: Anyone on Google+ yet?

2011-07-14 Thread Allen Johnson
> Yep, you're supposed to add everyone by hand and yes, it is totally unwieldy.
> That's the way it is right now.
> Circles are private and every user is supposed to make their own.

I'm definitely liking it so far. Although I do find myself avoiding
public posts to avoid spamming everyone in the Clojure circle but
maybe I'm thinking about it too much. Because of this experiment I'm
following lots of interesting people that I otherwise might not have
found.

We all share a common interest in clojure -- this is a fun way to see
what other interests we all share.

Allen

>
> cla
>
> 2011/7/15 Dave Ray :
>> http://profiles.google.com/daveray
>>
>> maybe this is a dumb question, but am I supposed to manually add
>> everyone on this thread in G+? Seems a little unwieldy.
>>
>> dave
>
> --
> 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 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


Re: Anyone on Google+ yet?

2011-07-14 Thread Allen Johnson
> Please add link to your profile below.

https://plus.google.com/101461247790324463561/posts

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


Re: Avoiding nils

2011-07-07 Thread Allen Johnson
On Thu, Jul 7, 2011 at 4:27 PM, octopusgrabbus  wrote:
> This code
>
> (defn ret-odd
>  [seq-val]
>  (if (not (nil? seq-val))
>    (if (odd? seq-val)
>      seq-val)))
>
> (def my-seq '(1 2 3 4 5 6 7 8 9))
>
> (map ret-odd my-seq)
>
> finds the odd numbers, but also returns nil. How do I find just the
> odd numbers?

(filter odd? my-seq)

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


Re: update xml attribute value

2011-06-02 Thread Allen Johnson
> Thanks Allen, it works, I did not know the loc can be treated like a hash.

'loc itself isn't a map even though zip/edit makes it seem that way.
Behind the scenes zip/edit calls (zip/node loc) which will return a
map, at least in the case of this xml example. zip/edit then applies
the function you provided (assoc-in) to this map plus any supplied
args. The result of this replaces the node at loc.

https://github.com/clojure/clojure/blob/59b65669860a1f33825775494809e5d500c19c63/src/clj/clojure/zip.clj#L210

Allen

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


Re: update xml attribute value

2011-06-02 Thread Allen Johnson
> Does anyone know how to update xml element attribute value on the zipper
> data structure?
> I have something like
> 
>     
>     
> 
> (:require (clojure [xml :as xml] [zip :as zip])
>      [clojure.contrib.zip-filter.xml :as zf])
> (let
>   [src (-> "c:/my.xml" io/file xml/parse zip/xml-zip)
>    edf (zf/xml1-> src :root :element1)
>    n    (-> (zf/attr :description) (zip/replace ""))])
> and this is giving me java.lang.ClassCastException: java.lang.Character
> cannot be cast to clojure.lang.Associative (test-xml-zip.clj:0)

Given that 'loc is the proper location in your zipper:

(zip/edit loc assoc-in [:attrs :description] "new value")

Allen

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


Re: Passing "environment configuration parameters" to a Clojure web app

2011-05-24 Thread Allen Johnson
> The DTD/schema for web.xml files is not small (e.g. 
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd).  Rather than offering a 
> transliteration of a subset of web.xml's elements into sexprs, perhaps it 
> would be better to be able to control your web.xml directly, and have 
> lein-ring use it when it's present rather than generating one.

Much better idea :)

Allen

> Just a thought from the suffering equine department. :-)
>
> - Chas
>
> On May 23, 2011, at 8:48 PM, Allen Johnson wrote:
>
>> On a related note. About a month or two ago I started work on a patch
>> for lein-ring so you'd have more control over the web.xml that is
>> generated. This was motivated by the desire to use the container's
>> datasource instead of creating one yourself. If anyone is interested I
>> can finish this up and contact weavejester to see if it's something
>> worth incorporating.
>>
>> https://github.com/mefesto/lein-ring/commit/3016142e1c7aadc77d273453e04f9196319406a2
>>
>> Allen
>>
>> On Mon, May 23, 2011 at 7:43 PM, Allen Johnson  wrote:
>>> I'm also interested in this topic. It was discussed briefly on the
>>> clojure-web-dev mailing list a little while ago. What I've been doing
>>> is something like this:
>>>
>>> # lein ring project
>>> myapp/
>>>  config/
>>>    production/WEB-INF/myapp.properties
>>>    development/WEB-INF/myapp.properties
>>>    test/WEB-INF/myapp.properties
>>>  src/
>>>  project.clj
>>>
>>> $ # create war file
>>> $ lein ring uberwar
>>>
>>> $ # update configuration for production
>>> $ jar uvf myapp.war -C config/production .
>>>
>>> $ # or... update configuration for development server
>>> $ jar uvf myapp.war -C config/development .
>>>
>>> This assumes you have a ServletContextListener or equivalent in place
>>> to read on deployment.
>>>
>>> This is quick and dirty. I'd definitely like to see something better emerge.
>>>
>>> Allen
>>>
>>> On Mon, May 23, 2011 at 3:59 PM, Shantanu Kumar
>>>  wrote:
>>>> Hello Laurent, Quite interesting points there.
>>>>
>>>> Yes, I agree - having confidential config (production etc.) in code
>>>> base is not advisable. The reason I mentioned that though, was because
>>>> I was trying to cover a gamut of workflows the situation may demand.
>>>> One one extreme there may be a company where no developer gets to
>>>> touch production servers and must develop for a target config
>>>> constraint. On the other a set of developers who routinely deploy to
>>>> production and can get away with changing deployment practices on the
>>>> fly.
>>>>
>>>> What I would like to emphasize is to distinguish one environment from
>>>> the other (the code base may contain dummy config data in version
>>>> control.) A developer can change the dev config to a valid setup, and
>>>> similarly the person who builds for production deployment can change
>>>> the config locally (without committing the config details back to the
>>>> version control) and build a deployable bundle.
>>>>
>>>> An added level of indirection (where a config script loads details
>>>> from either a discoverable or a fixed resource) can bring some
>>>> flexibility -- the Ops guys can even edit config and re-start the app.
>>>> Though web container specific and servlet specific solutions are
>>>> useful for many cases, I am not sure I would recommend that as a
>>>> general practice -- for example, what am I to do if I have to deploy
>>>> my code to Netty/Aleph? IMHO ideally a Clojure webapp should be easily
>>>> buildable/deployable as a WAR (or EAR :-\) for web containers like
>>>> Tomcat/JBoss etc., but it may not depend on one.
>>>>
>>>> How to accomplish such builds where we cherry pick config stuff when
>>>> building for a certain environment (and how it integrates with the
>>>> development workflow) is a different aspect. I think I have seen
>>>> Apache Ant gives sufficient flexibility to do these things. Maybe
>>>> Leiningen can deliver some of the same things using plugins.
>>>>
>>>> Regards,
>>>> Shantanu
>>>>
>>>> On May 23, 12:48 pm, Laurent PETIT  wrote:
>>>>> Hello,
>>>>>
>>>>> Thanks for

Re: Passing "environment configuration parameters" to a Clojure web app

2011-05-23 Thread Allen Johnson
On a related note. About a month or two ago I started work on a patch
for lein-ring so you'd have more control over the web.xml that is
generated. This was motivated by the desire to use the container's
datasource instead of creating one yourself. If anyone is interested I
can finish this up and contact weavejester to see if it's something
worth incorporating.

https://github.com/mefesto/lein-ring/commit/3016142e1c7aadc77d273453e04f9196319406a2

Allen

On Mon, May 23, 2011 at 7:43 PM, Allen Johnson  wrote:
> I'm also interested in this topic. It was discussed briefly on the
> clojure-web-dev mailing list a little while ago. What I've been doing
> is something like this:
>
> # lein ring project
> myapp/
>  config/
>    production/WEB-INF/myapp.properties
>    development/WEB-INF/myapp.properties
>    test/WEB-INF/myapp.properties
>  src/
>  project.clj
>
> $ # create war file
> $ lein ring uberwar
>
> $ # update configuration for production
> $ jar uvf myapp.war -C config/production .
>
> $ # or... update configuration for development server
> $ jar uvf myapp.war -C config/development .
>
> This assumes you have a ServletContextListener or equivalent in place
> to read on deployment.
>
> This is quick and dirty. I'd definitely like to see something better emerge.
>
> Allen
>
> On Mon, May 23, 2011 at 3:59 PM, Shantanu Kumar
>  wrote:
>> Hello Laurent, Quite interesting points there.
>>
>> Yes, I agree - having confidential config (production etc.) in code
>> base is not advisable. The reason I mentioned that though, was because
>> I was trying to cover a gamut of workflows the situation may demand.
>> One one extreme there may be a company where no developer gets to
>> touch production servers and must develop for a target config
>> constraint. On the other a set of developers who routinely deploy to
>> production and can get away with changing deployment practices on the
>> fly.
>>
>> What I would like to emphasize is to distinguish one environment from
>> the other (the code base may contain dummy config data in version
>> control.) A developer can change the dev config to a valid setup, and
>> similarly the person who builds for production deployment can change
>> the config locally (without committing the config details back to the
>> version control) and build a deployable bundle.
>>
>> An added level of indirection (where a config script loads details
>> from either a discoverable or a fixed resource) can bring some
>> flexibility -- the Ops guys can even edit config and re-start the app.
>> Though web container specific and servlet specific solutions are
>> useful for many cases, I am not sure I would recommend that as a
>> general practice -- for example, what am I to do if I have to deploy
>> my code to Netty/Aleph? IMHO ideally a Clojure webapp should be easily
>> buildable/deployable as a WAR (or EAR :-\) for web containers like
>> Tomcat/JBoss etc., but it may not depend on one.
>>
>> How to accomplish such builds where we cherry pick config stuff when
>> building for a certain environment (and how it integrates with the
>> development workflow) is a different aspect. I think I have seen
>> Apache Ant gives sufficient flexibility to do these things. Maybe
>> Leiningen can deliver some of the same things using plugins.
>>
>> Regards,
>> Shantanu
>>
>> On May 23, 12:48 pm, Laurent PETIT  wrote:
>>> Hello,
>>>
>>> Thanks for answering !
>>>
>>> My remarks follow:
>>>
>>> 2011/5/22 Shantanu Kumar :
>>>
>>> > I have wondered about this problem and at the first glance it looked
>>> > straightforward to me to put moving parts (config elements that could
>>> > change) into dynamic vars/atoms/refs. The production env can use the
>>> > default config, and anything else (dev, testing) can alter the default
>>> > config to override the settings.
>>>
>>> The idea of having production settings in the codebase as "default
>>> values" doesn't feel right to me -in general- (and in my particular
>>> case).
>>> Generally, some of these info are confidential, and their lifecycle
>>> does not match the lifecycle of the product.
>>>
>>> > The dev/testing should have different
>>> > entry point (may be in "test" directory, as opposed to "src") than the
>>> > prod version. That said, the config elements themselves can be loaded
>>> > from certain config files. If it's a web app, you can bundle co

Re: Passing "environment configuration parameters" to a Clojure web app

2011-05-23 Thread Allen Johnson
I'm also interested in this topic. It was discussed briefly on the
clojure-web-dev mailing list a little while ago. What I've been doing
is something like this:

# lein ring project
myapp/
  config/
production/WEB-INF/myapp.properties
development/WEB-INF/myapp.properties
test/WEB-INF/myapp.properties
  src/
  project.clj

$ # create war file
$ lein ring uberwar

$ # update configuration for production
$ jar uvf myapp.war -C config/production .

$ # or... update configuration for development server
$ jar uvf myapp.war -C config/development .

This assumes you have a ServletContextListener or equivalent in place
to read on deployment.

This is quick and dirty. I'd definitely like to see something better emerge.

Allen

On Mon, May 23, 2011 at 3:59 PM, Shantanu Kumar
 wrote:
> Hello Laurent, Quite interesting points there.
>
> Yes, I agree - having confidential config (production etc.) in code
> base is not advisable. The reason I mentioned that though, was because
> I was trying to cover a gamut of workflows the situation may demand.
> One one extreme there may be a company where no developer gets to
> touch production servers and must develop for a target config
> constraint. On the other a set of developers who routinely deploy to
> production and can get away with changing deployment practices on the
> fly.
>
> What I would like to emphasize is to distinguish one environment from
> the other (the code base may contain dummy config data in version
> control.) A developer can change the dev config to a valid setup, and
> similarly the person who builds for production deployment can change
> the config locally (without committing the config details back to the
> version control) and build a deployable bundle.
>
> An added level of indirection (where a config script loads details
> from either a discoverable or a fixed resource) can bring some
> flexibility -- the Ops guys can even edit config and re-start the app.
> Though web container specific and servlet specific solutions are
> useful for many cases, I am not sure I would recommend that as a
> general practice -- for example, what am I to do if I have to deploy
> my code to Netty/Aleph? IMHO ideally a Clojure webapp should be easily
> buildable/deployable as a WAR (or EAR :-\) for web containers like
> Tomcat/JBoss etc., but it may not depend on one.
>
> How to accomplish such builds where we cherry pick config stuff when
> building for a certain environment (and how it integrates with the
> development workflow) is a different aspect. I think I have seen
> Apache Ant gives sufficient flexibility to do these things. Maybe
> Leiningen can deliver some of the same things using plugins.
>
> Regards,
> Shantanu
>
> On May 23, 12:48 pm, Laurent PETIT  wrote:
>> Hello,
>>
>> Thanks for answering !
>>
>> My remarks follow:
>>
>> 2011/5/22 Shantanu Kumar :
>>
>> > I have wondered about this problem and at the first glance it looked
>> > straightforward to me to put moving parts (config elements that could
>> > change) into dynamic vars/atoms/refs. The production env can use the
>> > default config, and anything else (dev, testing) can alter the default
>> > config to override the settings.
>>
>> The idea of having production settings in the codebase as "default
>> values" doesn't feel right to me -in general- (and in my particular
>> case).
>> Generally, some of these info are confidential, and their lifecycle
>> does not match the lifecycle of the product.
>>
>> > The dev/testing should have different
>> > entry point (may be in "test" directory, as opposed to "src") than the
>> > prod version. That said, the config elements themselves can be loaded
>> > from certain config files. If it's a web app, you can bundle config in
>> > file(s) in WEB-INF and load from there on init -- now that leads to a
>> > complicated build process because you cherry pick the config file (for
>> > staging, prod or integration test?) for the build target.
>>
>> > Another complexity might arise where the config must be used to carry
>> > out certain stateful initialization to be useful to the app. How do
>> > you gracefully handle the errors? So we go back to some mutable flag
>> > that gives the go-ahead. Ugh!
>>
>> For what you describe, there are ways (as far as I remember) to manage
>> this with webapps, I think. By placing an HttpFilter/Listener in front
>> of the servlet, etc. (not sure about the details)
>>
>> > If the config element is common enough (e.g. database coords), it
>> > might make sense to go for convention-based settings that remains more
>> > or less the same. I have experimented a bit on this here:
>> >https://bitbucket.org/kumarshantanu/clj-dbcp/src(jump to the section
>> > "Create DataSource from .properties file") - I am interested in
>> > knowing what others think about this.
>>
>> Yes, to some extent convention settings can work. But it's not rare to
>> have some intermediate servers (dev's computer, test server) run on
>> e.g. Linux, and someti

Re: resultset-seq

2011-05-05 Thread Allen Johnson
> I don't think it's flexible enough to attach this to the connection. I
> work with databases where some groups of tables really need different
> naming strategies than others so I would definitely want these
> conversions available per operation - which is how c.j.j naming
> strategies currently work so it would be easy enough for folks to
> build something like Phlex suggests on top of what's already in c.j.j.

(inc)

> So it sounds like it would be useful to expose c.j.j's internal
> resultset-seq* function?

This has my vote.

> And given it's default behavior matches the core version, exposing it
> with the same name seems reasonable too since it won't break anyone's
> code (right?).

Won't break any of my stuff :)

Allen

> On Wed, May 4, 2011 at 4:06 PM, Phlex  wrote:
>>
>>
>> On 3/05/2011 23:58, Allen Johnson wrote:
>>>
>>> IMHO c.j.j/resultset-seq should perform something like the following:
>>>
>>> ;; i want my columns as strings exactly how they are in the db
>>> (resultset-seq rs)
>>> (resultset-seq rs identity)
>>>
>>> ;; i want my columns as lower-case keywords
>>> (resultset-seq rs (comp keyword lower-case))
>>>
>>> ;; i want my columns as upper-case symbols
>>> (resultset-seq rs (comp symbol upper-case))
>>>
>>> With the existing c.c/resultset-seq, I found myself converting the
>>> keys back to strings in order to pass those results to some existing
>>> Java code and templates for further processing. Most of the time the
>>> lower-cased keyword keys were just fine.
>>>
>>> Just my $0.02
>>> Allen
>>>
>> It would definitely be a plus to have some facilities for conversion from/to
>> clojure coding standard.
>> Not only for result sets but also for update functions and so on.
>>
>> I personally would prefer this as a default :
>> customer_id -> :customer-id (and the reverse)
>>
>> In a perfect world, it indeed would be best to have some control over this.
>> Maybe add this context as parameters to the connection object ?
>>
>> (with-connection {:classname "org.postgresql.driver"
>>            :subprotocol "postgresql"
>>            :subname (str "//" db-host ":" db-port "/" db-name)
>>            :user user
>>            :password password
>>            :field-names {:from-sql pascal-case->clojure ; or something like
>> this : (field-name-converter-fn :underscores :clojure-keyword)
>>                      :to-sql clojure->pascal-case}}
>>    (do-stuff))
>>
>> field-name-converter-fn being a multi-method returning a lambda that does
>> the conversion. One would be able to add his own methods, or simply use the
>> identity function.
>>
>> Sacha
>
> --
> 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 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


Re: resultset-seq

2011-05-05 Thread Allen Johnson
> How about extending java.sql.ResultSet to implement
> clojure.lang.Seqable instead?  Now that we have this capability
> wouldn't it be ideal to not have any more foo*-seq functions?

Since a ResultSet is also a resource that needs to be closed in a
timely manner it might be clearer to follow the same pattern as
line-seq.

(with-open [^ResultSet rs (exec-query ...)]
  (doseq [row (resultset-seq rs my-naming-strategy)]
(println (str "contact name: " (:name row)

Allen

> On May 5, 6:04 am, Sean Corfield  wrote:
>> I don't think it's flexible enough to attach this to the connection. I
>> work with databases where some groups of tables really need different
>> naming strategies than others so I would definitely want these
>> conversions available per operation - which is how c.j.j naming
>> strategies currently work so it would be easy enough for folks to
>> build something like Phlex suggests on top of what's already in c.j.j.
>>
>> So it sounds like it would be useful to expose c.j.j's internal
>> resultset-seq* function?
>>
>> And given it's default behavior matches the core version, exposing it
>> with the same name seems reasonable too since it won't break anyone's
>> code (right?).
>>
>> Sean
>>
>>
>>
>>
>>
>>
>>
>> On Wed, May 4, 2011 at 4:06 PM, Phlex  wrote:
>>
>> > On 3/05/2011 23:58, Allen Johnson wrote:
>>
>> >> IMHO c.j.j/resultset-seq should perform something like the following:
>>
>> >> ;; i want my columns as strings exactly how they are in the db
>> >> (resultset-seq rs)
>> >> (resultset-seq rs identity)
>>
>> >> ;; i want my columns as lower-case keywords
>> >> (resultset-seq rs (comp keyword lower-case))
>>
>> >> ;; i want my columns as upper-case symbols
>> >> (resultset-seq rs (comp symbol upper-case))
>>
>> >> With the existing c.c/resultset-seq, I found myself converting the
>> >> keys back to strings in order to pass those results to some existing
>> >> Java code and templates for further processing. Most of the time the
>> >> lower-cased keyword keys were just fine.
>>
>> >> Just my $0.02
>> >> Allen
>>
>> > It would definitely be a plus to have some facilities for conversion 
>> > from/to
>> > clojure coding standard.
>> > Not only for result sets but also for update functions and so on.
>>
>> > I personally would prefer this as a default :
>> > customer_id -> :customer-id (and the reverse)
>>
>> > In a perfect world, it indeed would be best to have some control over this.
>> > Maybe add this context as parameters to the connection object ?
>>
>> > (with-connection {:classname "org.postgresql.driver"
>> >            :subprotocol "postgresql"
>> >            :subname (str "//" db-host ":" db-port "/" db-name)
>> >            :user user
>> >            :password password
>> >            :field-names {:from-sql pascal-case->clojure ; or something like
>> > this : (field-name-converter-fn :underscores :clojure-keyword)
>> >                      :to-sql clojure->pascal-case}}
>> >    (do-stuff))
>>
>> > field-name-converter-fn being a multi-method returning a lambda that does
>> > the conversion. One would be able to add his own methods, or simply use the
>> > identity function.
>>
>> > Sacha
>
> --
> 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 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


Re: resultset-seq

2011-05-03 Thread Allen Johnson
IMHO c.j.j/resultset-seq should perform something like the following:

;; i want my columns as strings exactly how they are in the db
(resultset-seq rs)
(resultset-seq rs identity)

;; i want my columns as lower-case keywords
(resultset-seq rs (comp keyword lower-case))

;; i want my columns as upper-case symbols
(resultset-seq rs (comp symbol upper-case))

With the existing c.c/resultset-seq, I found myself converting the
keys back to strings in order to pass those results to some existing
Java code and templates for further processing. Most of the time the
lower-cased keyword keys were just fine.

Just my $0.02
Allen

On Tue, May 3, 2011 at 4:54 PM, Sean Corfield  wrote:
> Since this thread from October focused on clojure.core/resultset-seq,
> I thought I'd bump it again in the context of the (new)
> clojure.java.jdbc library (formerly clojure.contrib.sql).
>
> In order to support naming strategies, c.j.j uses an internal,
> modified copy of resultset-seq that allows you to control the way SQL
> entity names are converted to keywords. The default is still
> clojure.string/lower-case but you can override the behavior for calls
> to c.j.j. Naming strategies also allow you to control how keywords are
> converted to SQL entity names within c.j.j.
>
> I'm undecided on whether to expose this function (it's currently
> clojure.java.jdbc.internal/resultset-seq*) as part of the public API
> for c.j.j. In favor of exposing it: it would provide a way to get the
> behavior most people in this thread seem to want. Against exposing it:
> potential confusion with the version in clojure.core?
>
> This is the only decision I want to tie up before declaring a 0.0.1
> release of c.j.j (and moving on to other requested enhancements for
> 0.0.2).
>
> If anyone has any input...?
>
> Sean
>
> On Fri, Oct 15, 2010 at 2:04 PM, Laurent PETIT  
> wrote:
>>
>>
>> 2010/10/15 Mark Engelberg 
>>>
>>> On Fri, Oct 15, 2010 at 1:49 AM, David Powell 
>>> wrote:
>>> > I'm in favour of down-casing - at least by default.  Some processing is
>>> > going to happen anyway, as column names might contain spaces, which 
>>> > wouldn't
>>> > be allowed in keywords.
>>> >
>>> > --
>>> > Dave
>>>
>>> One of the more significant nuisances in Clojure/Java interop is that
>>> if you use some sort of wrapper library which converts Clojure things
>>> to Java, and then converts from Java back to Clojure, you often end up
>>> with something different than you started.  Anywhere we can ameliorate
>>> this, we should.
>>>
>>> For example, if I create a table using clojure.contrib.sql, where the
>>> column names are things like :numberOfApples, and then I load in a
>>> bunch of maps of the form {:numberOfApples 2}, {:numberOfApples 5},
>>> and so on, then when I fetch them out of the database, I really need
>>> them to be {:numberOfApples 2}, etc. so that I can compare them with
>>> the original maps used to fill the database to begin with.
>>>
>>> Right now, I get back {:numberofapples 2}.  Yes, SQL is usually case
>>> insensitive, but Clojure is not, so everything breaks down if you
>>> don't get back the maps in the form you started with.  Since SQL
>>> typically *stores* the column names internally in mixed case (even
>>> though it ignores the case for querying purposes), you might as well
>>> retrieve them in mixed case so it matches the form you started with.
>>>
>>> Why would I write my column names using mixed case?  Because I once
>>> tried using :number-of-apples to match Clojure's conventions, but got
>>> burned by a number of third-party tools gagging on the hyphens.
>>>
>>
>> I guess most of the time column names are written with
>> names_separated_by_underscores, but anyway, it seems indeed weird that such
>> downcase is done, especially without any (or to come) good reason for that.
>>
>>
>
> --
> 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 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


Re: clojure.org

2011-04-05 Thread Allen Johnson
Oops, didn't see this message from Stuart Sierra:

http://groups.google.com/group/clojure/browse_thread/thread/39adfb3ae7c4dab0

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


Re: clojure.org

2011-04-05 Thread Allen Johnson
> What's with http://clojure.org/ website? Is it expired?

I'm also having trouble accessing this. I receive a "Renew your domain
name now" page.

Allen

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


Re: Init timing for ring web servlet running on Jetty?

2011-03-31 Thread Allen Johnson
> Is there some way to convince Jetty (or tomcat, or ...) to run the
> init methods of a servlet before the first request comes in? Or maybe
> a pointer to the appropriate forum?

You can tell a servlet to init on startup with something like this in
your web.xml:


  test-servlet
  myapp.servlet
  1


This tells the container to initialize the servlet before any
requests. The number is just the ordering in which the servlets are
initialized.

Allen

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


Re: ANN: Clojure Toolbox (Early Beta)

2011-02-25 Thread Allen Johnson
> I'm sure I've covered only a very small proportion of Clojure
> libraries out there, so if you'd like to suggest a project that's not
> on there, please do so in this thread, or in an email to me. I'll try
> and update the site as quickly as possible.

How about: Messaging > WabbitMQ

https://github.com/mefesto/wabbitmq

Allen

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


Re: XML navigation puzzles

2011-02-04 Thread Allen Johnson
Here is my attempt using enlive:

(require '[net.cgrand.enlive-html :as html])
(import '[java.net URL]))

(def *url* "http://api.twitter.com/1/statuses/friends/barackobama.xml";)

(defn print-friends [url]
  (let [data (html/xml-resource (URL. url))]
(doseq [user (html/select data [:user])]
  (let [name (html/text (first (html/select user [:screen_name])))
id (html/text (first (html/select user [:id])))]
(println (str "username: " name " (" id ")"))

(print-friends *url*)

username: TruthSeekerZ1 (18346856)
username: davidaxelrod (244655353)
username: yankee13man (27474384)
username: carbo (14171957)
username: cadonato (27583520)
username: pfeiffer44 (131144091)
...

Hope that helps,
Allen

On Thu, Feb 3, 2011 at 5:25 PM, yiguang hu  wrote:
> Hello, Can some one show me how to navigate through xml?
>
> I am trying to have some fun with clojure and think of doing a simple
> xml navigation, it seems I didn't get the basics and not know how to
> do this simple thing in clojure.
>
> For example, I try to get the user id and name of all barackobama
> twitter friends. The following is as far as I can go and not know the
> best way to retrieve the id and name of each user.
>
> (let [users (clojure.xml/parse
> "http://api.twitter.com/1/statuses/friends/barackobama.xml";)]
> (:content users)
> )
>
> The following groovy scripts shows what I am trying to do:
>
> def data=new 
> XmlSlurper().parse("http://api.twitter.com/1/statuses/friends/barackobama.xml";)
> data.user.each{u->
> println u.screen_name.text()+" "+u.id.text()
> }
>
> It would do me a big favor to understand clojure if some one could
> show me how to do the above thing in clojure.
>
> Thanks
> Yiguang
>
> --
> 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 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


ANN: WabbitMQ v0.1.0

2011-02-03 Thread Allen Johnson
Hey everyone. WabbitMQ is a simple Clojure wrapper for RabbitMQ's Java
client v2.2.0. This is my first release and as such I'm sure there are
plenty of mistakes and/or non-clojure-isms. Feedback welcome! :)

https://github.com/mefesto/wabbitmq

Allen

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


Re: a loop gives boxing warning when it shouldn't

2011-01-02 Thread Allen Johnson
> I can't see where the variables are boxed into objects. Both the loop
> and the let declare them as primitives if they are given primitives.
> Perhaps they are already objects before they reach the inc and dec
> function calls in the recur, but if so, it's a mystery to me why.

Yeah that is interesting. I'm not sure the _why_ of it but I attempted
to narrow it down and it looks like it has something to do with nested
loops and recur. The code below is basically the same thing except the
first one generates auto-boxing warnings while the latter does not.
I'd also like to know why this is.

(set! *warn-on-reflection* true)

;; generates auto-boxing warnings
(defn example [^long x]
  (loop [a x]
(let [i (loop [k a] k)]
  (if false (recur i) i

;; no warnings
(defn example [^long x]
  (loop [a x]
(let [i (let [k a] k)]
  (if false (recur i) i

Also, I couldn't resist giving qsort another attempt. I got a new
laptop and need to break it in somehow :) So here is a rewritten
version based on an example in "Introduction to Algorithms" without
casts.

https://gist.github.com/763139

Allen

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


Re: a loop gives boxing warning when it shouldn't

2011-01-02 Thread Allen Johnson
Here is my attempt. I changed the divide to use unchecked-divide-int
and explicitly cast recur values to long.

http://clojure.pastebin.com/xs79ruw1

Allen

On Sat, Jan 1, 2011 at 5:47 PM, Albert Cardona  wrote:
> Hi all,
>
> I'd apreciate help on figuring out why a loop gets number boxing
> warnings, when it shouldn't:
>
> http://clojure.pastebin.com/9uLZqGhy
>
> I'm using clojure from:
>
> commit f30995c86056959abca53d0ca35dcb9cfa73e6e6
> Author: Stuart Halloway 
> Date:   Fri Dec 17 15:17:20 2010 -0500
>
> Thanks.
>
> Albert
>
> --
> http://albert.rierol.net
>
> --
> 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 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


Re: using aset in clojure-1.3-alpha4

2010-12-31 Thread Allen Johnson
Sorry I should have written 1.3.0-master-SNAPSHOT or whatever the
convention is that represents the latest master build :)


On Fri, Dec 31, 2010 at 11:21 AM, Sunil S Nandihalli
 wrote:
> Hi Allen ..
>  is 1.3.0 out? and I did not know that aset had so many variants.. glad I
> asked .. now I know .. :) thanks Allen.
> Sunil.
>
> On Fri, Dec 31, 2010 at 8:19 PM, Allen Johnson 
> wrote:
>>
>> This worked for me on 1.3.0:
>>
>> (aset-int (make-array Integer/TYPE 3 4 5) 1 2 3 -1)
>>
>> Might have something to do with the enhanced primitive support which
>> causes array handling to be stricter than it was in 1.2? Just a guess.
>>
>> Allen
>>
>> On Fri, Dec 31, 2010 at 8:53 AM, Sunil S Nandihalli
>>  wrote:
>> > Hello Everybody,
>> > why does this give an error in clojure-1.3-alpha4
>> >   (aset (make-array Integer/TYPE 3 4 5) 1 2 3 -1)
>> > can anybody tell me as to how to do this right?
>> > Thanks,
>> > Sunil.
>> >
>> > --
>> > 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 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 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 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


Re: using aset in clojure-1.3-alpha4

2010-12-31 Thread Allen Johnson
This worked for me on 1.3.0:

(aset-int (make-array Integer/TYPE 3 4 5) 1 2 3 -1)

Might have something to do with the enhanced primitive support which
causes array handling to be stricter than it was in 1.2? Just a guess.

Allen

On Fri, Dec 31, 2010 at 8:53 AM, Sunil S Nandihalli
 wrote:
> Hello Everybody,
> why does this give an error in clojure-1.3-alpha4
>   (aset (make-array Integer/TYPE 3 4 5) 1 2 3 -1)
> can anybody tell me as to how to do this right?
> Thanks,
> Sunil.
>
> --
> 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 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


Re: Soap Client

2010-12-29 Thread Allen Johnson
JAX-WS 2.1 is pretty good and included in Java 6.


On Wed, Dec 29, 2010 at 11:55 AM, Sean Devlin  wrote:
> Anyone know of a good soap client for Java?
>
> --
> 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 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


Re: requiring files

2010-12-29 Thread Allen Johnson
Perhaps it has something to do with the underscore in the namespace.
What if you try something like this in the repl:

(require 'project-name.foo)

(project-name.foo/my-fn)

Allen

On Wed, Dec 29, 2010 at 10:49 AM, Nicholas Wieland
 wrote:
> Hi *,
> I'm a bit ashamed but considering that I'm a newbie in Clojure and a total 
> newbie in Java there's apparently no end to this metanewbie status I'm 
> currently in :-)
> I'm trying to require a file and use it from the REPL, but every time I try 
> to call a function from this file Clojure is not able to resolve the symbol.
> What I did is creating a project using lein, and lein created a directory 
> structure that includes src/project_name, where I believe I'm supposed to put 
> my files.
> Now, other than the canonical core.clj I've created another file foo.clj. 
> There's still no interaction between the 2 files, but just as a matter of 
> testing what I'm writing I would like to be able to call the functions of 
> foo.clj from the REPL. The namespace is declared to be project_name.foo.
> I've tried to use both require and use inside lein repl, no matter what I do 
> it doesn't find the file (NO_SOURCE_FILE). If I understand the functioning 
> right I'm supposed to only use the namespace, so (:require project_name.foo) 
> should actually work and include the full namespace (that I translate 
> mentally with "file" :) inside the current one, that according to the repl is 
> project_name.core.
> Someone has a suggestion on where to look or how to fix ?
>
>  ngw
>
> --
> 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 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


Re: resultset-seq improvement: mapping column names

2010-12-06 Thread Allen Johnson
+1

On Fri, Dec 3, 2010 at 10:25 PM, ka  wrote:
> I'm also stuck with the same issues: 1. no option to get string keys
> 2. I don't understand, why do libs go through the trouble of
> downcasing ?
>
> Having said that I totally agree with the point Ryan makes: >> A
> greater feature of clojure is its extensibility.  What I am after is a
> generalization of the function in question, for greater
> interoperability with Java's SQL libraries.
>
> --
> 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 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


Re: REQUEST for feedback on http://clojure.org

2010-11-17 Thread Allen Johnson
I think annotations support was added in 1.2. Could we add some
information to the Java Interop section regarding this?

https://groups.google.com/group/clojure/browse_thread/thread/d2128e1505c0c117?pli=1

Allen

On Sat, Oct 30, 2010 at 10:38 PM, Alex Miller  wrote:
> Hi all,
>
> I'm doing a bit of doc cleanup on http://clojure.org and I'd welcome
> your feedback on things that are broken or could be improved.  I'm not
> looking (or likely authorized :) to make any drastic changes but if
> there are things that you have run into, please drop a line here or in
> email to alexdmiller at yahoo.com.  Ideally, I'd like people to be
> logging tickets in jira, but I'm not sure it's quite ready for that
> yet.
>
> Some recent changes I've already made:
> - switched all of the old richhickey github references to clojure
> - cleaned up some factually wrong or out of date stuff on getting
> started and download pages
> - added Protocol and Datatypes pages to left nav (the pages have
> existed for 6 months)
> - added a page on starting a user group (still in review, not yet
> linked)
> - currently working on updating the cheat sheet to the 1.2 version
> (and adding links!)
>
> I'm particularly interested in:
> - new user groups or suggestions for the community page
> - stuff that is just wrong or out of date
>
> This DOES NOT include stuff in the API or Contrib autodoc pages.
> Please raise those issues or file tickets on those but that's not what
> I'm focusing on at the moment.
>
> Alex
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To 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


Re: What is the best way to parasitically invade a java project with clojure goodness?

2010-08-23 Thread Allen Johnson
Oops,

s/create an instead/create an instance/

:)

On Mon, Aug 23, 2010 at 10:03 AM, Allen Johnson  wrote:
>> (:1 Should the clojure source files intermingle with the java source files,
>> each according to it's relavance to the problem, or should there be a top
>> level separation between them?)
>
> IMO, they should be separated. Since the project was started with Java
> I'd continue treating it as the top-level.
>
>> (:2 Say I have this:
>>     English.java --- which defines some cool data structure
>> representing English sentences
>>     Chinese.java --- same as above except for Chinese.
>>     awesome-junk.clj --- which provides unthinkably cool AI functions
>> that map English objects to Chinese objects. This is AOT compiled so
>> other things can use it.
>>     PainstakinglyMadeGUI.java --- which provides an awesome GUI that
>> uses the English and Chinese objects and calls the functions provided
>> by awesome-junk.
>>
>> Now, how can I build this project from nothing!?
>
> In the Java sources you can provide one or more java interfaces that
> describe the call contracts for awesome-junk.clj (IAwesomeJunk). All
> your Java code will depend on this interface and can be built first.
>
> Then you implement that interface in Clojure using gen-class or
> deftype/defrecord - which ever suits your needs best. These Clojure
> sources are built second and depend on the generated class files from
> your Java sources.
>
> Now at runtime, you can create an instead of the Clojure
> implementation of IAwesomeJunk and pass that to the Java classes that
> depend on it's functionality. A dependency injection framework makes
> this pretty simple but might be too heavy for what you need.
>
> So to summarize, IMO your build would have the following phases:
>
> 1. Compile Java Sources
> 2. Compile Clojure Sources (with step 1's classes available)
>
> You probably have even more options with defprotocol but I am not
> familiar enough.
>

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


Re: What is the best way to parasitically invade a java project with clojure goodness?

2010-08-23 Thread Allen Johnson
> (:1 Should the clojure source files intermingle with the java source files,
> each according to it's relavance to the problem, or should there be a top
> level separation between them?)

IMO, they should be separated. Since the project was started with Java
I'd continue treating it as the top-level.

> (:2 Say I have this:
>     English.java --- which defines some cool data structure
> representing English sentences
>     Chinese.java --- same as above except for Chinese.
>     awesome-junk.clj --- which provides unthinkably cool AI functions
> that map English objects to Chinese objects. This is AOT compiled so
> other things can use it.
>     PainstakinglyMadeGUI.java --- which provides an awesome GUI that
> uses the English and Chinese objects and calls the functions provided
> by awesome-junk.
>
> Now, how can I build this project from nothing!?

In the Java sources you can provide one or more java interfaces that
describe the call contracts for awesome-junk.clj (IAwesomeJunk). All
your Java code will depend on this interface and can be built first.

Then you implement that interface in Clojure using gen-class or
deftype/defrecord - which ever suits your needs best. These Clojure
sources are built second and depend on the generated class files from
your Java sources.

Now at runtime, you can create an instead of the Clojure
implementation of IAwesomeJunk and pass that to the Java classes that
depend on it's functionality. A dependency injection framework makes
this pretty simple but might be too heavy for what you need.

So to summarize, IMO your build would have the following phases:

1. Compile Java Sources
2. Compile Clojure Sources (with step 1's classes available)

You probably have even more options with defprotocol but I am not
familiar enough.

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


Re: cool compiler-project?

2010-08-19 Thread Allen Johnson
+1 on Dalvik compiler :)

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


Re: Databases for a Concurrent World

2010-07-10 Thread Allen Johnson
Here are my examples for mysql and postgres using commons-dbcp. They
are exactly the same except for the connection info. Might want to
play around with the initial,min,max size properties.

[MySQL]
http://gist.github.com/470901

[PostgreSQL]
http://gist.github.com/470904

Just download and include the following jars in the classpath:

http://commons.apache.org/dbcp/downloads.html
http://commons.apache.org/pool/downloads.html

Allen

On Sat, Jul 10, 2010 at 12:55 PM, Allen Johnson  wrote:
> To test with pooled DB connections I thought I'd mention Apache Commons
> dbcp. Its a generic connection pool library that could be used for any jdbc
> connection.
>
> I'd post a example clojure usage but I'm afk atm. The lib's BasicDataSource
> is probably all you'd need.
>
> Depends on Commons pool. Just place both jars on the classpath.
>
> http://commons.apache.org/dbcp/
>
> Allen
>
> On Jul 10, 2010 12:47 PM, "Toni Batchelli"  wrote:
> I think what you're doing is great. I understand you're using ab for
> these tests, right? What are the actual settings that you are using?
>
> Also, I'd like to mention that what these tests are showing is the
> behavior of the server under constant load (constant frequency in the
> arrival times of the requests, and constant load attached to each
> request). This is not what happens in reality though, and servers that
> do well under a constant distribution of requests might not do that
> well (at all) under a Pareto distribution of both arrival times and
> load (a real load that a server gets is very similar to a Pareto
> http://en.wikipedia.org/wiki/Pareto_distribution). Under a Pareto load
> a well crafted event-based server that has bounds on the number of
> threads used (and maybe other resources) might significantly
> outperform a 1-thread-per-request server. Unfortunately, I don't think
> ab can test these scenarios.
>
> I built a tool sometime ago while working at UCSB that would do
> exactly this. I will look into whether I can dig it out and opensource
> it.
>
> Toni.
>
>
> On Sat, Jul 10, 2010 at 8:59 AM, David Nolen  wrote:
>> On Fri, Jul 9, 2010...
>
> --
> Antoni Batchelli
> - twitter: @tbatchelli , @disclojure
> --- email: tbatche...@gmail.com
> - web: tbatchelli.org , disclojure.org
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To p...

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


Re: Databases for a Concurrent World

2010-07-10 Thread Allen Johnson
To test with pooled DB connections I thought I'd mention Apache Commons
dbcp. Its a generic connection pool library that could be used for any jdbc
connection.

I'd post a example clojure usage but I'm afk atm. The lib's BasicDataSource
is probably all you'd need.

Depends on Commons pool. Just place both jars on the classpath.

http://commons.apache.org/dbcp/

Allen

On Jul 10, 2010 12:47 PM, "Toni Batchelli"  wrote:
I think what you're doing is great. I understand you're using ab for
these tests, right? What are the actual settings that you are using?

Also, I'd like to mention that what these tests are showing is the
behavior of the server under constant load (constant frequency in the
arrival times of the requests, and constant load attached to each
request). This is not what happens in reality though, and servers that
do well under a constant distribution of requests might not do that
well (at all) under a Pareto distribution of both arrival times and
load (a real load that a server gets is very similar to a Pareto
http://en.wikipedia.org/wiki/Pareto_distribution). Under a Pareto load
a well crafted event-based server that has bounds on the number of
threads used (and maybe other resources) might significantly
outperform a 1-thread-per-request server. Unfortunately, I don't think
ab can test these scenarios.

I built a tool sometime ago while working at UCSB that would do
exactly this. I will look into whether I can dig it out and opensource
it.

Toni.



On Sat, Jul 10, 2010 at 8:59 AM, David Nolen  wrote:
> On Fri, Jul 9, 2010...
--
Antoni Batchelli
- twitter: @tbatchelli , @disclojure
--- email: tbatche...@gmail.com
- web: tbatchelli.org , disclojure.org


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To p...

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

Re: NullPointerException on disj

2010-05-27 Thread Allen Johnson
Opened ticket #360 for this.

https://www.assembla.com/spaces/clojure/support/tickets/360-nullpointerexception-on-disj

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


NullPointerException on disj

2010-05-26 Thread Allen Johnson
Hey everyone. I was playing around with the protocols/deftype stuff
and ran into a weird NullPointerException when calling the satisfies?
function. Seems to only happen with a java.lang.Object instance.

Clojure 1.2.0-master-SNAPSHOT
user=> (defprotocol Greeter (greet [this]))
Greeter
user=> (satisfies? Greeter nil)
false
user=> (satisfies? Greeter "")
false
user=> (satisfies? Greeter (Object.))
java.lang.NullPointerException (NO_SOURCE_FILE:0)

Narrowed it down to this function:

;; core_deftype.clj
(defn find-protocol-impl [protocol x]
  (if (instance? (:on-interface protocol) x)
x
(let [c (class x)
  impl #(get (:impls protocol) %)]
  (or (impl c)
  (and c (or (first (remove nil? (map impl (butlast (super-chain c)
 (when-let [t (reduce pref (filter impl (disj
(supers c) Object)))]
   (impl t))
 (impl Object)))

More specifically, here:

(disj (supers c) Object)

Since in this case, `c` is java.lang.Object, supers returns nil which
disj doesn't seem to like. Shouldn't disj handle nil gracefully?

Thanks,
Allen

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


Re: clojure.contrib.logging and Google App Engine

2010-04-25 Thread Allen Johnson
Sorry about the duplicated paragraph. My laptop touch pad is a pain.

On Sun, Apr 25, 2010 at 4:17 PM, Allen Johnson  wrote:
>> What seems to be happening is that when I build my 'gen-class' package, the
>> class is nailed down even though logging.clj itself is not gen-classed.
>
> I'm not familiar with GAE but as a workaround can you include the
> commons-logging.jar in your war file? Then configure commons-logging
> to delegate to java.util.logging.
>
> Otherwise, you could use java.util.logging directly. Remove
> clojure.contrib.logging from your servlet and import the java logging
> classes. You'd still want to configure the logger to use the provided
> name and not perform stack-inspection as noted in the
> clojure.contrib.logging description.
> Otherwise, you could use java.util.logging directly. Remove
> clojure.contrib.logging from your servlet and import the java logging
> classes. You'd still want to configure the logger to use the provided
> name and not perform stack-inspection as noted in the
> clojure.contrib.logging description.
>
> Ex.
> --
> (ns example.logging
>  (:import [java.util.logging Logger]))
>
> (def log (Logger/getLogger "logger.name"))
>
> (.info log "my log message")
>
> --
> Allen
>

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


Re: clojure.contrib.logging and Google App Engine

2010-04-25 Thread Allen Johnson
> What seems to be happening is that when I build my 'gen-class' package, the
> class is nailed down even though logging.clj itself is not gen-classed.

I'm not familiar with GAE but as a workaround can you include the
commons-logging.jar in your war file? Then configure commons-logging
to delegate to java.util.logging.

Otherwise, you could use java.util.logging directly. Remove
clojure.contrib.logging from your servlet and import the java logging
classes. You'd still want to configure the logger to use the provided
name and not perform stack-inspection as noted in the
clojure.contrib.logging description.
Otherwise, you could use java.util.logging directly. Remove
clojure.contrib.logging from your servlet and import the java logging
classes. You'd still want to configure the logger to use the provided
name and not perform stack-inspection as noted in the
clojure.contrib.logging description.

Ex.
--
(ns example.logging
  (:import [java.util.logging Logger]))

(def log (Logger/getLogger "logger.name"))

(.info log "my log message")

--
Allen

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


Re: idiomatic clojure of this java style ?

2010-04-24 Thread Allen Johnson
Oops, just saw the error in send-message as I replied. StatusMap
should (get recipient).

(defn send-message! [xmpp recipient body]
  (let [status (.sendMessage xmpp (create-message recipient body))
result (.. status getStatusMap (get recipient))]
(= SendResponse$Status/SUCCESS result)))

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


Re: idiomatic clojure of this java style ?

2010-04-24 Thread Allen Johnson
Here's my attempt. I don't think you can do much about the imperative
style when you are calling Java APIs unless someone was nice and wrote
a clojure wrapper. But I'm just a n00b.

---
(ns example.servlet.xmpp
  (:use[clojure.contrib.logging])
  (:import [xmpp.package.here XMPPServiceFactory MessageBuilder]
   [xmpp.package.here SendResponse SendResponse$Status])
  (:gen-class
   :extends javax.servlet.http.HttpServlet))

(defn create-message [recipient body]
  (let [builder (doto (MessageBuilder.)
  (.withRecipientJids recipient)
  (.witBody body))]
(.build builder)))

(defn send-message! [xmpp recipient body]
  (let [status (.sendMessage xmpp (create-message recipient body))
result (.. status getStatusMap (get from))]
(= SendResponse$Status/SUCCESS result)))

(defn -doPost [req res]
  (try
(let [xmpp (XMPPServiceFactory/getXMPPService)
  msg  (.parseMessage xmpp req)
  from (.getFromJid msg)
  body (.getBody msg)]
  (info (str "Received a message from " from  " and body " body))
  (if (send-message! xmpp from (str "You sent me: " body))
(info "Message has been sent successfully.")
(info "Message could not be sent.")))
(catch Exception e
  (fatal "Error sending message:" e

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


Re: JColorChooser

2010-03-22 Thread Allen Johnson
`showDialog` is a static method. Maybe something like below would work?

(JColorChooser/showDialog parent "Choose Color" bisque)

Allen

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: macro headaches

2009-12-15 Thread Allen Johnson
I'm just learning lisp but wouldn't a macro be overkill?

; manually add each item
(doseq [item items]
  (.add obj item))

; or wrapped in a function
(defn add-all [obj items]
  (doseq [item items]
(.add obj item)))

(add-all obj items)

If your java object had an addAll method that accepted a collection,
then you probably could do:

(.addAll obj items)

I'm wondering why you want it to be a macro?

Allen

On Tue, Dec 15, 2009 at 12:31 PM, tristan  wrote:
> Hi guys,
>
> I have a list (which i don't know the size of) and i want to do
> something like this:
> (doto (MutatingJavaObject.) (.add (first list-items)) (.add (second
> list-items)) . (.add (last list-items)))
>
> Now I may be doing this the complete wrong way, so if you have a
> better solution please tell me. but i've been trying to build a macro
> to expand this out, given the object, the function to call and the
> list of items.
>
> i've been playing with various things, and manage to get a few things
> that work if i pass the list of items in without being a list (i.e. (1
> 1 1) rather than '(1 1 1) or (list 1 1 1)) for example (defmacro d2
> [obj func inputs] (concat (list 'doto obj) (map #(list func %)
> inputs))) but if i try and pass in my list-items variable it just
> complains that it "Don't know how to create ISeq from:
> clojure.lang.Symbol".
>
> perhaps i'm not fully grasping the concept of macros? i'm very new to
> lisp and FP in general.
>
> while writing this email i had a light switch on that i could simply
> do it like this:
> (let [obj (MutatingJavaObject.)]
>  (loop [in list-items]
>    (when (not (empty? in))
>      (.add obj (first in))
>      (recur (rest in
>  obj)
> but i would still like to know if there is a way i could get the macro
> i wanted going.
>
> please help! my googling and trauling through Stuart Halloway's book
> have come up naught.
>
> thanks in advance!
> -Tristan
>
> --
> 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 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


Re: macro headaches

2009-12-15 Thread Allen Johnson
I think I misunderstood you. Battling a cold so I'm sorry if I'm way
off here but did you want a macro like this?

(defmacro my-doall [obj func-sym items]
  (let [func-name (symbol (str "." (name func-sym)))
item (gensym)]
`(doseq [~item ~items]
   (~func-name ~obj ~item

(my-doall obj add ["item1" "item2" "item3"])

Allen

On Tue, Dec 15, 2009 at 1:04 PM, Allen Johnson  wrote:
> I'm just learning lisp but wouldn't a macro be overkill?
>
> ; manually add each item
> (doseq [item items]
>  (.add obj item))
>
> ; or wrapped in a function
> (defn add-all [obj items]
>  (doseq [item items]
>    (.add obj item)))
>
> (add-all obj items)
>
> If your java object had an addAll method that accepted a collection,
> then you probably could do:
>
> (.addAll obj items)
>
> I'm wondering why you want it to be a macro?
>
> Allen
>
> On Tue, Dec 15, 2009 at 12:31 PM, tristan  wrote:
>> Hi guys,
>>
>> I have a list (which i don't know the size of) and i want to do
>> something like this:
>> (doto (MutatingJavaObject.) (.add (first list-items)) (.add (second
>> list-items)) . (.add (last list-items)))
>>
>> Now I may be doing this the complete wrong way, so if you have a
>> better solution please tell me. but i've been trying to build a macro
>> to expand this out, given the object, the function to call and the
>> list of items.
>>
>> i've been playing with various things, and manage to get a few things
>> that work if i pass the list of items in without being a list (i.e. (1
>> 1 1) rather than '(1 1 1) or (list 1 1 1)) for example (defmacro d2
>> [obj func inputs] (concat (list 'doto obj) (map #(list func %)
>> inputs))) but if i try and pass in my list-items variable it just
>> complains that it "Don't know how to create ISeq from:
>> clojure.lang.Symbol".
>>
>> perhaps i'm not fully grasping the concept of macros? i'm very new to
>> lisp and FP in general.
>>
>> while writing this email i had a light switch on that i could simply
>> do it like this:
>> (let [obj (MutatingJavaObject.)]
>>  (loop [in list-items]
>>    (when (not (empty? in))
>>      (.add obj (first in))
>>      (recur (rest in
>>  obj)
>> but i would still like to know if there is a way i could get the macro
>> i wanted going.
>>
>> please help! my googling and trauling through Stuart Halloway's book
>> have come up naught.
>>
>> thanks in advance!
>> -Tristan
>>
>> --
>> 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 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