Groovy and Ruby
Up till now I have used Ruby for the odd scripting job, just to get into the language as it were. One script I use regularly is a one that opens a url a 100 times and sleeps for a few seconds in between. Here is the Ruby code:
require 'net/http'
require 'uri'
response = ''
for i in 0 ... 100
puts(i)
url = URI.parse('http://localhost:8080/frontier/batchProcess.html')
res = Net::HTTP.start(url.host, url.port) {|http|
response=http.get('/frontier/batchProcess.html')
}
puts(response)
sleep(10);
end
as I have gone all Groovy, I decided to re-write this in Groovy. It is very similar but slightly more familiar for us Java herberts:
println "start"
for(i in 1..100) {
url = new URL("http://localhost:8080/frontier/batchProcess.html")
s = url.getText()
println s
println "sleeping ${i}"
sleep(2000)
}
println "stop"
I think that familiarity could be key.
Finally, I had some friends over on the week and they spotted my “Groovy Programming book”. Oh how they laughed and pointed at me. Sigh.
2 Responses to “Groovy and Ruby”
Leave a Reply
May 9th, 2010 at 10:12 pm
If you are in uncomfortable position and have got no money to get out from that point, you will have to receive the loans. Because that will help you definitely. I get credit loan every time I need and feel myself OK because of it.