Sohan's Blog

Things I'm Learning

Uploading Files With Blog Post

At times I wanted to push some files with my blog so that people can download and check something locally. Up until now, it was not a straight-forward way. I either uploaded the file to my own server or google pages or somewhere. Then linked it on the blog.
However, you can now publish files from Windows Live SkyDrive (total free space of 25 GB) or Google Docs (Total free space 1GB). If you haven’t checked already, google now offers you the opportunity to upload any kind of file without conversion. I know there are other services like this, but these two should be reliable.
I took some information from this Tim Anderson’s ITWriting blog.

Experience Notes From a RoR Code Review Job

Recently I had the opportunity to review a ruby on rails code. The project aims to create an online market place for experts, with a similar model to some other freelancing/outsourcing sites. Here is how and what I reviewed:
I had a read-only access to the code and no download was allowed locally. So, I didn’t get to run the code, tests or any tool to auto-generate some reports on the code. Also, it was supposed to be a high level review and I was supposed to take 5 hours to take a look into the code and write a report on the various aspects of it. In the end, it took me 6 hours and I came up with a 14 page report. I liked this job for a few reasons:

  1. When I was working at www.ScrumPad.com project, we got our code reviewed by Gregg Pollack of RailsEnvy. During those days we had little experience on RoR before we started the project. So, we ended up with something that was working well, but wasn’t the best one in terms of confidence and reliability. I remember the review was very well-thought and presented by Gregg and that to a great extent shaped the later works on the project.
  2. This was my first official assignment as a reviewer.
  3. I was excited to see how other people were approaching their RoR projects.
 Now coming to my review approach, here you go:

  1. After some googling about reviewing RoR applications, I didn’t find any comprehensive suggestion and decided to go my own way.
  2. To get started, I took a look into the config/routes.rb file. I had the impression that, routes.rb would help me understand the resources and their relationships. But soon I discovered one potential issue as there were almost no nesting of resources and some resources had tens of actions apart from the standard RESTful methods.
  3. Next, I picked the resource with most number of methods and found that, it was actually taking the responsibility of 5 different resources. Although these resources were somewhat related, it made little sense to me to have such FAT controllers.
  4. I was also looking for logging, exception handling, ruby coding style, naming and came up with some suggestions to improve on these aspects.
  5. I also suggested them to modularize their controllers. They already had an admin module, but they could introduce more to clean up things.
  6. After controllers, I went to the models. By the time I found a few natural inheritance relations among the models. But the relations were not found in the models that ended up with a number of code duplications and similar looking branches at several places. So, I suggested them to install the relations using single table inheritance and cleanup the stuffs.
  7. Apart from the relations, I also found a number of self or class methods floating here and there. While ActiveRecord models themselves offer a number of such methods, its not always wise to create one without thinking. In the code I found self methods resulted in method duplication and wrong method placement at several places.
  8. Next coming to views, I found they did a good job with the helpers and partials. Views were better organized. But also, I found a lot, I mean a lot, of partials. Such an explosion of partials often makes it hard to find the right ones, especially for new comers.
  9. Going to test code, I found they had a test suite with unit, functional and integration tests. But the amount of test was a concern for me. I believe test codes are there to help good design practices and managing changes over time. I suggested them to target 80% test coverage at a minimum.
  10. Coming about deployment, I found they were using manual deployment techniques. I suggested them to use capistrano for deployment.
  11. Overall I found a lot of reinventing the wheel scenario as they could get rid of lots of code by just using commonly known and free plugins. I suggested some plugins in this regard.
  12. I suggested them to use named_scopes to get rid of some self methods here and there.
After the review, I felt such patterns in RoR code is expected to surface in most new to RoR teams. Although experienced and smart people often read articles and consult experts as an on going basis to get things right at the first place. I suggest every team, if they haven’t already gone through, to take some time and study the resources at http://guides.rubyonrails.org and http://wiki.rubyonrails.org/
Also, its a good idea to know the Ruby language fluently to make use of the power of the language. A good learning resource comes with ruby installation named Programming Ruby, also available in the internet at http://ruby-doc.org
As a continuous learning tool, I also suggest keeping an eye on http://railscasts.com and http://stackoverflow.com/questions/tagged/ruby-on-rails

Home/End Key in Mac ( MacBook Pro ) Windows on Bootcamp

