Wednesday, September 30, 2009


I am capturing some conversation from JavaRanch on Ruby:-

Performance Ruby v Java

Ruby vs Java

It would take 5 min to read this as well.

Why Ruby?

Ruby is a strongly, but dynamically, typed, "dynamic," object oriented programming language. That's the official spiel but I suspect that's just a list of buzzwords to many. Being practical, if you're familiar with Python, it's a little like that in terms of its scope (i.e. not high performance, can be used as a "scripting" language, object oriented). Ruby is often called a "pure" object oriented language because everything is an object. This is not strictly true (e.g. a lot of the basic syntax isn't OO) but is a good way to compare it with other languages.

Ruby isn't verbose (if you consider Java to be a 7 out of 10 on the verbosity scale, Ruby's perhaps a 2) and it "gets out of the way" and lets you simply code your logic and features with as little architectural work as necessary (of course, if you want to, you can write Ruby in a very anal way, but it's not necessary to start with).

Inspiration (similar languages)
Python is quite similar to Ruby in some ways, but it's not quite as dynamic and consistent. Ruby takes a lot of influence from Smalltalk, so that's going to be quite similar too.

Major Projects
The Human Genome project uses Ruby and RoR. Check out some slides on the project here
. See this list of some companies that use Ruby/Rails. Frank Carver used a great quote describing Ruby (low ceremony). Ruby feels a lot less like "coding", and more like "trying out ideas".

As far as the Rails framework itself, it's a lot of the things you DON'T do:

configure the webapp
parse xml to objects/ objects to xml/json/html
write a ton of validations
type and tune a bunch of SQL (DDL or queries)
hand-write Ajax or Prototype
bind form elements, parse URL parameters
spend time searching for existing solutions only to have to search out their dependencies (this jar needs these three jars which need...)
pluralize, singularize, capitalize, camelize, humanize, turn into a sentence, format date and time
configure dev v test v prod environments

Plus, you get a lot of advantages that come with using Rails (or gems along with rails):

restful services/web-app urls
easy gem integration
great testing support (unit, functional, integration, performance)
rails application bootstraps (boostrap a: social media site, blog, etc)
a vibrant community
ever expanding platforms (JRuby/Java, IronRuby/.net, etc)
unobtrusive JavaScript (soon)
deployment with capistrano

IDE Support
Aptana RadRails is probably the way to go. It's based on Eclipse. Despite the name it's not just for Rails development and can be used for pure Ruby development if you want. It's a reasonable IDE as long as you like Eclipse

More celebrated is JetBrains' (of IntelliJ IDEA fame) RubyMine but it's a commercial product. I suspect a lot of Java-heads will love it though, and it gets the best reviews overall. I don't use it because I'm cheap.

Ruby In Steel is definitely a good option on Windows. I've given it a go and it feels really nice. Despite not being a Windows user anymore, I still appreciate how well constructed Visual Studio is I wish there were an IDE as good as VS on other platforms. Eclipse just doesn't cut it for me.

There are a lot of ways to do testing, load testing, and Web application testing from Ruby. The Ruby community seems to be a little bit nuts over testing - almost religious about it - so the number of testing libraries is.. quite large for the size of the community ;-)

One of the best known libraries is Watir. To steal some info: "Watir is an open-source library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible. Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page. Watir is a family of Ruby libraries. They support Internet Explorer on Windows, Firefox on Windows, Mac and Linux, Safari on Mac, Chrome on Windows and Flash testing with Firefox."

There's also an attempt to port Selenium to Ruby.

If you want something that's lower level and doesn't rely on a browser, there's also WebRat which provides an API for mechanizing Web requests and browser features using Ruby methods. With this you can put together scripts to perform whatever actions are necessary on your sites.

Deployment and Hosting

"Deploying Rails Applications: A Step-by-Step Guide by Ezra Zygmuntowicz, Bruce Tate, and Clinton Begin" is a popular book to understand the deployment process in detail. Here is another link to understand deployment process in Ruby-on-Rails application. Either you use JRuby or not. Mongrel and Apache are the popular Web Servers I know. This link describes the Popular Web Hosts for Rails

