Convention over configuration - the smarter choice digg delicious su

Posted by daniel
on Friday, August 31

I was debugging a Java legacy system and found out that the error was due to configuration. Yeah.. I forgot to change the configuration that maps to the database and I cost me 1 day to debug!. I guess I’m too used to rails way of doing things now. Convention over configuration, definitely the smarter choice!

Using raspell with your own custom dictionary digg delicious su

Posted by daniel
on Wednesday, August 08

A good search engine should be smart enough to detect spelling errors and provide suggestions. For example if you misspelled a word when using Google search, it will ask Do you mean:.... It will be cool to have such feature for our own search engine. So I started to explore possible solutions what works will rails and came upon this blog post by Evan Weaver. He has implemented a ruby gem raspell to interface with Aspell. That sounds like a good solution and I decided to check it out.

1. Installing Aspell

As mentioned in Evan’s post to install Aspell just type the following command from terminal:


sudo port install aspell aspell-dict-en

This will install both the aspell library and aspell English dictionary.

2. Install raspell

This is straight forward.


sudo gem install raspell -- --with-opt-dir=/opt/local

3. Setting up your own dictionary

For my case I needed aspell to check against my own custom dictionary. I create a text file containing the list of words with each word on a new line save it as wordlist. e.g.


John
Simon
Mae
Tim
Louis

Then run it with the following command.


aspell --lang=en create master ./en_SG-name.rws < wordlist

Note that for the language option I’m using ‘en’ which is the standard code for English. If you are generating a word list in other languages you will have to change lang option accordingly. The name of the output file is important because Aspell only pick up dictionary file in a certain naming format. The dictionary file should start with the language code then follow by a country code which is optional. For my case I have chosen SG because I do not want to override the default en dictionaries from Aspell. The ‘name’ after the ’-’ is actually the jargon. So if you are generating a word list of street names in US you might want to name you dictionary as en_US-street.rws. Once you have generated the dictionary you will have to place it in Aspell default dictionary directory.


sudo mv en_SG-name.rws /opt/local/share/aspell/

Because Aspell will only look for dictionaries with .multi file extension in the default directory. I’ll need to create a en_SG-name.multi file for my new dictionary

sudo vi /opt/local/share/aspell/en_SG-name.multi

and add the following line.


add en_SG-name.rws

You can add multiple dictionary to this file. If you needed the common English dictionary together with your custom one. Just add it accordingly.

4. Using your own dictionary in ruby.

Finally to use the dictionary I have just created.


require 'rubygems'
require 'raspell'

sp = Aspell.new('en_SG', 'name')
sp.suggest('Mea')
=> ["Mae"]

The first parameter is the language part of the file name and the second is the jargon. So if you have named your dictionary as en_US-street.multi then you will need to initialize it with


sp = Aspell.new('en_US', 'street')

Sphinx - nginx of full text search digg delicious su

Posted by daniel
on Thursday, August 02

I got to know Sphinx a Russian search engine from Snax. This could be an alternative to ferret.

Setting up Rspec, Autotest and Growl on Mac OS X digg delicious su

Posted by daniel
on Sunday, July 22
p> We have recently decided to use BDD for our upcoming projects. To make testing more fun and efficient I have hook up Growl with ZenTest’s autotest to display test results from Rspec. Some of the following instructions is taken from http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl

What follows are the instructions to install the software to setup your own if you like to try out.

  1. Growl
  2. ZenTest
  3. Rspec

Installing Growl

  1. Download the dmg package from Growl
  2. Open the disk image, and double click in the Growl.prefPane icon.
  3. Next is to install growlnotify . Double click on the Growl disk image again if you have close it and execute the following commands from a terminal
 cd /Volumes/Growl/Extras/growlnotify
 sudo ./install.sh
 cd
 hdiutil detach /Volumes/Growl 

Installing ZenTest

ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails. For our purpose we will be using autotest. The latest version of ZenTest has added rspec support and it’ll auto detect rspec and run tests in the background whenever there’s any changes to the specs.

Installing ZenTest is easy just run the following command:

 sudo gem install ZenTest 

Installing Rspec

To test rails with rspec you will need to install rspec and rspec_on_rails plugins . Run the following command from your project root directory.

 script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
 script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails 

After you have installed the plugins you will need to run following command once to bootstrap your Rails app with RSpec.

 script/generate rspec 

Customize Autotest

The last step is to customize Autotest. Download the following 2 images and save them under ~/.autotest_images (create this directory if it does not exist). You can also create your own images if you want.

