Pages

Thursday, July 7, 2011

Ruby Pair Programming

As we all know, Learning Ruby is fun, i just want to use this post to share my experience in Ruby pair programming. Initially i don't have any idea on pair programming and after i learnt i found that, this is one type of writing unit testing in Java. Also, its just like the approach of Test Driven Development, that is what i understood.

Writing tests and writing code based on that test and checking every time the test are passed whenever we do modifications... that is what finally pair programming is.. so what will be the advantage? New modifications in the code should not break the existing functionality as iteration is the important aspect in software development.

Our mentor Victor Goff teach this concept to me like how a father can teach to his kid... i really admired of his teaching skill and its my duty to say special thanks to him as this post is mainly because of his inspiration. I do not know whether i will post all the inputs that he shared with me, but i will try my best to achieve that.

Lets start jump towards the pair programming...

For that we need rubydoctest to be installed. My concentration is mainly towards Windows since for Mac and other OS there needs to me some more settings we need to do for installing that. Mostly these types are installed as gem and hence other OS users can do some google on it to identify the steps for rubydoc installation.

Just install the rubydoctest as below
You can choose the directory where Ruby is installed if it throws any error. I hope it will not throw any error but i am not sure... so try it if you want.

The next step is towards writing the program.
Create a file called hello_world.rb and type the following in it.

Now run the file in the command prompt as below and we will get the following result.The errors and failures are 0 and this is the good startup.
So, whatever doctest we need to write, we have to write it within the comment block = begin and =end

Next we are going to start by writing the first doctest for our program.
For that we just update the lines as below in the hello_world.rb file

when we run the rubydoctest, we will get the following outputSo, we are calling a method called hello_world but its not defined.
In order to correct this error, we can define the method as below.

Now when we again run the rubydoctest, we can see the ouput as belowNow the error becomes 0 but the failure is 1. That means the expected output doesn't match with the result output.
So, we have to think about how to correct it. The expected output is "Hello World!". We will update the code as like below and we will check whether we are able to correct this error or not.

Run the rubydoctest, and check the output which is as shown below.Now there are no errors and failures since the we get the expected output.

This is how the pair programming works and hence it mimimizes the error while coding.

Similar to the above steps, we can add 'n' number of doctest and we can check for the output result.

Whatever steps we learnt above is the basic for running the rubydoctest.
I can show two more iterations from which we can get more comfort with this process.

Iteration 1:

Add the following doctest and run the program.

doctest: I can pass a name to hello_world and get "Hello Mani!"
>> hello_world "Mani"
=> "Hello Mani!"
In order to correct the error, update the method as below:

Now when we run the doctest, we will get the output without errors as like below.So, by passing the arguments to the existing method, we are able to correct the error. Also, note that, the existing doctest is also not failed.

Iteration 2:

In this iteration, we just add one more argument to the method. We will write the doctest as like below.

doctest: I can also ask a question by passing "Erik", "?"
>> hello_world "Erik", "?"
=> "Hello Erik?"

By running the test, the ouput will be as like below.In order to correct the error, we need to modify the method as like below.

And the output after running the doctest will look like this.Now all the tests are passed and your code is working fine without affecting the existing functionality.

This is how the advantage of pair programming stands. We keep on adding the functionalities over by over. At the same time, some care needs to be there to check the existing thing and thats why we are checking all the tests. If any one of the test failed, that means we are doing something wrong and we will be cautious while coding.

If you understand the above concept, surely you will try to go to the next step in that. You can try this Blog post on Ruby Doctest of my mentor which will definitely help you to move little bit further. (I feel little bit hard :( while going through that.. May be because of getting the input directly from him)

Hope all enjoy this post and Happy pair programming until the next post.. :)

Wednesday, July 6, 2011

Journey towards Ruby - Nautical Mile 1

A little bit of distance i reached after i started the journey towards Ruby. I want to mainly focus on the initial startup of few things that i learnt so far.

Very happy to start my week 1 course. This is my first online class that i have attended in my lifetime. Since i don't have any experience, i do have lot of expectations. Also, i heard that there is no screen casts provided from their forum and i thought how they can handle without that.