Passenger, a.k.a. mod_rails or mod_rack, is the most common way to deploy Rails (and other Ruby web framework) applications nowadays. It works on both Apache and nginx. It's reliable, good with memory, and runs like a champ. It's easy to install on your own Apache-powered server, of course, but some shared hosts run it too, such as Dreamhost. An older technique is to use fcgi/FastCGI. Most hosts are moving to Passenger, but it's still possible to deploy apps via FastCGI and on some setups it works just great.

If Rails is the drug, Ruby is the addiction!!


  2. (JavaRanch Ruby Forum)

Monday, September 28, 2009

Google Docs now performs OCR!!

Google is constantly working on new features for their online services like Gmail or Google Docs. The latest feature is currently available as a demonstration only and not yet integrated into Google Docs. The Google Docs OCR demonstration can OCR the three digital image formats jpg, png and gif. Google lists the following limitations that are currently in place:

  • Files must be fairly high-resolution — rule of thumb is 10 pixel character height.
  • Maximum file size: 10MB, maximum resolution: 25 mega pixel
  • The larger the file, the longer the OCR operation will take (500K: ~15s, 2MB: ~40s, 10MB: forever)

You can upload an image containing typewritten or printed text (like a fax document or a scanned newspaper clipping) to your Google Docs account and it will turn that image into editable text. The quality depends largely on the quality of the image. It is usually necessary to look over the text and correct errors that have been made during character recognition. Google Docs helps in the error correction by underlining unknown words in red in its interface. It still takes some time to correct the errors.

I am providing steps to get started and sample image provided by Google. Here is a sample form to upload scanned images to your Google Account and the server will automatically try to extract text from these images provided the image resolution is good and that the text inside images is written using Latin character sets.





HTTP.jpg provided by Google for testing



Unfortunately, when I tried it I received the following error:-

Error processing document:
Expected response code 200, got 400 <?XML:NAMESPACE PREFIX = [default] NS = "" />GData InvalidEntryException Could not convert document.


Invalid file

Please chose a JPG, GIF or PNG file not larger than 10 MB/25 mega pixel.

The OCR feature can also extract text from noisy images as well (like this WSJ clipping) though the recognized text is not very accurate and the document formatting is lost (see conversion results).

If you are a developer, you can add the ocr=true parameter to your upload request and Google Docs will automatically scan that image for text patterns. You can also upload images to Google Docs without the OCR parameter but in that case, the image will be converted into a new Word document minus OCR.

Like Google Docs, Google Search too includes OCR features but the difference is that while Google Docs can extract text from images, the OCR in Google Search works only with scanned PDF files.

Friday, September 25, 2009

Format code in Windows Live Writer

I never got the Code Snippet plugin for Windows Live Writer to work. Below is the error on my system:-


Rather the Source Code plugin works like a charm:-

Formats following languages (Wilco Bauwers Syntax Highlighting):
ASPX, C, C#, C++, COBOL, Cold Fusion, CSS, Eiffel, Fortran, Haskell, Java, JavaScript, JScript, Mercury, MSIL, Pascal, Perl, PHP, Python, Ruby, SQL, Visual Basic, Visual Basic Script, XML.
In addition it provides live preview and options to adjust background color, border color, font size, and box width.
UPDATED: Line Numbering, Alternating Line Style, tab replacement, selection ...
Source code can be found at


Simple format of Java code

public class SourceCodeFormatter
    /* Member 1 */
    public static string member1;
    /* Member 2 */
    private int member2;
    // Constructor
    public SourceCodeFormatter()


Insert box around code and line numbers

  1: public class SourceCodeFormatter
  3: {
  5:     /* Member 1 */
  7:     public static string member1;
  9:     /* Member 2 */
 11:     private int member2;
 13:     // Constructor
 15:     public SourceCodeFormatter()
 17:     {
 19:     }
 21: }

Alternating colors + selection:-

public class SourceCodeFormatter
    /* Member 1 */
    public static string member1;
    /* Member 2 */
    private int member2;
    // Constructor
    public SourceCodeFormatter()


No more escaping and formatting code!!

Monday, September 21, 2009

No wireless networks were found in range

If you play with Windows and especially Services you will find the following screen very familiar:

Wireless networks

I especially turn to my Dell Wireless Utility to manage wireless network when I find that my laptop is not able to find networks in range

Dell Wireless Utility

But after tons of research, I figured out that this is basically a direct effect of toying with the Services and disabling the “Event Logs”

