Wednesday, April 8, 2009

GIT Warning: LF will be replaced by CRLF

I am using msysgit on windows 2000

After setting up the repository and when I tried to add files to GIT index (inorder to have my files considered for next commit) ........ I got

Warning: LF will be replaced by CRLF in FILENAME

After googling I found this a default GIT setting and can be overridden by issuing

git config core.autocrlf false

in Bash mode


A note on LF & CRLF

Most Unix operating systems represent the end of each line with a line feed (LF) character. However, the Windows operating system represent the end of line with both a carriage return (CR) and a LF.

Monday, April 6, 2009

Git on windows - Basics

GIT has now become the preferred source code management tool for Rails community. GIT is at its best when used in Linux / Mac platforms, here we will see how this can be used in Windows. GIT still has few issues in windows but the basic functionalities should work fine.

GIT for windows can be downloaded from Google

There some good links detailing the installation steps

> Using SSH

> Using PuTTY

Follow the above links to finish installation.

Once done with this we are ready to start using GIT as SCM tool.

Getting started - To start GIT bash Right click on your project directory and select 'Git Bash Here' ( if you are a fan of typing commands or else use GUI option)

This will open a CMD window, start by typing 'git help'

Create Git repository - to create a git repo. for your project type - git init

I don't want to reinvent the wheel, so just providing a list of useful links which has very good articles on GIT usage.

Useful links

> Github
> User guide
> GIT commands
> Access issue

Sunday, April 5, 2009

Nice output for Ruby objects

Ruby has a wide range of methods to format the output of an object.

Like

1) Inspect
2) y or to_yaml
3) PrettyPrint

y is actually used as a shorthand for to_yaml

example
 
a={'1'=>'one','2'=>'two','3'=>'three','4'=>'four'}

y a

puts a.to_yaml

generates the same output.

Below are the ouputs using different output methods

> Using normal puts
 
usage: puts a

output:

1one2two3three4four

Using y or to_yaml

usage: y a or puts a.to_yaml

output:

"1": one
"2": two
"3": three
"4": four

> Using PrettyPrint

usage: Please do a require 'pp' in your script file,
 
pp a

output:

{"1"=>"one", "2"=>"two", "3"=>"three", "4"=>"four"}

> Using inspect
 
usage: puts a.inspect

output:

{"1"=>"one", "2"=>"two", "3"=>"three", "4"=>"four"}

Thursday, April 2, 2009

Ruby - DUP vs CLONE

Both DUP & CLONE can be used to create shallow copy of an object. Both copies the instance variables of obj. But we need to be selective in their usage.

Few difference between these are

1) CLONE copies both FROZEN and TAINTED state of an object, where as DUP only copies TAINTED state of an object.

2) With CLONE you can copy any singleton methods of an object but DUP does not support this.

CLONE is used to duplicate an object, including its internal state, DUP typically uses the class of the descendent object to create the new instance.

I had some bitter experience while using DUP for duplicating an ActiveRecord row, this ended up in losing the original one the same worked fine with CLONE.


A good article on Objects states can be found here


Frozen state:

The object can not be modified any more.

Example
 
a = [ "a", "b", "c" ]
a.freeze
a << "z"

Will return

`<<': can't modify frozen array