If you are anything like me, you love using the home and end key to quickly move to the start/end of a line of text. But, in Apple MacBook Pro, there is no default home/end key! I searched the internet and found Command + Left/Right to the rescue on OS X.
But, then I installed windows 7 on my Mac and it was nightmare to edit without the home/end keys. Today I just found that you can use fn+ Left/Right for this purpose! Hurray! It makes my time with Microsoft office and Visual studio much happier, again :-)

Comments

Anonymous
Thx a lot.
Wraithbone
Thanks! needed this too! VS2010 is a pain without those 2 keys!
Anonymous
This is amazing!! I am exactly looking for this!! Cheers!
Anonymous
Thank you, helps alot!

Added Crummy to Generate Breadcrumbs for CampZero.com

According to google’s SEO guideline, its a good idea to provide breadcrumbs to your web contents. This is good in two ways: a) It helps people to find path to move up the navigation stack and b) it helps the google and other search engines to get a feel about your web content’s hierarchical organization.
To add this breadcrumbs support, in my application www.campzero.com, a going to be online service marketplace for Bangladesh, I simply used the Crummy plugin. You can take a look at the Crummy plugin at github. It took me less than 10 minutes to find, learn and use this plugin! You can see the plugin in action at the campzero site.
I recommend this plugin for your Ruby on Rails breadcrumbs needs!

Acts_as_permalinkable: SEO Friendly Rails URLs Using My First RoR Plugin

As a byproduct of my work on www.campzero.com, I released my first ruby on rails plugin called acts_as_permalinkable on github athttp://github.com/smsohan/acts_as_permalinkable
A comprehensive documentation is given at the github page. If you ever need to use search engine friendly urls or permalink like this blog, you may consider using the acts_as_permalinkable plugin. It takes less than 3 minutes to add the permalink feature to your rails model!
Get started by the following and you are free to contribute!
script/plugin install git://github.com/smsohan/acts_as_permalinkable.git

Sitemap-generator for Your Rails App and Deployment Solution

When talking about Search Engine Optimization for your public web pages, you probably try to follow the google guidelines for search engine optimization. Its a good one to get started with. For my recent project, www.campzero.com, I read the document and tried to follow the steps. Today, I worked on generating sitemap for www.campzero.com using the following:
  • Installed the site-map generator plugin following this link at Aktagon’s, github link
  • For some reason, probably because of permission issues, my plugin install didn’t generate the sample sitemap.yml file for me. However, I created the config/sitemap.yml file myself and put the following contents there:
domain: www.campzero.com
limit: 5000
priority: 1
change_frequency: weekly
  • Then, I put the call to the sitemap method as shown in the github documentation.
  • Finally, I ran the command rake sitemap:gerenate to generate my sitemap.xml file inside the public folder.
  • So far this went well with the local environment. However, when I deployed this code and ran the rake command in my staging environment, it said it was not finding any model with the sitemap method.
  • After some debugging, I found that the problem was with the code at the file generator.rb where they put model.methods.include?(‘sitemap_options’) to see if the model contains a method named sitemap_options. But, at my staging environment, I found that this was returning false although there was this method inside the model. I changed the code to the following so that the include? check is done both for strings and symbols and it worked fine.
if((model.methods.include?(:sitemap_options) || model.methods.include?('sitemap_options')) && model.sitemap_options != nil)
models << model
end
  • Now, I could generate sitemap at my staging environment.
  • However, soon I found another issue with deployment, as I want my sitemap file to stay between deployments. So, I had to ensure the sitemap file is generated at a shared place other than the default public folder. I did the following changes to the sitemap_generator_task.rake file:
if defined?(SITEMAP_FILE_PATH)
SitemapGenerator::Generator.new(SITEMAP_FILE_PATH).find_models_and_generate
else
SitemapGenerator::Generator.run
end
  • I added the constant SITEMAP_FILE_PATH in my config/environments/staging.rb file to get it working.
  • Finally, I changed my deployment script to define a symlink from the public folder to the shared file path as follows:
run “ln -s #{shared_path}/sitemap/sitemap.xml #{release_path}/public/sitemap.xml”

How to Strip Html Tags, Truncate and Highlight Texts in Ruby on Rails

Recently, I had the following requirements as I was working on CampZero.com - the going to be service marketplace of Bangladesh.
  1. Remove all html tags other than hyperlinks and new lines from a html fragment
  2. Truncate the text to show only first 200 characters of the text and append ellipsis (…) in case the text was truncated.
  3. Highlight an array of words in the text to show the search query worlds that matched