They have posted week1 lessons. Also, i have bought the online book which the course is based upon. Initially i thought the book is not needed but anyway i have bought that E-book, The ultimate guide to programming which seems to be useful.

There are limited portions that need to be read for the week1. Also, the exercises that are posted in the forum are quite interesting. Quiz is also there. I am more interested in reading about the different people answers for the questions in their own way. Also, challenges have been posted which gives more enthusiasm while participating.
The only thing i feel bad is that, the people who have some knowledge in Ruby start applying that concept while answering the questions leads to some confusion while going in the right path. Anyway the tutors Sathish Talim and Victor Goff guide us during that time by replying to the answer in a nice manner of learning those things in detail in the coming week. This gives some more confident to the people who are little bit new to this.

First, i start struggle to set up the environment and IDE. I am able to install Ruby as i had some experience already on that but i forget the exact tools what i used for IDE. I tried with this Geany IDE. I have downloaded that from here... Download Geany. But i am not feeling comfort with this. I start using SCITE editor. I found this two blog post useful when i start google for the SCITE IDE - Post1 and Post2. The above two post give some idea on SCITE tool and its advantages.

Also i have gone through some other useful books which can give some quick reference. And i found the following book, The Ruby Pocket Reference which is a good reference book in order to see all the usage of syntax and keywords. But the above link has only limited pages and i bought this book from here. I also bought the kindle(thought to write some post related to my experience on this later :)) version of this book, which makes me to read with more eagerness.

I have made some friends through this training program. Still i want to make some more contacts. I started posting some answers for the exercises and i felt good. I thought i reached little bit of distance from where i have started. More experiences on the upcoming posts :)

Friday, June 24, 2011

A journey towards Ruby

Ruby is one of the popular language of this time and i want to make use of this post to share my experience of how i get started with that.

As a Java developer, my full concentration is towards Java based technologies. This mindset gets changed when i start using social media. I came to know that many popular applications like Twitter, BaseCamp, etc are built based on Ruby on Rails platform.
I started analyzing the reason behind that...

Nowadays lot of applications are created based on web. Deploying and hosting the application is one of the major hurdle everyone is facing. In my experience, there are lot of PHP based web applications available in the market. The main reason behind is that, lot of hosting services are supporting PHP. But what happen when we develop applications based on Java. Yes, there are few hosting services that are available to host Java based web apps but the cost is more compared to PHP based hosting services.

One more problem is the deployment. Deploying a Java based applications is not that much easy even though lot of tools are there. The main reason is, we need to set up lot of configuration parameters. Also the time taken for development is more for Java based application. Even for building a small application, we need to set up the required environment which can be set as similar to large enterprise applications. So, Java is mainly suited for large enterprise applications.

What is the alternate for that? PHP - Its more suited for the programmers who know C# Dotnet environment and they can easily picked up and move towards the environment.Also the learning curve is more for any person who want to move towards PHP since it will be easy at the startup. Even i start maintaining the website built on PHP based on my little knowledge. But what will be the alternate for Java developers like me?

Here comes Ruby. Learning Ruby is fun... :) That is what i come across. Learning curve is simple... Hiring the people and getting the people trained is more easy.. Quick development cycle... Easy deployment... what more? For quick launch of small products, Ruby platform is good...

With that in mind, i start studying the Ruby based framework.. Ruby on Rails(ROR).. i started a year before... its like entering in to the struts framework directly without knowing much knowledge in Java. Initially i didn't know about that and have fun reading the entire book, Head First Rails. Quickly did some basic programs... even i start posting blog on that - Setting up Ruby on Rails Environment in Windows and also deploy the sample application in Heroku.. a popular hosting provider for free...

Bit everything stops once i reached a particular stage. Reason is, i do not know about the interior programming language, Ruby. Now i realized and searched for some course and i found the Rubylearning and i enrolled in the course.
I missed the chance of joining it for free what they have provided it for their 25th batch. But anyway i paid it through my company and i joined. The course started and also thus my journey...

