<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>It's not a blog, It's a feature &#187; code</title>
	<atom:link href="http://javazquez.com/juan/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://javazquez.com/juan</link>
	<description>Juan A. Vazquez</description>
	<lastBuildDate>Wed, 16 Nov 2011 02:45:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Groovy project using Gradle</title>
		<link>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/</link>
		<comments>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 02:40:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Gradle]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=378</guid>
		<description><![CDATA[Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.]]></description>
			<content:encoded><![CDATA[<p>Hello fellow Groovyists <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have been kicking the tires on using Gradle for my Groovy projects. I had a few stumbles along the way and wanted to share what I came up with for getting a very simple example working.</p>
<p>build.gradle<br />
<code><br />
apply plugin: 'groovy'<br />
version = "1.0-${new Date().format('yyyyMMdd')}"</p>
<p>manifest.mainAttributes("Main-Class" : "com.javazquez.HelloThere")</p>
<p>repositories {<br />
    mavenCentral()<br />
	mavenRepo urls: "http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"<br />
}<br />
dependencies {<br />
	groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.4'<br />
	groovy group: 'org.mongodb', name: 'mongo-java-driver', version: '2.6.5'<br />
	groovy group: 'com.gmongo', name: 'gmongo', version: '0.9.1'<br />
	testCompile "org.spockframework:spock-core:0.5-groovy-1.8"<br />
}</p>
<p>jar {<br />
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }<br />
}<br />
</code></p>
<p>below is the the HelloThere.groovy file located src/main/groovy/com/javazquez/HelloThere<br />
<code><br />
package com.javazquez<br />
public class HelloThere {</p>
<p>    public static void main(String []args) {<br />
        println "Hello coders!"</p>
<p>    }    </p>
<p>}<br />
</code></p>
<p>after running <strong>gradle build</strong>, I can navigate to the build/libs directory and run <strong>java -jar HelloThere-1.0-20111115.jar </strong> and get the following ouptut</p>
<p>Hello coders!</p>
<p>Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POP3 Gmail access with Clojure and JavaMail</title>
		<link>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/</link>
		<comments>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:44:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google api]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[javamail]]></category>
		<category><![CDATA[pop3]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=357</guid>
		<description><![CDATA[I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful Enjoy (use '[clojure.contrib.duck-streams]) (def props (System/getProperties)) ; Get the default Session object. (def session (javax.mail.Session/getDefaultInstance props)) ; Get a Store [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful  Enjoy <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code><br />
(use '[clojure.contrib.duck-streams])<br />
(def props (System/getProperties))<br />
  ; Get the default Session object.<br />
  (def session (javax.mail.Session/getDefaultInstance props))</p>
<p>  ; Get a Store object that implements the specified protocol.<br />
  (def store (.getStore session "pop3s"))</p>
<p>  ;Connect to the current host using the specified username and password.<br />
  (.connect store "pop.gmail.com" "username@gmail.com" "password")</p>
<p>  ;Create a Folder object corresponding to the given name.<br />
  (def folder (. store getFolder "inbox"))</p>
<p>  ; Open the Folder.<br />
(.open folder (javax.mail.Folder/READ_ONLY ))<br />
  ; Get the messages from the server<br />
  (def messages (.getMessages folder))</p>
<p>   (defn getFrom [message](javax.mail.internet.InternetAddress/toString (.getFrom message)))<br />
   (defn getReplyTo [message] (javax.mail.internet.InternetAddress/toString (.getReplyTo message)) )<br />
   (defn getSubject [message] (.getSubject message))</p>
<p>   ;print out the body of the message<br />
      (for [m messages] (read-lines(.getInputStream m)) )</p>
<p>;;;;;code for sending an email</p>
<p>(def props (System/getProperties))<br />
(. props put "mail.smtp.host", "smtp.gmail.com")<br />
(. props put "mail.smtp.port", "465")<br />
(. props put "mail.smtp.auth", "true")<br />
(. props put "mail.transport.protocol", "smtps")</p>
<p>(def session (javax.mail.Session/getDefaultInstance props nil))<br />
(def msg (javax.mail.internet.MimeMessage. session))<br />
(. msg setFrom (javax.mail.internet.InternetAddress. "sender@gmail.com"))<br />
(. msg addRecipients javax.mail.Message$RecipientType/TO<br />
   "receiver@gmail.com") </p>
<p>(. msg  setSubject "i am the subject")<br />
(. msg setText "I am the body!!!")</p>
<p>(. msg setHeader "X-Mailer", "msgsend")<br />
(. msg setSentDate (java.util.Date.))</p>
<p>    ; send the email<br />
(def transport (. session getTransport))<br />
(. transport connect "smtp.gmail.com" 465 "sender@gmail.com" "password")<br />
(. transport sendMessage msg (. msg getRecipients javax.mail.Message$RecipientType/TO))<br />
(. transport close)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a PayPal SOAP client with Java 6</title>
		<link>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/</link>
		<comments>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 02:50:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consume]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=318</guid>
		<description><![CDATA[I have always been mystified on the inner workings of SOAP. That was until I learned about the "wsimport" utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal's Sandbox. This code will execute the SetExpressCheckout API call. ]]></description>
			<content:encoded><![CDATA[<p>I have always been mystified on the inner workings of SOAP. That was until I learned about the &#8220;wsimport&#8221; utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal&#8217;s Sandbox. This code will execute the SetExpressCheckout API call. </p>
<p>Just enter the following on your command line to generate the com.javazquez package</p>
<p><strong>wsimport -keep -XadditionalHeaders -Xnocompile -p com.javazquez http://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl</strong></p>
<p>open your favorite java editor(I used eclipse) and add the package(“com.javazquez”..created in the above command) to your new project </p>
<p>next, write some code to test out the APIs<br />
<code><br />
package com.javazquez;</p>
<p>import javax.xml.ws.Holder;<br />
public class TestEC {</p>
<p>	public static void main(String[] args) {<br />
         SetExpressCheckoutReq req = new SetExpressCheckoutReq();<br />
         SetExpressCheckoutRequestType reqType = new SetExpressCheckoutRequestType();<br />
         SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();<br />
         AddressType addr = new AddressType();<br />
         addr.cityName = "omaha";<br />
         addr.street1 = "123 main";<br />
         addr.country = CountryCodeType.US;<br />
         addr.name = "joe tester";</p>
<p>         details.address = addr;<br />
         details.orderTotal = new BasicAmountType();<br />
         details.orderTotal.currencyID = CurrencyCodeType.USD;<br />
         details.orderTotal.value = "1.00";<br />
         details.cancelURL = "http://javazquez.com/cancel";<br />
         details.returnURL = "http://javazquez.com/return";</p>
<p>         reqType.setVersion("2.10");</p>
<p>         reqType.setExpressCheckoutRequestDetails = details;<br />
         req.setSetExpressCheckoutRequest(reqType);</p>
<p>         UserIdPasswordType user = new UserIdPasswordType();<br />
         user.username = "XXX";<br />
         user.password = "XXXX";<br />
         user.signature = "XXXX";</p>
<p>         PayPalAPIInterfaceService pp = new PayPalAPIInterfaceService();<br />
         PayPalAPIAAInterface pinterface = pp.getPayPalAPIAA();<br />
         Holder<CustomSecurityHeaderType> security = new Holder(new CustomSecurityHeaderType());<br />
         security.value.setCredentials(user);<br />
         try{<br />
               SetExpressCheckoutResponseType resp = pinterface.setExpressCheckout(req, security);<br />
               System.out.println(resp.token);<br />
               System.out.println(resp.correlationID);<br />
               for(ErrorType msg: resp.errors){<br />
                     System.out.println(msg.longMessage);<br />
               }<br />
         }<br />
         catch(Exception ex){<br />
               System.out.println(ex.getMessage());</p>
<p>         }<br />
	}</p>
<p>}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(def Bonjour-Clojure &#8220;Welcome to functional programming&#8221;)</title>
		<link>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/</link>
		<comments>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 20:54:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=285</guid>
		<description><![CDATA[This post will follow my usual getting started with a language snippets.<br/><br/> 

(defn count-consonants [string] (count ( re-seq  #"[^aeiouAEIOU\s]" string )))
<br/> 
(defn count-vowels [string] (count ( re-seq  #"[aeiouAEIOU\s]" string )))
<br/> 
;read a file into a list.. any suggestions on other ways are welcome :)<br/> 
;usage (file-lines "string_path_to_file")<br/> 
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))
<br/> ]]></description>
			<content:encoded><![CDATA[<p>After the briefest of introductions to functional programming in college(a la Lisp) and dabbling with Scala, I took the functional plunge and started using Clojure recently. At this point, I have only written a couple of small programs and haven&#8217;t formed much of an opinion on where it stacks against my current favorite language at the moment(Groovy). This post will follow my usual getting started with a language snippets. I plan to write more entries as I get more familiar with the language.  On to the code!</p>
<p>&#8212;<br />
;binding<br />
user=> (def Bonjour-Clojure &#8220;Welcome to functional programming&#8221;)<br />
#&#8217;user/Bonjour-Clojure<br />
user=> Bonjour-Clojure<br />
&#8220;Welcome to functional programming&#8221;</p>
<p>;items in a list can be seperated via a comma or white space..<br />
user=> (= [ 1 2 3] [1,2,3])<br />
true</p>
<p>;count the number of consonants in a string<br />
(defn count-consonants [string] (count ( re-seq  #&#8221;[^aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-consonants &#8220;writing code is fun&#8221;)<br />
10</p>
<p>;count the number of vowels in a string<br />
(defn count-vowels [string] (count ( re-seq  #&#8221;[aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-vowels &#8220;lukaskiewicz&#8221;)<br />
5</p>
<p>;read a file into a list.. any suggestions on other ways are welcome <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
;usage (file-lines &#8220;string_path_to_file&#8221;) or to read a webpage ((file-lines &#8220;http://javazquez.com&#8221;)<br />
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))</p>
<p>;view objects class<br />
user=>(class &#8220;Im a string&#8221;)<br />
java.lang.String</p>
<p>;length of string<br />
user=>(count &#8220;I am 18 chars long&#8221;)<br />
18</p>
<p>user=>(range 1 9)<br />
(1 2 3 4 5 6 7 8 )</p>
<p>;repeat a digit<br />
user=>(repeat 4 3)<br />
(3 3 3 3)</p>
<p>;list comprehension<br />
user=>(for [fruit ["apple" "orange" "grape"] ] (str fruit))<br />
(&#8220;apple&#8221; &#8220;orange&#8221; &#8220;grape&#8221;)</p>
<p>;use map to create a new list&#8230; #() is a shortcut for an anonymous<br />
user=>(map #(* 2 %1) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>; also an anonymous function<br />
user=> (map (fn [item](* 2 item)) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>;simple fiter example on a list using odd?<br />
user=> (filter odd? [1, 2,3,4,5])<br />
(1 3 5)</p>
<p>;factorial using reduce<br />
user=> (reduce * [1 2 3])<br />
6</p>
<p>;if statement<br />
user=> (if true (str &#8220;i am true&#8221;)(str &#8220;i am false&#8221;))<br />
&#8220;i am true&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login with Basic Authentication using Groovy</title>
		<link>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/</link>
		<comments>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 02:21:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=278</guid>
		<description><![CDATA[Hey there fellow Groovyists! I was recently in need of performing Basic Authentication on Apache using Groovy for a proof of concept. Below is what I was able to quickly put together. //Here is a quick groovy 1.7.4 Basic Auth Example @Grab(group=&#8217;org.codehaus.groovy.modules.http-builder&#8217;, module=&#8217;http-builder&#8217;, version=&#8217;0.5.0&#8242; ) def authSite = new groovyx.net.http.HTTPBuilder( &#8216;http://10.110.201.115/~juanvazquez/basicAuth/&#8217; ) authSite.auth.basic &#8216;user&#8217;, &#8216;pwd&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>Hey there fellow Groovyists! I was recently in need of performing Basic Authentication on <a href="http://www.webreference.com/programming/apache_authentication/">Apache</a> using Groovy for a proof of concept. Below is what I was able to quickly put together.</p>
<p>//Here is a quick groovy 1.7.4 Basic Auth Example<br />
@Grab(group=&#8217;org.codehaus.groovy.modules.http-builder&#8217;, module=&#8217;http-builder&#8217;, version=&#8217;0.5.0&#8242; )</p>
<p>def authSite = new groovyx.net.http.HTTPBuilder( &#8216;http://10.110.201.115/~juanvazquez/basicAuth/&#8217; )<br />
authSite.auth.basic &#8216;user&#8217;, &#8216;pwd&#8217;<br />
println authSite.get( path:&#8217;testAuth.html&#8217; )</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Python</title>
		<link>http://javazquez.com/juan/2010/08/31/python-quickstart/</link>
		<comments>http://javazquez.com/juan/2010/08/31/python-quickstart/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 03:28:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=240</guid>
		<description><![CDATA[Hey there fellow developers I have been working with Python lately(specifically Python3) and wanted to share some things I thought were pretty cool from an outsider&#8217;s(learning the language) perspective. I hope the following helps with getting to know this great language.. Enjoy #construct a tuple using() t=(1,2,3) #contruct a list using [] lst= [1,2,4] #iterate [...]]]></description>
			<content:encoded><![CDATA[<p>Hey there fellow developers <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
I have been working with Python lately(specifically Python3) and wanted to share some things I thought were pretty cool from an outsider&#8217;s(learning the language) perspective.  I hope the following helps with getting to know this great language.. Enjoy </p>
<pre>
<code>
#construct a tuple using()
t=(1,2,3)

#contruct a list using []
 lst= [1,2,4]

#iterate a string and print each character
for i in "This is a String":
	print(i)

#getting the length of a string
print ("length is",len("12345"))	

#test x is in a range
x=6
if(3< x <10 ):
	print( "I am true")
else:
	print( "I am false")

#test membership

if "2" in "1234":
	print("I am in the string")
if int("2") in [1,2,3,4]:
	print( "I am in the list")

#replication
print( "hithreetimes, "*3)

#using math class
import math
print(math.sqrt(4))

#print all methods
print(dir(math))

#named Tuples
import collections
Movie = collections.namedtuple("Movie","title rating")
collection =[Movie("Jaws", 4.0)]
collection.append(Movie("Toy Story", 5.0))
for movie in collection:
	print("I watched {0} and gave it {1} stars".format(movie.title,movie.rating))

#sequence unpacking
head, *rest = [1,2,3,4,5]
print("head is {0} and rest is {1}".format(head,rest))

#passing and unpacking parameters
def fullname(f,m,l):
	print("First Name ="+f)
	print("Middle Name ="+m)
        print("Last Name  ="l)

fakenamelist =["Homer","J","Simpson"]
fullname(*fakenamelist)		

#list comprehensions (print all odd numbers from 0 to 99)
print( [item for item in range(0,100) if item % 2])

#named parameters
def count_animals(number,*,	animal="ducks"):
	return "{0} {1}".format(number,animal)
print( count_animals(3,animal="cows"))
print( count_animals(3))

print(sorted([-1,2,-3],key=abs)) #same order

line = input("enter something.. ")
print("your line was " ,line)

</code>
</pre>
<p>I have been using python for web requests and recommend using the <a href="http://code.google.com/p/httplib2/">httplib2 library</a>. It has a lot of really nice features. </p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2010/08/31/python-quickstart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby&#8217;s variable variables</title>
		<link>http://javazquez.com/juan/2009/08/31/rubys-variable-variables/</link>
		<comments>http://javazquez.com/juan/2009/08/31/rubys-variable-variables/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 02:13:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=229</guid>
		<description><![CDATA[Hello everyone, This is a quick post that should help developers new to Ruby. It may also help out those that have been away from the language for a while. Its just a quick reference to Ruby&#8217;s variables and their respective scopes. I know I had a chart to keep it all straight when I [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>This is a quick post that should help developers new to Ruby. It may also help out those that have been away from the language for a while. Its just a quick reference to Ruby&#8217;s variables and their respective scopes. I know I had a chart to keep it all straight when I first encountered the language.</p>
<ol>
<li>@ 	 An instance variable</li>
<li>[a-z] or _ 	A local variable</li>
<li>[A-Z] 	A constant</li>
<li>@@	A class variable</li>
<li>$ 	A global variable</li>
</ol>
<p>This information is easily found on the net if you know what you are looking for. I just posted it to help make it even easier to find for those that are new to Ruby, or new to code writing <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/08/31/rubys-variable-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows GUI File Parser using Groovy</title>
		<link>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/</link>
		<comments>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 19:53:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[DND]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[java swing]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=221</guid>
		<description><![CDATA[I find myself doing a lot of file parsing on my Windows XP machine lately. I decide to write a quick utility that would allow me to drag and drop files and search for the key words that I have identified. The utility doesn&#8217;t have the logic for searching using regex&#8217;s yet, but it should [...]]]></description>
			<content:encoded><![CDATA[<p>   I find myself doing a lot of file parsing on my Windows XP machine lately. I decide to write a quick utility that would allow me to drag and drop files and search for the key words that I have identified. The utility doesn&#8217;t have the logic for searching using regex&#8217;s yet, but it should be really easy to add this functionality. </p>
<p> I hacked some Groovy Code with some Java Code and came up with the following script. Hope it is useful.</p>
<p><strong>DISCLAIMER:</strong></p>
<p>  As the title suggests, I have only been able to get this to work on my Windows XP machine, OS X didn&#8217;t like the <strong> javax.swing.TransferHandler </strong>and it appears some other operating systems have a hard time with this also.</p>
<p><code><br />
import java.awt.datatransfer.DataFlavor;<br />
import java.awt.datatransfer.Transferable;<br />
import java.awt.datatransfer.UnsupportedFlavorException;<br />
import java.io.File;<br />
import java.io.IOException;<br />
import java.security.NoSuchAlgorithmException;<br />
import java.util.List;<br />
import java.awt.BorderLayout;<br />
import java.awt.*;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.ActionEvent;<br />
import javax.swing.JFrame;<br />
import javax.swing.JPanel;<br />
import javax.swing.JLabel;<br />
import javax.swing.JButton;<br />
import javax.swing.JTextArea;<br />
import javax.swing.JTextField;<br />
import javax.swing.TransferHandler.*;</p>
<p>class FileDropHandler extends TransferHandler {</p>
<p>	private static final long serialVersionUID = 1L;</p>
<p>	def wordsToFind =[]<br />
	JTextArea output<br />
	private JLabel errorMsg;<br />
	private String fileText = "";<br />
	private boolean test = false;<br />
	private boolean same = true;</p>
<p>	public boolean canImport(TransferSupport supp) {<br />
	/* for the demo, we'll only support drops (not clipboard paste) */<br />
	if (!supp.isDrop()) {<br />
		return false;<br />
	}</p>
<p>	/* return false if the drop doesn't contain a list of files */<br />
	if (!supp.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {<br />
	return false;<br />
	}</p>
<p>	boolean copySupported = (COPY &#038; supp.getSourceDropActions()) == COPY;</p>
<p>	if (copySupported) {<br />
	supp.setDropAction(COPY);<br />
	return true;<br />
	}</p>
<p>	return false;<br />
	}</p>
<p>	public boolean importData(TransferSupport supp) {<br />
	if (!canImport(supp)) {<br />
	return false;<br />
	}</p>
<p>	/* get the Transferable */<br />
	Transferable t = supp.getTransferable();</p>
<p>	try {</p>
<p>	Object data = t.getTransferData(DataFlavor.javaFileListFlavor);</p>
<p>	List fileList = (List) data;</p>
<p>	for (int j = 0; j < fileList.size(); j++) {</p>
<p>	File file = (File) fileList.get(j);<br />
	//file.getAbsolutePath()<br />
	def tmpfh = new File("FileParser.txt")<br />
	println wordsToFind.inspect()<br />
	 new File(file.getAbsolutePath()).eachLine{line-><br />
	   wordsToFind.each{   if(line =~ "${it}" ){<br />
	        println "${line}"<br />
	        tmpfh.append(line)<br />
	        tmpfh.append("\n\n")<br />
			this.output.setText(this.output.getText()+line+"\n")<br />
	   }<br />
	  }<br />
	 }//end for</p>
<p>	tmpfh.close()</p>
<p>	}<br />
	} catch (UnsupportedFlavorException e) {<br />
	return false;<br />
	} catch (IOException e) {<br />
	return false;<br />
	} catch (NoSuchAlgorithmException e) {<br />
	// TODO Auto-generated catch block<br />
	e.printStackTrace();<br />
	}</p>
<p>	return true;<br />
	}</p>
<p>	public void setOutput(JTextArea jta) {<br />
	this.output = jta;<br />
	}</p>
<p>	public void setOutput(JLabel jta) {<br />
	errorMsg = jta;<br />
	}</p>
<p>	public String getText() {<br />
	return fileText;<br />
	}</p>
<p>	public void clearAll() {<br />
	fileText = "";<br />
	test = false;<br />
	same = true;</p>
<p>	}<br />
}</p>
<p>class AL implements ActionListener{<br />
   public JTextField jtf<br />
   public FileDropHandler dh<br />
    public AL(JTextField jtf,FileDropHandler dh){<br />
     this.jtf = jtf<br />
     this.dh =dh<br />
    }<br />
    public void actionPerformed(ActionEvent actionEvent){<br />
        println "${this.jtf.getText()}"<br />
        dh.wordsToFind= this.jtf.getText().split(' ')<br />
        }<br />
}</p>
<p>JTextArea dTextArea = new JTextArea("Drop on me");<br />
FileDropHandler dh = new FileDropHandler()<br />
dh.setOutput(dTextArea)<br />
JTextField jta = new JTextField("Enter words seperated by spaces")<br />
dh.wordsToFind= jta.getText().split(' ')<br />
JButton jb =new JButton("Update Word List")<br />
jb.addActionListener( new AL(jta ,dh  ))</p>
<p>dh.setOutput(dTextArea);<br />
dTextArea.setDragEnabled(true);<br />
dTextArea.setTransferHandler(dh);</p>
<p>JPanel p =new JPanel(new BorderLayout());<br />
JFrame f = new JFrame()<br />
p.add(jta, BorderLayout.NORTH)<br />
p.add(dTextArea, BorderLayout.CENTER)<br />
p.add(jb, BorderLayout.SOUTH)</p>
<p>f.getContentPane().add(p)<br />
f.setSize(400,400)<br />
f.setVisible(true)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Groovy Flickr API</title>
		<link>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/</link>
		<comments>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 16:19:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Flickr]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[java swing]]></category>
		<category><![CDATA[pictures]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=204</guid>
		<description><![CDATA[The hardest part of the whole thing was figuring out how to post images to Fickr, for that, I used the flickrj code as reference. If it was not for the available source code, I don't think I would have ever figured it out. So a big thanks to all the folks working on that project!]]></description>
			<content:encoded><![CDATA[<p>     A long time ago I wanted to write a desktop GUI interface for Flickr. At the time I had just learned Java and thought it would be really cool to write it using swing. Little did I know how not cool working with swing would be <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  </p>
<p>     About halfway through the project I heard about a cool new dynamic way to write Java code called Groovy. From that day on Groovy has been making my life a whole lot easier. I didn&#8217;t need all the functionality in the flickrj library, so I decide to write a few methods for my app using Groovy. The hardest part of the whole thing was figuring out how to post images to Flickr, for that, I used the flickrj code as a reference. If that source code was not available, I don&#8217;t think I would have ever figured it out. So a big thanks to all the folks working on that project!</p>
<p>This is not a complete API for Flickr, but should provide enough to get started.<br />
<a href="http://github.com/javazquez/glickr">Link to my GitHub Repo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding and Resizing Images with Grails</title>
		<link>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/</link>
		<comments>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 18:58:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[imageTools]]></category>
		<category><![CDATA[pictures]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=179</guid>
		<description><![CDATA[Just wanted to provided a working example for those that are entering the Grails territory for the first time.]]></description>
			<content:encoded><![CDATA[<p>Here is a quick post on how to upload images within your Grails project to your file system(rather than your database). It seems simple enough, but I ran into a few snags as I was working on one of my projects. Just wanted to provided a working example for those that are entering the Grails territory for the first time. Happy Coding!</p>
<p>I am using the imageTools plugin which you can read more about <a href="http://grails.org/ImageTools+plugin">here</a> </p>
<p><strong>NOTE: </strong>The imageTools plugin has been criticized for its low quality of output. ImageMagick may be a better fit for you project(s). My particular project didn&#8217;t call for high quality pictures. A quick google search for &#8220;imagemagick for grails&#8221; should get you started on your way.</p>
<p>I am using version 1.0.3 in the example below</p>
<p><strong>to install, I ran the following command from my grails application&#8217;s root directory</strong></p>
<p><code>grails install-plugin http://www.arquetipos.co.cr/blog/files/grails-image-tools-1.0.3.zip</code></p>
<p><strong>Domain-Class</strong><br />
<code><br />
class Picture {<br />
byte[] imagefile<br />
//Any other stuff you want to track</p>
<p>}<br />
</code></p>
<p><strong>Controller Code for Saving an image</strong><br />
<code><br />
    def save = {</p>
<p>		def downloadedfile = request.getFile('imagefile')<br />
	 	def pictureInstance = new Picture(params)<br />
		def imageTool = new ImageTool()</p>
<p>     	       if(downloadedfile &#038;&#038; pictureInstance.save()){<br />
			String imagepath = grailsAttributes.getApplicationContext().getResource("images/").getFile().toString() + 	File.separatorChar + "${pictureInstance.id}.jpg"<br />
			downloadedfile.transferTo(new File(imagepath))</p>
<p>			imageTool.load(imagepath)<br />
			imageTool.thumbnail(140)</p>
<p>			imageTool.writeResult(imagepath, "JPEG")<br />
			imageTool.square()<br />
            flash.message = "Picture ${pictureInstance.id} created"<br />
            redirect(action:show,id:pictureInstance.id)<br />
        }<br />
        else {<br />
           render(view:'create',model:[pictureInstance:pictureInstance])<br />
        }<br />
    }<br />
</code><br />
<strong>Code for displaying the image in both the &#8216;show&#8217; and &#8216;list&#8217; views</strong><br />
<code><br />
	&lt;td&gt;&lt;img  src="${createLinkTo(dir:'images', file: pictureInstance.id+'.jpg' )}" /&gt; &lt;/td&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