Open your favorite editor and copy and paste the code, then save the file as .autotest under your user home directory.

 module Autotest::Growl

   def self.growl title, msg, img, pri=0, sticky=""
     system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
   end

  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/) 
      if output
        if $~[2].to_i > 0
          growl "FAIL", "#{output}", "~/.autotest_images/fail.png", 2
       else
         growl "Pass", "#{output}", "~/.autotest_images/pass.png" 
       end
     end
   end 
 end 

Configure Growl

Finally you can configure growl to with different display style via System Preference -> Growl. Try out all the different display style to see which one you prefer. Personally I like “Music Video”.

Once you have setup all the above. Run autotest under your project root directory and you will see Growl in action. Have fun!!

Internet Wasteland digg delicious su

Posted by daniel
on Sunday, July 22

Check out this geek song Internet Wasteland by Eddy Boston. It has Ruby on Rails in the lyrics.

Sending emails using GMail smtp with ActionMailer digg delicious su

Posted by daniel
on Wednesday, July 11

If you have been following our blog you should have read the post Swiss Amry Knife 2.0 . We have recently switch our mail server to Google Apps. This is nice but that also means we have to change our ActionMailer server settings to GMail’s smtp server and this pose a problem. Because default ActionMailer does not support SSL authentication which is required by GMail. I tried searching for a solution and lucky enough I managed to came across this post and got to work! Check out the link if you are facing the same problem.

Rake file for SVN default ignores digg delicious su

Posted by daniel
on Wednesday, July 11

After reading the rake tutorial and reading about doing proper svn ignores . I had the idea of creating a rake file to do the default ignores. Here’s the code:


 namespace :svn do
   desc "Ignore standard files from svn" 
   task(:default_ignores => 'tmp:clear') do 
     `svn remove log/*` 
     `svn commit -m "removing all log files from subversion"` 
     `svn propset svn:ignore "*.log" log/` 
     `svn update log/` 
     `svn commit -m "Ignore all files in /log/ ending in .log"` 
     `svn remove tmp/*` 
     `svn propset svn:ignore "*" tmp/` 
     `svn update tmp/` `svn commit -m "Ignore all files in /tmp/"` 
     `svn move config/database.yml config/database.example` 
    `svn commit -m "Moving database.yml to database.example to provide a template for anyone who checks out the code"` 
     `svn propset svn:ignore "database.yml" config/` 
     `svn update config/` 
     `svn commit -m "Ignoring database.yml"` 
     `cp config/database.example config/database.yml`
   end
 end 

Save or download this code as svn_default_ignores.rake under the lib/tasks folder. Then run it using the following command from your project root directory:

 rake svn:default_ignores 

Enjoy!

Setting up SVN server on Mac digg delicious su

Posted by daniel
on Tuesday, July 10

As a software house, we need a way to track and manage all our different versions of source code. We are currently using subversion for version control (If you are not using any kind of version control for you source code you should serious think about it.) . There’s an article on how to install svn on mac from hivelogic .

After installation you will need to create the repository and configure the server before it’s ready to run.

STEP 1 : Create the repository

SVN stores all it’s files under a repository. We will need to create one before it can start running. Open the terminal and change directory a your desired location for the repository. Then issue the commoand:

 svnadmin create repos 

A ‘repos’ directory will be create.

STEP 2 : Securing your repository

Most of the time we do not want anybody to access our source codes unless it’s open source. Therefore we need to control user access. Using the same terminal from the previous step issue the command (You may use your preferred editor to edit the file):

vi repos/conf/svnserve.conf

The default svnserve.conf file will iinclude the following lines but are all commented out.

 # anon-access = read 
 # auth-access = write 
 # password-db = passwd 

The first line anon-access = read means that everyone have read access. But we do not want that. Therefore we have to change it to anon-access = none . The second line auth-access = write means that authorize users has read and write.

Just uncomment out these lines and change the anon-access value to none and save the file. The resulting file should be:

 anon-access = none
 auth-access = write
 password-db = passwd 

Since we only allow authorized users to access, we will need to modify the users database file passwd, which is in the same directory as the svnserve.conf file. Using vi command again :

vi repos/conf/passwd

Add in users under the “[users]” section and save the file:

 [users]
 harry = harrysecret
 sally = sallysecret 

STEP 3 Starting the server

Finally it’s time to start running the server. From the same terminal issue the following command:

 svnserve -d -r repos 

This will start the server in daemon mode using the repository ‘repos’ which you have created in step 1.