Tuesday, July 21, 2009

A non-ruby post about marketing tips

Goggling about some Ruby thing, I came across a nice article on Marketing Tips. I was forced to share these beautiful thoughts ....

http://www.webdesignerdepot.com/2009/07/9-marketing-tips-from-a-six-year-olds-lemonade-stand/

Wednesday, July 1, 2009

Installing Rails plugin from Github on Windows

One more pain when coding on windows (as if I was born using Unix/Linux etc ;)))... but try installing a plugin -

ruby script/plugin install git://github.com/toamitkumar/extra_sanitize.git

and it will fail with an empty folder.

After googling found a way -> here which suggests using http instead of git protocol.

ruby script/plugin install http://github.com/toamitkumar/extra_sanitize.git

Well this also failed with an empty folder. After hours of struggling found adding a trailing forward slash to the url did the trick.

ruby script/plugin install http://github.com/toamitkumar/extra_sanitize.git/

It works now....

Saturday, June 20, 2009

Extra Sanitize your models

We have been using xss_sanitize, which is nicely bundled plugin. You drop it in your Rails application and rest the plugin takes care of protecting from XSS attacks. In our project, we found issues dealing with other special characters like -> microsoft single-double quotes, asterisk, percentage, tilda, angular brackets, question mark etc.

These characters cause extra pain to handle when they appear in urls. You have to encode/decode them. Rolled out a simple but effective plugin. It does nothing but puts an extra layer of sanitization on top of xss_terminate. Yes it is independent of xss_terminate and you can just use it.

Check the project page for usage.

Tuesday, June 16, 2009

Factory Girl - fixtures replacement for focussed and readable tests

Why Factory Girl:
  1. Fixtures separates the data we are testing with actual behavior
  2. Makes tests brittle and you have to look at fixture files to understand the tests, which is certainly not the intent for the tests
  3. Its painful to have fixtures maintained for each model
  4. You have to keep switching between files to see what fixtures there are, always struggling with dependencies and conflicts
How to get started:
  1. gem install thoughtbot-factory_girl --source http://gems.github.com
  2. Add the following code to your test environment file ---> config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => http://gems.github.com
  3. Add test/factories.rb if using UnitTesting framework or spec/factories.rb if using Rspec framework. It will be automatically loaded if defined at this location
  4. Ryan Bates has an excellent screencast @ http://railscasts.com/episodes/158-factories-not-fixtures
  5. Excellent documentation

Saturday, June 6, 2009

GitHub - growing Social Network for Programmers

GitHub is Public Open Source Git repository that's being called "Social Network" for programmers. Lets understand Git first.

Git is a distributed version control system co-developed by Linus Torvalds that has speed and efficiency. Git does away with the idea of a central repository. In Git every user has a complete copy of the repository data stored locally which makes accessibility easy and fast even when the n/w is disconnected. This seems radical to the concept of Subversion or other VCS (Version Control Systems) we have been using where the central repo has complete history (which makes it slow and inefficient). Git users have to push and fetch changes with each other. If any repository is lost due to system failure only the changes which were unique to that repository are lost. Once that system comes up it does push/fetch to update/get the changes. Git is extermely fast for all operations (except push and fetch), perform a diff, view file history, commit changes, merge braches, obtain any other revision of file, switch branches etc.

GitHub uses Git as a core technology while extending its basic ideas into the direction of social networking and publication. Everything you do with your source code on GitHub becomes a Web resource, complete with its own URL. Github is a pay service but it also offers free package which are suitable for many open source projects. GitHub really comes together for most users when you start talking about the social features. Every user and project has a profile. For ex: Amit Kumar (its me) is my profile page and Ruby on Rails is project profile page. The project profile page keeps track of progress and participation. Both users and projects profile page also have public activity feeds which display activity on public projects such as commits, comments, forks, etc. Users can follow specific developers or projects to keep tabs on the activity.

Getting started with github is very easy. The screencasts and podcasts are wonderful resources. Getting git and github on windows is a little timetaking but with msysgit latest version has made life easy. Github provides a beautiful of the master code and all the forks.


It lets you see everyone else who’s cloned a particular repo, and what changes they have made. The big benefit is that this prevents you from re-inventing the wheel when you see that someone is already working on the same feature you’re trying to submit. Instead of going and doing your own thing, you fork off of them and work with them. You might even fork off of a grandchild of the original project just because it has some feature that you need. It’s like the long tail of open source..you no longer have to wait for the original author to implement your obscure changes. Just find what you want out there and work with it. The reciprocal benefit of this, of course, is that the original author can actually watch your changes as you’re making them. Instead of some disjointed patches, he sees your commits as you add them to your own line and can follow your progress visually. At some point, if the author likes your work he can merge your branch back into his code. And GitHub will show this on the network, so everyone else who is following the project can benefit. They’ve made it easy to notify the author that you have some good changes as well, with the pull request.

Github is growing everyday. Statistics say after being launched in Feb' 08, in one year of being online it accumulated 46, 000 public repos.

Enjoy collaborating your project on github !!

Thursday, May 28, 2009

Playing with Watir - File Upload/Download component

In my last post I talked about WATIR integration with Rspec.

In our project, we had excel report download component. The challenge with Watir was to be able to download the excel file, save it and validate data against DB. Thanks to David Brown for his Excel Interface class library which is easy to implement. Next thing was to be able to save the file at any given location (always). None of the documented steps worked. The autoit dll supported by Watir was at the rescue. Au3Info.exe helps to identify IE control IDs. The following code snippet explains the rest:



After conquering file download, next was file upload. It was much easier coz Au3Info.exe was always their to figure IE control IDs. Using AutoIt documentation simplified it further.



WATIR rocks !!

Wednesday, May 27, 2009

Read only models in ActiveRecord

I was working in one of my project, where we were required to connect to 2 databases.
  1. First we had access to do CRUD
  2. Second we were only supposed to READ
For the second DB we wanted to raise exception from Rails, if somebody by accident tried to create/edit. ActiveRecord has this attribute as part of all models already called @readonly. There are definitely few challenges. Here is what I did:

The sweet model:


If somebody tries to add a record:


If someone tries destroy


What if someone uses delete


Rest in peace !!