Saturday, October 24, 2009

E4SI Fellowship

How I came to know about E4SI was through Shrey Goyal, a 2008 fellow. Though the words "Social Impact" stirred excitement in me I was very unsure of the nature of the work. Intellecap offered me the opportunity to work at the intersection of Technology and Social Sector. Through E4SI I got the opportunity to work for a 'real' project. I got the opportunity to work with the 'professionals'. What could be a better platform to learn? E4SI gave me the chance to meet the change makers.

I was instantly comfortable with Intellecap's working environment. I was to stay at the company's guest house. A jogging park, mall, gym and lot of restraunts and snakcs corners were nearby. A fifteen minutes walk, straight from the guest house, led to my office.

4th May, was the first day of my office. I was to work with the Tech Team (also called the Geek Team by co-workers) under Siddharth (Sid). Office hours for me where anything from twelve in the afternoon to eight thirty in the evening. To Sid what ultimately mattered was my motivation to work and my productivity.

My first job was to write Tests for MISFIT (our MIS for the MFIs). The aim was to get aquainted with the existing codebase, and the tool and the technologies used. The working platform was GNU/Linux with Ruby for scripting and Merb/Rails for web programming. My major project was to develop, a KMS (Knowledge Mangement System) for SMEs ( Small Medium Buisness). The software essentially is an easy to use, feature rich "Office Twitter", with the ability to create group updates, create private messages, comment on updates, attach multiple files along with the update, tag the update, create and moderate polls and groups and perform full text searches. Alongside, I also devloped scripts to audit loans for the MFIs that migrated to MISFIT from their older solution. Later, I also worked on improving, and demonstrating the web API of MISFIT to potential clients for easy integration with their legacy system.

Very soon I mixed with the highly skilled team that drives Intellecap. Lunch time was my slot for interaction with the entire Intellecap team, where they would share their experiences on work and life. Friday afternoons were always dedicated to watching an episode of TED talk, which would invariably invite a heated discussion.

This was my first opportunity to work at a professional level. I made a product that brings to the enterprises the power of the Internet to share "information" within any company in real time and, manage "work". Thanks to Intellecap and E4SI at having provided me with a summer that was filled with loads of fun and adventure.

Wednesday, October 21, 2009

Image Morphology - Dilation and Erosion

For my assignment I had to implement the basic image morphology algorithms: Dilation, Erosion, Opening, Closing, Hit and Miss Transform, Hole Filling, Thinning, Thickening, Pruning, Skeletonizing, Boundary Extraction and Connected Components in C++ using the OpenCV library.

Theory of Image Dilation and Erosion (as well as for other algorithms) can be found here.

I have put here the code for Image Dilation and Erosion. I will put up the complete code on github soon.



I have represented the kernel using an IplImage structure. The code above is for Dilation. For Erosion all you need to do is replace max_element with min_element in line number 40.

P.S: The use of vectors and algorithms is not "entirely" justified except that I am used to dynamic languages like Ruby and Python :P.

Tuesday, August 4, 2009

Generating MD5 hash of a file in Ruby

The 'md5' library can be used to hash the 'string' using the MD5 algorithm. The 'new' or 'md5' function can be used to create a new md5 object. The string to be hashed can be passed as an argument to these functions.

require 'md5' #include the library
hash = MD5.new('Hello World') #or MD5.md5('Hello World')

Using 'update' you can add more string to the md5 object. The step 2 could have been accomplished in the following way as well :

hash = MD5.new #create a new md5 object
hash.update('Hello') #add the string 'Hello' to the object
hash.update(' World')
#add the string ' World' to the object

To return the hash value the 'hexdigest' function is used

puts hash.hexdigest #display the md5 hash of 'Hello World'

Now, to generate the md5 hash of a file we need to read the content of the file as a string, then use the string to generate the MD5 hash. So in short you can do the following:

md5hash = MD5.new(File.read('path_to_file')).hexdigest

Note: My sample file was a simple text file. You may have to add the 'b' flag for binary files.

md5hash = MD5.new(File.read('path_to_file', 'b')).hexdigest

Friday, July 31, 2009

Base64 encoding-decoding a zip file in Ruby

Zip file is a binary file. First of all you need to read the content of the binary file as a string. So you do:

content_string = File.open('path_to_zip_file.zip', 'rb') {|file| file.read}

The value of the content variable is assigned with the return value of the block. To the block the file which we are opening is passed as a parameter. The 'read' method returns the content of the file as a String. The block form of open automatically takes care of closing the file.

Now we use, the pack method of the Array class to encode the given string to the base64 format (you can also use the base64 standard library, if you want to). Here is the code:

base64string = [content].pack('m')

Now you can store the base64string in any other file for later use.

File.open('path_to_base64_encoded_file', 'w') {|file| file << base64string }

When we want our real file back, we use the unpack method of the string.

base64sting = File.open('path_to_base64_encoded_file', 'r') {|file| file.read }
File.open('file_name.zip', 'wb') {|file| file << (base64string.unpack('m')).first } This will recreate our original zip file. Since the unpack function returns an array, we have used the first function to return the first element.

Note: I have used the above code on a Debian GNU/Linux system. The code should work on Windows environment as well.

Tuesday, June 30, 2009

Creating Tabs using jQuery

This is the piece of jQuery code I wrote to create tabs. I will explain the code in detail and put in the html and css also as soon as I get more time.

Sunday, June 14, 2009

Google Federated Login in Merb

Google Federated login is implemented using Open ID standards. Google uses AX Response instead of the Standard Sreg Response. Merb bundles with the meb-auth-more gem, which provides openid authentication functionality to merb apps. The strategy is called :basic_openid. To use Google Federated Login I modified the code for openid authentication to use AX response(/usr/lib/ruby/gems/1.8/gems/merb-auth-more-1.0.11/lib/merb-auth-more/strategies/basic/).

The run method looks like this:


And the on_success and the find_user_by_email method looks like this:



It is based on Nils Franzen's guide to Using Google Federated Login in your Rails Application.

Friday, June 5, 2009

ZSH and Tilda

Tilda does not work on Ubuntu if your default shell is ZSH. There is a way round this problem. After you have installed Tilda, run the command:
   tilda -c bash
This will start Tilda with the Bash Shell and also opens its Config Manager. Go to the Title and Command tab and check the box that reads Run a custom command instead of shell. In the Custom Command text box, type zsh.

Close the Config Manager and exit Tilda. The next time you start Tilda it will start with the ZSH shell.