To fix this follow the following steps:

1. Go to Start->Settings->Control Panel->Administrative Tools->Services


2. Right click “Event Log” go to Properties


3. Change start type to “Automatic” and click Apply

Event Log

4. The start button is now enabled. Click on the “Start” button

Event Log

5. Restart your PC and you will be able to see wireless networks in range.


Thus, this is a direct effect of disabling the Event Logs.

Friday, September 18, 2009

Proven Anti-virus for free

Microsoft Security EssentialsGet high-quality, hassle-free antivirus protection for your home PC now.

Microsoft Security Essentials provides real-time protection for your home PC that guards against viruses, spyware, and other malicious software.

Microsoft Security Essentials is a free* download from Microsoft that is simple to install, easy to use, and always kept up to date so you can be assured your PC is protected by the latest technology. It’s easy to tell if your PC is secure — when you’re green, you’re good. It’s that simple.

Microsoft Security Essentials runs quietly and efficiently in the background so that you are free to use your Windows-based PC the way you want—without interruptions or long computer wait times.

Learn more at the Microsoft Malware Protection Center

Find information, definitions, and analyses of all the latest threats that Microsoft Security Essentials can help protect you against in the Microsoft Malware Protection Center

Need security for your business?
Protect your computers with Microsoft Forefront Client Security

Key Features
  • Comprehensive malware protection
  • Simple, free download*
  • Automatic updates
  • Easy to use

*Your PC must run genuine Windows to install Microsoft Security Essentials. Learn more about genuine

System Requirements

Operating System: Genuine Windows XP (Service Pack 2 or Service Pack 3); Windows Vista (Gold, Service Pack 1, or Service Pack 2); Windows 7

  • For Windows XP, a PC with a CPU clock speed of 500 MHz or higher, and 1 GB RAM or higher.
  • For Windows Vista and Windows 7, a PC with a CPU clock speed of 1.0 GHz or higher, and 1 GB RAM or higher.
  • VGA display of 800 × 600 or higher.
  • 140 MB of available hard disk space.
  • An Internet connection is required for installation and to download the latest virus and spyware definitions for Microsoft Security Essentials.
  • Internet Browser:
    • Windows Internet Explorer 6.0 or later.
    • Mozilla Firefox 2.0 or later.
  • Microsoft Security Essentials also supports Windows XP Mode in Windows 7. For more information see the system requirements for Windows XP Mode in Windows 7


Watch videos to help you get the most from Microsoft Security Essentials.


Get step-by-step instructions on how to quickly install Microsoft Security Essentials. Watch now Watch now


Learn how to do an on-demand scan for viruses. Watch now Watch now

Fix a problem

Find out how to address a threat when detected. Watch now Watch now

Maintain history with a trigger

It is very easy to create a trigger history table without modifying the applications inserting/updating or deleting from the core table. In my case, I had to maintain a history of MAIN_ORDER_PROCESS_PARAMS table without modifying the application. MAIN_ORDER_PROCESS_PARAM_HIST is my slave (history) table which silently copies records on update/ delete from the code table.

It is important to note that DATE_CHANGED should be made a primary key in the history table. Also, another important point is that the insert/update to core table should also update DATE_CHANGED.

Trigger History

You may modify the procedure to also capture current record or inserts.

MESSAGE VARCHAR2 (1000) := ' ';
PURPOSE: To record the changes to the MAIN_ORDER_PROCESS_PARAMS table
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 09/16/2009 VMS 1. Created this trigger.
  BMS_OUTPUT.put_line ('ERROR: ' || MESSAGE);
  html_email ('email address','ARCHIVE_MOPP','Error encountered in ARCHIVE_MOPP trigger','Error encountered in ARCHIVE_MOPP trigger',MESSAGE); 
  /*I have it set to send email to our group if errors are encountered*/

Sunday, September 13, 2009

Session Façade v Business Delegate

Business Delegate
The business delegate and session façade patterns are similar, but their motivations are different.

The business delegate motivation is to decouple the presentation/web tier and the business tier. When you make changes to the interface of objects in your business tier, the changes can be handled in the business delegate--without requiring the deployment of an updated presentation/web object.

If you are trying to decouple the presentation/web and business tiers, you will implicitly be using a business delegate pattern to do it.