The first thing i learnt is Learning Ruby is Fun :) but mastering Ruby is difficult :(

I will post my experiences towards this journey so that the people like me who are coming from other language can get some idea on this.

Thursday, June 23, 2011

Jboss KB Project Validator problem in Jboss Tools with Eclipse 3.5

I just want to put this post in order to express my frustrations towards working with Jboss 3.1 tools with eclipse. We are using Eclipse 3.5 for our development work. Also we are using RichFaces for the front end development. Whenever we tried to do some changes in the JSP files, a progress bar with Jboss KB project validator gets started.
When we made change in less number of files, then the validator only runs for few seconds. If we give full build to the project, then the frustration gets started.. yes.. the system gets entirely hang and it will take around one hour to complete the process.
After analysis i found that, the problem will get fixed in the later versions of Jboss tools. I found the workaround solution from the following thread from the Jboss Community site.
We need to uncheck the Jboss KB Validator option from the menu Windows>Preferences>Validation. We can unselect only for the option box while build leaving the option for manual as it is.
By this way, we are able to do some work around to solve that problem.
Ok.. by the way we are talking about KB problem.. what is that.. its keep on coming to mind whenever that problem occurs... so.. after finding the solution.. i was little bit relaxed.. its nothinng but.. Knowledge Base. Its main purpose is to keep track of the related details about the files which includes content assist, bean configuration, etc...
So, anyway we are now having solution for this problem.

Sunday, May 29, 2011

Technical Conferences in India

Attending technical conference is one of the main area where we can gain & share more knowledge with peers of the same technical community. This is what i understood from various tweets i come across and also heard from various people of my contacts. So i thought to search for various events that take place in India.
I got many results that are occurring mostly in Bangalore and Mumbai. Few of them take place in Chennai too. The following sites helped me to filter some of my desired events which are in my technical area.




I plan to attend the following events that are occurring in Bangalore.



Anyway i missed the following event on Ruby on rails.


Hope to see other upcoming events that are taking place in India.

Friday, December 24, 2010

Favorite Tech Links

We used to come across different links while we working on a particular work. Each link will give an idea. Some will serve our purpose and some will not. I just want to group all those links which helped a lot along with what type of purpose it served. Hence i start writing this post and i hope it will be helpful to the people who used to google it.
Cloud Computing
Scaling an Internet architecture - This link clearly tells the difference between horizontal and vertical scaling in cloud.
SAAS, PAAS, IAAS - Difference - This link clearly tells the difference between SAAS, PAAS & IAAS and also guidance for Cloud Computing.
Introduction to Multi-Tenant Architecture - This link gives a basic idea about how multi-tenant architecture is built with an example.
Cloud computing terms - In order to get a knowledge on cloud computing, we should know the terminologies used over there. This link listed down most of the terminologies used in cloud.


Json
Dynamic Web Pages with JSON


JQuery
Nivo Slider – The most awesome jQuery Image slider


JSF & RichFaces
Practical example of the JSF 2.0 event system
Using datatables in JSF
Rich Faces - Live Demo - Scrollable DataTable
Switching tab via javascript in RichFaces




Thursday, December 23, 2010

97 Things Every Programmer Should Know

1. Act with Prudence

2. Apply Functional Programming Principles

3. Ask, “What Would the User Do?” (You Are Not the User)

4. Automate Your Coding Standard

5. Beauty Is in Simplicity

6. Before You Refactor

7. Beware the Share

8. The Boy Scout Rule

9. Check Your Code First Before Looking to Blame Others

10. Choose Your Tools with Care

11. Code in the Language of the Domain

12. Code Is Design

13. Code Layout Matters

14. Code Reviews

15. Coding with Reason

16. A Comment on Comments

17. Comment Only What the Code Cannot Say

18. Continuous Learning

19. Convenience Is Not an -ility

20. Deploy Early and Often

21. Distinguish Business Exceptions from Technical

22. Do Lots of Deliberate Practice

23. Domain-Specific Languages

24. Don’t Be Afraid to Break Things

25. Don’t Be Cute with Your Test Data

26. Don’t Ignore That Error!

27. Don’t Just Learn the Language, Understand Its Culture

28. Don’t Nail Your Program into the Upright Position

29. Don’t Rely on “Magic Happens Here”

30. Don’t Repeat Yourself

31. Don’t Touch That Code!

32. Encapsulate Behavior, Not Just State

33. Floating-Point Numbers Aren’t Real

34. Fulfill Your Ambitions with Open Source

35. The Golden Rule of API Design

36. The Guru Myth

37. Hard Work Does Not Pay Off

38. How to Use a Bug Tracker

39. Improve Code by Removing It

40. Install Me

41. Interprocess Communication Affects Application Response Time

42. Keep the Build Clean

43. Know How to Use Command-Line Tools

44. Know Well More Than Two Programming Languages

45. Know Your IDE

46. Know Your Limits

47. Know Your Next Commit

48. Large, Interconnected Data Belongs to a Database

49. Learn Foreign Languages

50. Learn to Estimate

51. Learn to Say, “Hello, World”

52. Let Your Project Speak for Itself

53. The Linker Is Not a Magical Program

54. The Longevity of Interim Solutions

55. Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly

56. Make the Invisible More Visible

57. Message Passing Leads to Better Scalability in Parallel Systems

58. A Message to the Future

59. Missing Opportunities for Polymorphism

60. News of the Weird: Testers Are Your Friends

61. One Binary

62. Only the Code Tells the Truth

63. Own (and Refactor) the Build

64. Pair Program and Feel the Flow

65. Prefer Domain-Specific Types to Primitive Types

66. Prevent Errors

67. The Professional Programmer

68. Put Everything Under Version Control

69. Put the Mouse Down and Step Away from the Keyboard

70. Read Code

71. Read the Humanities

72. Reinvent the Wheel Often

73. Resist the Temptation of the Singleton Pattern

74. The Road to Performance Is Littered with Dirty Code Bombs

75. Simplicity Comes from Reduction

76. The Single Responsibility Principle

77. Start from Yes

78. Step Back and Automate, Automate, Automate

79. Take Advantage of Code Analysis Tools

80. Test for Required Behavior, Not Incidental Behavior

81. Test Precisely and Concretely

82. Test While You Sleep (and over Weekends)

83. Testing Is the Engineering Rigor of Software Development

84. Thinking in States

85. Two Heads Are Often Better Than One

86. Two Wrongs Can Make a Right (and Are Difficult to Fix)

87. Ubuntu Coding for Your Friends

88. The Unix Tools Are Your Friends

89. Use the Right Algorithm and Data Structure

90. Verbose Logging Will Disturb Your Sleep

91. WET Dilutes Performance Bottlenecks

92. When Programmers and Testers Collaborate

93. Write Code As If You Had to Support It for the Rest of Your Life

94. Write Small Functions Using Examples

95. Write Tests for People

96. You Gotta Care About the Code

97. Your Customers Do Not Mean What They Say

Wednesday, September 1, 2010

Password protection to website directory - .htaccess

A simple technique to protect the website folder from access is as given below.

Step 1:

Create a simple file with an extension .htaccess

Step 2:

Create a simple file with an extension .htpasswd

Step 3:

Copy the given below commands in the .htaccess file and save it.

AuthName "folder name"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user


- the folder name is the website folder you need to do password protect
- /full/path/to is the full path of the .htpasswd file

Step 4:

Give the username and password as like below in the .htpasswd file and save it.

username:password

- username is the normal user name that you can give for protection
- password is the encrypted form of your password that you can give for protection
(You can get the encrypted code from the KXS website )

Step 5:

Place the .htaccess file in the folder where you need to protect.

Step 6:

Place the .htpasswd wherever you want inside the ftp but you need to specify the full path of the file in the .htaccess file. The full path may vary based on the hosting provider. An easy way is there to find the full path. Download the following php file Path Info. Place the file where you want to know the full path. Access the php file from the server. It will give you the full path.

Thats it! Now if you try to access the files inside the folder, it will ask for the username and password and your work is done.

For more information, you can visit this, HtAccess Tutorial site

Friday, August 6, 2010

Deploy Rails on Heroku

Heroku is one of the popular web based ruby hosting platform to launch our rails application. We can host our ROR demo applications free of cost to a certain level. Features like repository support, database support,etc are available. Using this we can host our application, work on that application from anywhere and update the application at anytime.
Prerequisites:
The following things are required in order to deploy the ROR application on Heroku.
1Heroku Account Setup
2GitHub Account Setup
3Repository Setup - Git Installation
4Public(ssh) key generation
5Repository Authentication
6Heroku Installation
7ROR Application setup
8Launch Application in Heroku
9References
Heroku Account Setup

An account is needed in order to work with Heroku.create an account from the Heroku site. Your username and password credentials are required in order to deploy the application. You can also create an application inside the heroku account for checking purpose.

GitHub Account Setup

GitHub account is required in order to authenticate the public keys in repository.Create a free account in the Git Hub site
After you logged in to the account, you need to upload the SSH public keys generated in the Public(ssh) key generation.

Repository Setup - Git Installation
In order to work with heroku, git repository is required.Download the latest Git version and install it.
Public(ssh) key generation
A public SSH key is required in order to authenticate the remote servers.
There are different ways to create SSH public key.
If your Git repository installation is already done, you can create as like below.
Type the following in command prompt
set path=%path%;C:\Program Files\Git\bin; [setting the git path]
cd C:\Program Files\Git\bin [Move to the bin folder]
ssh-keygen -t rsa -C "emailid" [generating a key pair with your email id]
id_rsa.pub and id_rsa files will be created. Use these two files wherever, ssh authentication is required.Copy the key from id_rsa.pub and paste it in the public key of github account.
For more information, refer Generating SSH keys
Repository Authentication

In order to test your git remote repository, you need to copy the SSH key files(id_rsa.pub and id_rsa) and paste it in .ssh folder in [C:\Program Files\Git\.ssh].

Type the following in the commmand prompt
ssh git@github.com
if Successfully authenticated message comes, then your remote repository setup will be working fine.
Heroku Installation
In order to deploy rails on heroku, Heroku gem needs to be installed in your system.
Type the following in the commmand prompt
set path=%path%;c:\ruby\bin; [set the ruby path]
gem install heroku [Remote installation of heroku gem]
heroku list[To list down the deployed applications]
It will ask to enter your heroku user crendentials.If, No public ssh key found error will be displayed, it means that, ssh authentication key is required. For that, you need to copy the SSH key files(id_rsa.pub and id_rsa) and paste it in .ssh folder in C:\Documents and Settings\[user]\.ssh.
Now if you run heroku list command again, successful authetication occurs by entering the user credentials and it will list down the applications that are currrently running in your heroku account.
ROR Application setup

Before starting with heroku, we need to ready with our ROR application. If it is not ready yet, refer the blogs, Setting up Ruby on Rails Environment and Ruby on Rails for Beginners in order to get ready with the application.

Launch Application in Heroku
Now, all the setup is ready and we are ready to launch the application.
As a first step, move to rails application directory in the command prompt and initialise the git repository. Type the following in command prompt
git init [initialise the application directory]
git add . [add the files to the repository]
git commit -m "your comment" [commit the files in the directory]
Now your application is initialized and added to git repository.
As a second step, an application needs to be created on heroku and it has to be added to the remote repository.
heroku create app-name [creating the application on heroku with the specified name]
git remote add heroku git@heroku.com:app-name.git [initialise the application to remote repository]
As a third step, push the code to the master repository.
git push heroku master [push the code to master repository on heroku server]
If it is first application to launch in heroku, then create .gems file with the rails version as shown below and put it in root folder to rectify the warning.
rails -v 2.3.8
Once done, run the following command for db creation in heroku
heroku db:migrate [creating db structure in heroku server]
Now the ROR application on heroku is ready and you can access it from anywhere.
References
1Heroku site
2Git Hub Site
3Ruby On Rails for Beginners
4Setting up Ruby on Rails Environment in Windows
5Hosting your Rails app – first look at Heroku
6Getting Started with Heroku on Windows

Sunday, August 1, 2010

Setting up Ruby on Rails Environment in Windows

Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language. It is intended to be used with an Agile development methodology that is used by web developers for rapid development.
Prerequisites:
The following things are required in order to set up the ROR environment.
1Ruby Installation
2Testing the Ruby environment
3Rails Installation
4Setting up the server
5Setting up the database
6Testing the ROR environment
7References
Ruby Installation

Rails framework is created using Ruby language and hence setting up the Ruby environment is the first thing to proceed. Download the latest ruby file ruby186-26.exe for windows and install it.
Testing the Ruby environment
Before moving on to rails, we need to test whether our ruby environment is set up properly or not. There are many tutorials available for testing it and you can check this blog Execute RUBY program on Command Prompt which is very simple to check at this stage.
Rails Installation
Once the ruby enviroment is ready, it is the time to install rails.Type the following in command prompt

gem update --system [To update the system with latest gems for ruby]
Ex: C:\ruby\prg>gem update --system
gem install rails --include-dependencies [Installation of rails along with all dependencies]
Ex: C:\ruby\prg>gem install rails --include-dependencies
The above installation is completed by automatically downloading from ruby site.
Setting up the server
Once the application is installed, we need to check whether the server setup is completed.By default, WEBrick server is coming along with rails installation. There is no seperate installation required.
In order to check the server, a sample application is required.
Type the following in command prompt
rails MyRails [creating an application called MyRails]
Ex: c:\rails>rails MyRails
Ex: c:\rails>ruby script/server [start the server & You will get a message console as given below....]
=> Booting WEBrick
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-07-24 00:12:41] INFO WEBrick 1.3.1
[2010-07-24 00:12:41] INFO ruby 1.8.6 (2007-03-13) [i386-mswin32]
[2010-07-24 00:12:41] INFO WEBrick::HTTPServer#start: pid=14200 port=3000
Now you can launch the application, http://localhost:3000 and a default welcome page will be displayed.
If you have done the above process, then server setup is completed.
Setting up the database
Rails can be easily configured with SqlLite database.We can install the database by remote using the below command.
install -r sqlite3-ruby
Ex: c:\rails>install -r sqlite3-ruby [remote installation of sqlite3 database]
In order to run the database, dll file is required and you can download here sqlit3 DLL Download
Download and extract the file sqlitedll-3_7_0.zip[sqlite3.dll, sqlite3.def] in C:\WINNT\system32 folder.