The first one, getting rid of all but hyperlinks and new lines was achieved by the following code:

<%= sanitize my_html_text, :tags => %w(br a) %>
Next, to truncate the text, I simply used the following:

<%= truncate my_sanitized_text, :length => 200 %>
Lastly, to highlight my search query words, I did the following

#in the controller
@query_words = params[:query] ? params[:query].split(/\W/) : ''
#in the view
In reality, I chained the above thee methods as shown below:
<%= highlight(truncate(sanitize(my_html_text, :tags => %w(br a)), :length => 200), @query_words) %>
These methods and their siblings are great as time savers. Rails makes the web development fun by including this as built in methods. For reference, you can check the link at SanitizeHelper and TextHelper
Happy railing!

How Is Rails Plugins Helping Me in Developing CampZero.com?

I am up to a web venture called www.CampZero.com - an online market place for you service providers in Bangladesh. This is somewhat similar in spirit to classified sites like ebay and craigslist, but the target market it consciously chosen to be the service industry. Anyway, I will go to the point why I picked rails for this project and how it is paying off.

A little background about me. I have some good background on .Net/C# and I developed several projects using this technologies. Also, I have some experience with Rails and developed almost same number of projects as that of .Net. So, I made an informed decision about choosing the Ruby on Rails framework for my project over .Net/C#. Here’s the rationale:

Story#1: As a CampZero developer, I want to deploy the system as soon as I am done with a feature.
Solution: Use capistrano to automate the deployment process. It took me less than 30 minutes to setup the automatic one-click deployment. The deployment steps are at a minimum as follows:
  1. Get the latest code from the code repository.
  2. Create a link to the shared log directory.
  3. Create a link to the shared assets directory.
  4. Create a link to the full text search configuration file.
  5. Migrate the database schema.
  6. Change the link to the application to the latest code.
  7. Restart the full text search engine.
  8. Restart the web server.
  9. Rollback if any step of 1-8 results in a failure.
The whole process is triggered by a single line of command ”cap staging deploy:migrations” and takes less that 3 minutes to complete on an average.

Story#2: As a guest user of CampZero, I would like to sign up for an account so that I can post an ad and/or rank the service providers.
The signup process is actually a three step process as follows:
  1. Create account, with password encrypted.
  2. Get an email with an activation link.
  3. Verify email address by clicking an activation link.
Also, there are several related works as follows:
  1. Login
  2. Logout
  3. Reset password
I used Authlogic for this purpose and it has taken care of all the aspects for me. For emailing I used ActionMailer. The whole job of authentication took no more than 4 hours! Thanks again to Authlogic.

Story#3: As a user of CampZero, I want to search for service providers using natural text.
The full text search was implemented using Sphinx and Thinking-sphinx. This also comes with default support for paginating lists. So, Thinking sphinx took care of all my search needs. I used the following features:
  1. Search by full text in the service description, title.
  2. Also search the service provider names and service categories.
  3. Rank by the ratings.
  4. Search using English morphology, for example, if searching for ‘cars’ it also searches for ‘car’.
I spent as little as 6 hours to setup and code the whole free text search! The total coding size for search is less than even 15 lines in total!

Story#4: As a service consumer, I want to rate and write comment on my service providers so that other consumers can make informed decisions.
I used two plugins called, rate-fu and acts as commentable! These plugins are great time savers as well. All the underlying logics for handling ratings and commenting are already there and you merely plug the features in. It took me 5 hours and most of it was due to the UI part!

I am convinced that for most web applications now, Ruby on Rails is an automatic best seller. But, of course, my prior experience helped me in getting things done even faster. Lets see how this project makes a business :-)


What I Learned From My First Semester at University of Calgary as a Grad Student?

