JRuby is an implementation of the Ruby programming language in Java. The common Ruby implementation is in C. So what is so cool another implementation of Ruby in Java?
Well, I did several small applications in Java, and it was my language of choice for some time now. Java is Free, and lots of IDE's are free, like eclipse, and netbeans. Java has millions of free libraries for almost anything. Java can be used on the server with jsp, j2ee and on the client with Swing. So it's an all-in-one language.
So, having a Ruby implementation in Java, you can leverage your Java code, and use the elegance and beauty, and fun of coding in Ruby. You can extend your Java classes using Ruby, and you can automate some of the high level work for your applications using Ruby.
Another GREAT news is that JRuby is now endorsed, and officially supported by Sun. The core JRuby developers are paid by Sun. Way to go Sun!
There are some nice tutorials in the JRuby site. I'll try that out myself and see how far I can go with JRuby.
When a Tandem, or HP NSK program crashes, it creates a memory dump file called a SAVEABEND file. When my brain crashes, it adds an entry to this blog.
Saturday, September 09, 2006
Thursday, September 07, 2006
Ruby Oneliners
Ruby can be very useful for performing some rapid and powerful operations on files. The Ruby syntax is much more user friendly than awk or sed, especially if you are familiar with Ruby.
The one liners can be found here.
If you are running on Windows, then substitute type for cat.
As an example, Here is a handy oneliner
Note that the command
Another useful oneliner is the following:
The above oneliners depend on the $ Ruby global variables. Here are some of the most commonly used:
Have fun.
The one liners can be found here.
If you are running on Windows, then substitute type for cat.
As an example, Here is a handy oneliner
# delete leading whitespace (spaces/tabs/etc) from beginning of each line
$ cat| ruby -pe 'gsub(/^\s+/, "")'
Note that the command
ruby -pewill execute the Ruby commands that follow it on each input line, and sends the output to STDOUT. To capture the output you can use the Linux/Unix or DOS > char.
Another useful oneliner is the following:
# print line number 52
$ cat| ruby -pe 'next unless $. == 52'
The above oneliners depend on the $ Ruby global variables. Here are some of the most commonly used:
$! error message
$@ position of an error occurrence
$_ latest read string by `gets'
$. latest read number of line by interpreter
$& latest matched string by the regexep.
$1, $2... latest matched string by nth parentheses of regexp.
$~ data for latest match for regexp
$= whether or not case-sensitive in string matching
$/ input record separator
$\ output record separator
$0 the name of the ruby script file
$* command line arguments for the ruby script
$$ PID for ruby interpreter
$? status of the latest executed child process
Have fun.
Wednesday, September 06, 2006
The Story of the Mexican Fisherman
In line with my previous post about the movie Click, I recalled an interesting email I got some time ago. Thank's too Google, Here it is again/ (Copied from here)
An American investment banker was at the pier of a small coastal Mexican village when a small boat with just one fisherman docked. Inside the small boat were several large yellowfin tuna. The American complimented the Mexican on the quality of his fish and asked how long it took to catch them.
The Mexican replied, "only a little while."
The American then asked why didn't he stay out longer and catch more fish?
The Mexican said he had enough to support his family's immediate needs.
The American then asked, "but what do you do with the rest of your time?"
The Mexican fisherman said, "I sleep late, fish a little, play with my children, take siestas with my wife, Maria, stroll into the village each evening where I sip wine, and play guitar with my amigos. I have a full and busy life."
The American scoffed, "I am a Harvard MBA and could help you. You should spend more time fishing and with the proceeds, buy a bigger boat. With the proceeds from the bigger boat, you could buy several boats, eventually you would have a fleet of fishing boats. Instead of selling your catch to a middleman you would sell directly to the processor, eventually opening your own cannery. You would control the product, processing, and distribution. You would need to leave this small coastal fishing village and move to Mexico City, then LA and eventually New York City, where you will run your expanding enterprise."
The Mexican fisherman asked, "But, how long will this all take?"
To which the American replied, "15 - 20 years."
"But what then?" Asked the Mexican.
The American laughed and said, "That's the best part. When the time is right you would announce an IPO and sell your company stock to the public and become very rich, you would make millions!"
"Millions - then what?"
The American said, "Then you would retire. Move to a small coastal fishing village where you would sleep late, fish a little, play with your kids, take siestas with your wife, stroll to the village in the evenings where you could sip wine and play your guitar with your amigos."
An American investment banker was at the pier of a small coastal Mexican village when a small boat with just one fisherman docked. Inside the small boat were several large yellowfin tuna. The American complimented the Mexican on the quality of his fish and asked how long it took to catch them.
The Mexican replied, "only a little while."
The American then asked why didn't he stay out longer and catch more fish?
The Mexican said he had enough to support his family's immediate needs.
The American then asked, "but what do you do with the rest of your time?"
The Mexican fisherman said, "I sleep late, fish a little, play with my children, take siestas with my wife, Maria, stroll into the village each evening where I sip wine, and play guitar with my amigos. I have a full and busy life."
The American scoffed, "I am a Harvard MBA and could help you. You should spend more time fishing and with the proceeds, buy a bigger boat. With the proceeds from the bigger boat, you could buy several boats, eventually you would have a fleet of fishing boats. Instead of selling your catch to a middleman you would sell directly to the processor, eventually opening your own cannery. You would control the product, processing, and distribution. You would need to leave this small coastal fishing village and move to Mexico City, then LA and eventually New York City, where you will run your expanding enterprise."
The Mexican fisherman asked, "But, how long will this all take?"
To which the American replied, "15 - 20 years."
"But what then?" Asked the Mexican.
The American laughed and said, "That's the best part. When the time is right you would announce an IPO and sell your company stock to the public and become very rich, you would make millions!"
"Millions - then what?"
The American said, "Then you would retire. Move to a small coastal fishing village where you would sleep late, fish a little, play with your kids, take siestas with your wife, stroll to the village in the evenings where you could sip wine and play your guitar with your amigos."
Monday, September 04, 2006
Click, Fast farward, rewind
I just came back from the movie Click. It's a nice 'n' easy Adam Sandler Movie. The movie seems a bit shallow, and the points it wants to show are obvious. There are no big twisters, no big surprise at the end. But still, it got me thinking of my own life.
I was talking about the same subject after lunch with my family before going for the move. We talked about how some people struggle so hard to "get a better life for my kids", but forget that they are losing their own life. Time can never be brought back... One should enjoy the journey, not just the goal.
In a job like IT, we tend to work so hard, and "fast forward" through life, missing many of it's moments that we can never get back.
Get your priorities right. Mine is my family.
I was talking about the same subject after lunch with my family before going for the move. We talked about how some people struggle so hard to "get a better life for my kids", but forget that they are losing their own life. Time can never be brought back... One should enjoy the journey, not just the goal.
In a job like IT, we tend to work so hard, and "fast forward" through life, missing many of it's moments that we can never get back.
Get your priorities right. Mine is my family.
Subscribe to:
Posts (Atom)