Wednesday, September 30, 2009

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 ProjectsThe 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):

IDE SupportAptana 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.

TestingThere 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."

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. ConclusionIf Rails is the drug, Ruby is the addiction!!

Monday, September 28, 2009

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.

Invalid file

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 18, 2009

Get 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

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.

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

Sunday, September 13, 2009

Business DelegateThe 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.

Tuesday, September 08, 2009

Consider trying http://tryruby.sophrinix.com/ 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

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:

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

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.

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 application.properties file:-app.version=0.1