In a single line, the first semester has been awesome.
Some of you already know that I came to Calgary, AB, Canada this fall to start a graduate research focusing agile software development. So, to get started I tried to come up with a research idea by hunting several resources including popular publications, blogs and books. This is not yet over…
However, I took a course called Applied Machine Learning and had the opportunity to work on a project that might lead to my MS thesis. The project, Auto Tagging Emails with User Stories, targets to grab and automatically tag emails with user stories based on a project’s context information. The trick is, if you see the text similarity between an email and a user story and complement with their temporal and meta data similarity, you can make a guess about their relation. I wanted to make it an automatic process so that when people share knowledge in emails they can easily make use of this knowledge for future references. The project was successful in its scope and I submitted a paper day before yesterday. Keeping my fingers crossed to see the decision on this paper!
Apart from the project, this course also offered the unique opportunity to work with Prof. Dr. Richter. He was really helpful and spent a lot of time on my project and the paper.
I also did a group project for the Interactive Tabletops and Surfaces course. This project was called “Tavolo”, a surface solution for conferences where people could bring their research ideas through images/videos/pdfs and annotate/share with others. This was my first ever tabletop project. We used Microsoft Surface and I liked the hardware so far. But in the end I found that the size and low resolution of the surface limited our opportunity to implement several features of the project. But in a nutshell this project gave me the opportunity to try something around Human Computer Interaction and next generation collaboration designs.
During the last week of November, I attended the ITS2009 conference. It was a 3 day international conference people came from all continents. I liked the presentations and the fact that this research community is as if its a connected web. I must say, the Bill Buxton speech was a great one. He envisioned the next generation human computer interaction and also discussed about real life commercial applications coming out of the research. It was very inspiring!
I also submitted a grant application to iCore. I am personally convinced that this was a good proposal and I have the necessary background to make it a successful research. But according to my supervisor, its a good idea to be less optimistic with iCore fund. Anyway, composing this application helped me in finding some of the holes in my writing and thinking skills. I will happily take this lesson!
In my family life, this was an eventful time as well. My wife, Shahana, got admitted to the ECE department at University of Calgary and she will start her MS this January. This means we might be graduating at similar times and be back to Bangladesh soon thereafter. Wish we make good use of the opportunity in our graduate studies.
Well, this is a pretty much a summary! But I forgot one thing, Swimming! For the last month and half, I am going to swimming 3/4 days a week and enjoying this activity. The university swimming pool, like all other games and sports venues, is really well maintained.
I am looking for a Camera and waiting for the Boxing Day sale. Let me know if you saw a good DSLR camera around $500!
Oh! I forgot another announcement! I have taken my first web venture at www.campzero.com! If you have some time stop by and let me know if you like/dislike the idea and its presentation. I am planning to go live from Jan 1 2010!
Merry Christmas!

Comments

Sohan
@Syed Raihan, this is a RoR project. After I worked in .Net and RoR for over 3.5 years, I realize that at this moment RoR is the better choice for a web project for me.
Any comment on the business idea?
Syed Raihan
What technology are you using in CampZero? Is it Rails or ASP.NET MVC?

Lean Thinking: You Will Probably Like to Learn the Essence of Agile

Image taken from: http://www.leansoftwareinstitute.com/images/img_bigpicture.jpg

If you read the Poppendieck’s book called, “Lean Software Development : An Agile Toolkit”, you probably liked it because it managed to get the essence out of agile practices. So, what are these core principles? Well, most of you already know the phrase, “Inspect and Adapt”. Now, you also know a bunch of specifications that facilitate this, for an instance, Scrum, XP etc.

Reading the book, I had a realization that, its good to talk using concrete facts as much as possible. So, doing a value stream mapping practice is worth than spending hours in discussing the process optimization. The same holds true with the Profit and Loss statement when figuring out which option to take - quality compromise, deadline shifting or feature squeezing. Being able to answer why questions, at least 5 in a succession, is something very critical - then you know the hidden junk thats causing the bad smell. I highly recommend reading this book, especially to people who are doing agile for a year or so and thinking about getting better at it.

I also had the opportunity to attend a speech by the authors on this Monday. The speech was a great one. But for my readers, I will write about an example from the speech.

Once Mary and Tom visited a company that creates hardware and software tools for real time video conferencing. They met the Boss there and asked what they were doing. The answer was, “We are working to improve the system so that our customers get better video conferencing solution for their businesses.” They went to a section where people were working on hardware and asked one what he was doing. The person replied, “I am creating a component for the system, so that our customers can do better video conferencing”. Then they went to a software developer and asked what she was doing. She replied, “I am working to improve a part of the software so that our customers can do better video conferencing”…. (I am sure Mary used better words than mine and it was really interesting to hear the story in her voice :-))

So, the fact that she wanted to capture using this example is, although each individual is involved in a specific task, they envision the bigger picture from the customers’ standpoint. This is really important. Because as soon as you start seeing the views from the customers’ perspective, you will produce less bugs. In the book they mentioned, most software bugs are not results of coding/design errors, rather they arise from the difference in views among customers and developers.

Overall, it was a pleasure to read the book, although this blog post may not reflect all of my respect and take home from the book :-(