Now your system is ready for working with database.
There are some firefox Add-Ons available in order to view the SQLite database.
Testing the ROR environment

You can test the above environment by writing sample applications.One of the simple tutorial to get started with is given in the blog, Ruby On Rails for Beginners
Now the ROR environment is ready you can successfully run any type of applications in Rails.
References
1Rails Forum
2Derek Anderson's blog
3Ruby Forum
4Execute Ruby Program on Command Prompt
5SqLite Downloads
6Ruby on Rails for Beginners

Friday, July 16, 2010

How to post source code/syntax in Blog?

If you want to post the source code or highlight the syntax in Blogger, you can follow the below steps.
1. Login to Blogger and Go to design view
2. Edit HTML
3. Copy the CSS from Syntax Highlight CSS and paste it above the end of css section(i.e before ]]-->) in blogger template.
4.Download the code from Syntax Highlighter Support
and paste the code at the bottom after the comment, end outer-wrapper and above the end of body tag.
5. Save it and you are ready to use the syntax highlighter
Now you can post the code snippets by using “pre” or “textarea” tag as below.
In the pre tag just use, class="language" name="code". Language is the type of code we are going to put. For ex, ruby, java, xml, html etc..

Example:
Given below is the sample for ruby code.

def show_with_map
@incident = Incident.find(params[:id])
respond_to do format
format.html{
}
format.xml{
render :text=>@incident.to_xml (:only=>[:latitude, :longitude, :title, :description], :root=>"data")
}
end

end

Thanks for the original source from Heisencoder Blog.

Monday, May 17, 2010

Cloud Computing

What is Cloud computing?
It is Internet-based computing, whereby shared resources, software and information are provided to computers and other devices on-demand.

Why do we need that?
Round the clock availability of resources is a must and we can achieve using this.