Sunday, November 23, 2014

TextMate bundle for remove space, add newline, etc

This is one of the useful bundle for TextMate which converts Tabs to Spaces, Remove Trailing Whitespace and Add a newline at end of file

Wednesday, August 21, 2013

Rails 4 - Scope

In rails 4, scopes should take a proc object or a block. Take an example this User model
Class User < ActiveRecord::Base
  attr_accessor :name,:age,:status

  def initialize(name, age)
    @name = name
    @age = age
I would like to make default scope based on status 'user' and admin scope based on status 'admin'. In rails 3, I can make scope like this
#Rails 3
scope :admin, where(status: 'admin')
default_scope where(status: 'user')

Rails 4, I can make scope this way
#Rails 4
default_scope { where(status: 'user') } #  block
#default_scope ->{ where(status: 'admin) } #Proc valid
scope :admin, ->{ where(status: 'admin') }
If we try to use scope without(see rails3 examples) passing proc or block in Rails 4, it triggers DEPRECATION WARNING message.

Rails 4 - Finders

Old-Style finders are deprecated
In Rails 4, Old-Style finders are deprecated. Consider User model with name, age members
Class User < ActiveRecord::Base
  attr_accessor :name,:age

  def initialize(name, age)
    @name = name
    @age = age

In this class, If we want find user with name of 'foo'. See the difference in rails 3 and rails 4 call
#Rails 3
User.find(:all, conditions: { name: 'foo' })
#Rails 4
User.where(name: 'foo')

In rails 4, you will get DEPRECATION WARNING: Calling #find(:all) is deprecated. You can call #all directly instead or build a scope instead of using finder options.

Dynamic finders that return collections are deprecated
#Rails 3
#Rails 4
User.where(name: 'foo')

In Rails 4 alerts DEPRECATION WARNING if we use dynamic method(User.find_all_by_name). Preferable alternative option is User.where(...).all

Tuesday, March 26, 2013

Install Tombay on Mac

Tombay is a good note-taking application for Linux.After I have changed to Mac, I was looking for a similar note-taking application. At the end, I installed Tombay on my Mac Mountain Lion/Lion.

Here are the quick steps I have followed to install Tombay.

1. Make sure you have n't installed Mono library. If your system has any previous installation, uninstall it.

2. Download and install Mono. Why we need Mono library? - Since tombay is written in C#, system needs Mono runtime to build and run on mac.

3. Get the latest source code from repository.

git clone git://

4. Build and Open the application. Go to the source code directory(tombay)

$ xbuild Tomboy-mac.sln
$ ./
$ open

After the above step, Tombay application is successfully installed and available on spotslight search. I hope these steps helpful to install Tombay on Mac Mountain Lion/Lion.

Monday, March 18, 2013

Install instruction for Tomcat 7 on Mac

To install Tomcat 7 you should have Java 1.6+, so make sure version of java on your Mac by using "java --version" command.
Here are the quick steps to install Tomcat 7 on Mac. I believe it may take few minutes to install

1. Download a Core Binary file from here. The link of the binary file looks like this
2.Extract the downloaded binary file tar -xzvf ~/Downloads/apache-tomcat-7.0.37.tar.gz
3.Create or make sure you have local folder.If you don't have it then create it sudo mkdir /usr/local Then move the extracted binary files to /usr/local sudo mv ~/Downloads/apache-tomcat-7.0.37 /usr/local
4.Soft link the installed folder to Mac's library folder. To maintain easily the installed application sudo ln -s /usr/local/apache-tomcat-7.0.37 /Library/Tomcat7
5. Change the ownership and executable permission to application folder sudo chown -R YOUR_MAC_USER_NAME /Library/Tomcat7 sudo chmod +x /Library/Tomcat7/bin/*.sh
6. Installation is done, now you can start/stop the Tomcat7 Service /Library/Tomcat7/bin/ /Library/Tomcat7/bin/
7. Open your browser and type the URL to see welcome message of tomcat7 application server - http://localhost:8080