Business Delegate is to reduce coupling between client and business objects. One of the basic example is, if you use a method from business object in your clients, let say in 10 servlets, if the method signature changes on the business object, you have to change in all(10) your client places(of course, IDE can easily refactor it, but it will be complicated if the project is very big). To avoid this, have a layer of classes/interfaces which have the methods corresponding to each business object.

Session Façade
Facade(s) act as common entry points to business services. They also help reduce network traffic by eliminating the need for the clients to invoke multiple fine-grained methods.
Business delegates( and delegates in general ) provide a clean way for the clients to interact with the service layer. They hide complex things such as service lookups, error handling, remoteness of the service etc. They can also implement additional services such as client caching, thread synchronization, service selection and request routing.


Session Facade is to reduce the number of network calls made from client to business objects. As you said, if you implement the business logic in your Business Delegate layer, you will be making multiple fine grained calls to your business objects to complete a Use Case. Network calls are expensive and must be reduced. So instead of implementing the business logic in clients, implement it in business object layer and send required data as a bundle(coarse grained).

The session façade motivation is to simplify the interaction between presentation/web tier and the business tier. For example: If you had three business objects that had methods named cutTheGreenWire, cutTheBlueWire, and cutTheRedWire, your session façade object would like have a method disarmTheBomb that took care of whether or not each method was called, the order in which those methods were called, the time between each method call, and so forth.

Thursday, September 10, 2009

Larry Ellison to Sun Customers – “We’re in it to win it”

Here is an advertisement from today’s (Sep 10, 2009) Wall Street Journal (also here)

Also find out why Oracle + Sun is faster than IBM on Oct 14.

Tuesday, September 08, 2009

Getting Started and Learning Yet Another Language : Ruby

Try Ruby - in your browser!!

Consider trying if you want to have a quick play with a Ruby interpreter. There's a short tutorial built into it too. It's a great way to give it a try without doing any installations!

Sunday, September 06, 2009

File download in grails

I was reviewing the Grails 1.1 Web Application Development book. In the section wherein we are putting in the logic for downloading files, we are given directions for updating the FileController. As is, it will not work quite properly in Firefox (on Windows, anyway) when downloading files with embedded spaces in their names. The fix is quite simple. Here is the line as specified on page 149:

response.setHeader("Content-Disposition", "attachment; filename=${file.downloadName}")

Changing this to:
response.setHeader("Content-Disposition", /attachment; filename="${file.downloadName}"/)

will assure that the proper file name is used. Here I used Groovy's slashy strings and surrounded the filename in double quotes. This fix was tested not only in Firefox, but also IE, Google Chrome, Opera and Safari, all on Windows XP.

Friday, September 04, 2009

Escape HTML Characters in Blogger post

If you use Blogger's GUI editor and want to use some special characters (<>) or HTML code and use the Blogger HTML GUI editor then you would be in a shock. You would expect it to escape <> if you copy and paste it. Obviously, if you're in GUI mode and you type <>, you want to see <>.

Blogger's system simply keeps the <> intact and does not escape the HTML code. It also tries to validate your HTML and "fix" it and will insert and add extra elements.

The only solution is to use escape characters. I found an Online HTML Escape Character. Of course the best option is to type your post in a desktop HTML editor (like Dreamweaver), then view the HTML source and copy/paste that into Blogger.

The online HTML escape character tool is used to embed html code into the webpage as it is, without being transformed into html elements. The same for php or javascript code. Escape HTML Characters tool is very easy to use, just paste the code into the box and push the bottom button.

Remove version from grails war file name

Grails by default creates strange looking war files ApplicationName-0.1.war. I am not able to deploy the files on Tomcat with the trailing -0.1 since Tomcat thinks the application context is http://hostname/ApplicationName-0.1 when it is just http://hostname/ApplicationName

Remove the following line from file:-

My looks like

And now grails prod war generates ApplicationName.war

Wednesday, September 02, 2009

JavaScript to control mouse cursor

The following JavaScript can be used to change the cursor to an hourglass while the form is being submitted.'wait'

Example form:-

<form action=\"\" method=\"POST\" onsubmit=\"\'wait\';
javascript:return releaseButtonClicked();\">

To return back to the original cursor view you can use:-'auto';