Sunday, May 25, 2008

AshishKulkarni.com - Ashish Kulkarni's very own website

Finally I managed to get some time to get my own website/blog at www.ashishkulkarni.com sorted out.

My domain name was lying around for a long time. Finally I got some time and have got a wordpress blog sorted with a decent theme.

From now on, I am going to create at least one blog entry per week.

-Ashish Kulkarni
http://www.ebizss.com
http://www.ashishkulkarni.com
http://www.sapforbusiness.com

Tuesday, July 11, 2006

Installing Ruby and Rails Framework from behind a firewall

I think it is the frustration of not being able to do something very simple that often leads programmers to feel elated to see something as simple as the Hello World printed on the screen.

I mean, if you can do it with a simple "echo Hello World", why do you need all these fancy languages?

Anyway, I have been trying to go where probably a lot of men have gone before. But I am going to leave a map for those that follow.

Task: Install Ruby and ROR framework from behind a firewall.

Part 1. Installing Ruby.

This is faily straightforward.

Just click on the following link and that should give you the executable to install Ruby:

ruby182-15.exe

Note: Make sure C:\ruby\bin is in the path.

Part 2. Installing RubyGems.

Again, click on the link below to get RubyGems zip file:

rubygems-0.9.0.zip

Unzip file file. This will create a directory like C:\rubygems-0.9.0.

CD C:\rubygems-0.9.0
ruby setup.rb

Part 3. Installing Rails.

The documentation asks you to type "gem install rails --include-dependencies". But what if you are behind a firewall? Or even worse, don't have internet connection? It might seem impossible in this day and age, but there are people who don't have internet connection.

You will get a smug little error like:

ERROR: While executing gem ... (SocketError)
getaddrinfo: no address associated with hostname.

Not much descriptive is it? You won't find much help anywhere else either. But here is all the help you will need. This is what you do:

1. Open Internet Explorer and go to rubyforge gems subdirectory. Here, if you say that you don't have internet, well, you will need to go to a Net Cafe and download some files then....and copy these to a floppy.

2. Here, find the following files and save them to your local drive (I am assuming you are saving these to C:\).

a. actionmailer-1.2.3.gem
b. actionpack-1.12.3.gem
c. actionwebservice-1.1.4.gem
d. activerecord-1.14.3.gem
e. activesupport-1.3.1.gem
f. rails-1.1.4.gem

3. Next, go to command prompt and change directory to where you saved the gem files (C:\ in my case) and run the following commands one by one.

gem install activesupport
gem install activerecord
gem install actionwebservice
gem install actionpack
gem install actionmailer
gem install rails

Part 4. Running rails for the first time.

Run the following commands to create a skeleton rails application:

C:
CD rails rails
(This will create a sample application under C:\rails)
CD rails
ruby script/server
(This should kick off WEBrick)
Open a browser and visit http://localhost:3000

Initial WEBrick console should look like:

C:\rails>ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-07-11 13:10:27] INFO WEBrick 1.3.1
[2006-07-11 13:10:27] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-07-11 13:10:27] INFO WEBrick::HTTPServer#start: pid=57 port=3000

After you visit http://localhost:3000, it should look like:

C:\rails>ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-07-11 13:10:27] INFO WEBrick 1.3.1
[2006-07-11 13:10:27] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-07-11 13:10:27] INFO WEBrick::HTTPServer#start: pid=57 port=3000
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET / HTTP/1.1" 304 0 - -> /
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /javascripts/prototype.js HTTP/1.1" 304 0 http://localhost:3000/ -> /javascripts/prototype.js
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /javascripts/effects.js HTTP/1.1" 304 0 http://localhost:3000/ -> /javascripts/effects.js
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /images/rails.png HTTP/1.1" 304 0 http://localhost:3000/ -> /images/rails.png

Press Ctrl-C here and that should shut WEBrick down.

So now you really don't have any excuse not to get onto Rails.

Wednesday, June 28, 2006

LeapYear V2

And Neo said....'Hmmmm. Upgrades'.

Here is the version 2.0 of the program:

# LeapYearv2.rb - This program reads an year and tells whether it is a LeapYear or not.
# Author - Ashish Kulkarni (http://ashishkulkarni.blogspot.com)
# Date - 28-Jun-2006

GregorianCutoverYear = 1582

puts 'Please input the year for checking for Leap Year:'
STDOUT.flush
year = STDIN.gets.chomp.to_i

if (year >= GregorianCutoverYear && # Gregorian
((year.modulo(4) == 0) &&
((year.modulo(100) != 0) ||
(year.modulo(400) == 0)))) ||
(year < GregorianCutoverYear && # Julian
year.modulo(4) == 0)
puts 'It is a Leap Year'
else
puts 'It is not a Leap Year'
end


Output:

Please input the year for checking for Leap Year:
2000
It is a Leap Year

Please input the year for checking for Leap Year:
2002
It is not a Leap Year

Please input the year for checking for Leap Year:
2004
It is a Leap Year

Please input the year for checking for Leap Year:
2006
It is not a Leap Year

Please input the year for checking for Leap Year:
3000
It is not a Leap Year

LeapYear Assignment

Program:

# LeapYear.rb - This program reads an year and tells whether it is a LeapYear or not.
# Author - Ashish Kulkarni (http://ashishkulkarni.blogspot.com)
# Date - 28-Jun-2006

puts 'Please input the year for checking for Leap Year:'
STDOUT.flush
year = STDIN.gets.chomp.to_i

if year.modulo(4) == 0
if year.modulo(100) == 0
if year.modulo(400) == 0
puts 'It is a Leap Year'
else
puts 'It is not a Leap Year'
end
else
puts 'It is a Leap Year'
end
else
puts 'It is not a Leap Year'
end

Output:

Please input the year for checking for Leap Year:
2000
It is a Leap Year

Please input the year for checking for Leap Year:
2001
It is not a Leap Year

Please input the year for checking for Leap Year:
2003
It is not a Leap Year

Please input the year for checking for Leap Year:
2004
It is a Leap Year

Please input the year for checking for Leap Year:
2008
It is a Leap Year

Please input the year for checking for Leap Year:
3000
It is not a Leap Year

I made use of the Ruby Manual under C:\ruby\doc\ProgrammingRuby.chm to find the modulo() function.

Tuesday, June 27, 2006

The drive to Falkirk

To get a permanent driving license in UK, one needs to do the following:

1. Get a provisional driving license (you can't proceed any further unless you have got this). This is a 2 part document. First part is a plastic card and second part is a paper document.
2. Pass the Driving Theory Test. This has 2 parts. First is a multiple answer section of 35 questions. You have to get atleast 30 of them correct. Second is a section of 14 video clips. You have to click the mouse as soon as you can see a hazard. Once you pass this, you get a theory certificate which remains valid for 2 years.
3. Once you have a provisional driving license, you can start taking driving lessons. Once you have passed the theory test, and your instructor feels that you are ready, you can apply for the practical test. You can give as many practical tests as needed (to pass) before your theory certificate runs out. If that happens, you need to sit your theory test again.
4. The practical test is a one hour drive where the driving examiner sits next to you and asks you to drive around. This takes place not in a test area but on real road and amongst real traffic. They have recently added a bit where they ask you to open the bonnet of the car and ask you a few questions about the stuff under the hood.

My practical test is on the 18th of August 2006. And my driving instructor John has been telling me that I need to get more practice than just the one hour that he takes me out every week.

The irony is that I already have a car which Kate generously bought for me as my birthday gift last year.

So eventually this Sunday, after a long time, I got behind the wheel of my car and drove it around Stirling and Bannockburn. For those who don't know much about Scottish History, Stirling is where the famous battle between Scots and English took place. You can see the results in the movie Braveheart.

Stirling has got the Wallace Monument where William Wallace's sword rests....and also a beautiful castle - The Stirling Castle.

On Sunday, I drove around all these places.

Unfortunately John was off sick on Monday. So Kate decided to take me for a run in the car.

And I drove all the way from Stirling to Falkirk via Camelon and Larbert and came back via another road - over the Kinkardine Bridge.

It was a good drive and I came back via Alloa. I hope to get some more hours behind the wheel.

gets lives to see another day

Found another interesting function - gets

printf "Name: "
STDOUT.flush
name = gets
printf "Hello " + name

Output:

Name: Ashish
Hello Ashish

The journey of discoveries continues.

printf reborn

I was looking for ways to format the Ruby output and lone-behold, bumped into an old friend - printf.

printf "%3.2f\n", 2.0 / 3.0

Output:
0.67
(and a big grin on my face)

The escape character for escaping the newline works only on double quotes and together with printf, gives me the comfort of knowing that a bit of c/Java syntax is still at the heart of Ruby.

Comments in Ruby!!!

Just finished the next few Ruby programs. What did I learn? Well, the first thing is COMMENTS!!!

Single line comments start with #. Put a # anywhere on the line and rest of the line becomes a comment.

Multiline comments start with =begin and end with =end.

It must be noted that /*, */ and // do not work.

Just tried the oracle way and no, -- does not work either.

Semi-colons, whether at the beginning or at the end of the, statement are ignored as well.

I hate to say this but Ruby is a completely new language. So woe is me. No shortcuts. I will have to learn everything from scratch.

And I thought that they were joking when they said life begins at 30 (in my case, 34).

No, I don't feel like Alice in wonderland or Dorothy following the yellow brick road.

I still have more questions.

Yes, I do want to know as to why people start new languages rather than adding to existing ones. But we won't go there yet.

Now that we can output stuff, my next question is how do we read stuff from console into variables?

And how do we format the output?

And how are dates stored?

Again, I am sure, all will be revealed in good time.

Kate wants to know who this Ruby is that I am spending half an hour with everyday.

Sunday, June 25, 2006

The Laird (Lord in Scottish) of Kincavel

Kate, my Scottish wife, has bought me a plot of land in the Kincavel Estate. This entitles me to use the title of Laird (Owner of Land or Lord in Scottish) officially.

The Kincavel estate lies on the Ardnamurchan peninsular, which covers 50 square miles and is due west of Fort William.. There are around 2000 human inhabitants of the peninsular, but many more thousands of creatures and plants, some of which are very rare. The north coast of the peninsular faces the Islands of Muck, Eigg and Rhum, while the south coast runs alongside Loch Sunart and the Sound of Mull.

The Kincavel estate is within a large area of land belonging to the Sonachan Hotel – 1000 acres in total - 400 of which have been enclosed by fences to encourage the natural regeneration of the flora and fauna without damage by farm stock. Sonachan is located between the beautiful sandy beaches of Ardnamurchan’s north coast and Tobermory – the scene for children’s television show on BBC ‘Balamory’, which is a short ferry ride away on the Isle of Mull.

The Kincavel Estate itself is just a few hundred yards from a secluded golden sandy beach – visitors at some times of the year are likely to find they have it all to themselves! Your land is on a seaward facing hillock and looks out over the sea to the Isle of Mull. On a nice day it is the perfect place for a picnic as there are spectacular views in every direction; across the mountainous countryside inland and over the sea to the Isle of Mull.

Nearby attractions include the Ardnamurchan Natural History Centre and Ardnamurchan Point lighthouse. This lighthouse was one of many built by the Stevenson family, and is the only one in the world built in an Egyptian style. Ardnamurchan Point is the most westerly point in mainland Britain – a claim often wrongly thought to belong to Land’s End in Cornwall.

The nearest village to the Estate is Portuaik – the most westerly settlement on the mainland, overlooking Sanna Bay. From the village there are also views across to the Isle of Skye and the Small Isles.

Well, so now I am a Scottish Laird (Lord) :-).

Interesting stuff.

Saturday, June 24, 2006

Hello World in Ruby

puts 'Hello World'

And thats it. The interpreter comes to life and prints the famous words on the console.

What is interesting is after I installed Ruby, all I have to do is go to command-line and type the name of the program - Hello.rb in this case - and the program runs.

Not really impressed by SciTe as yet....but already like it better than Eclipse.

But I have so many questions...how do I write comments?...how secure is Ruby?....how do I create web-applications talking to ruby?....and I am just hoping I don't have to write the same amount of code as C or Java.

Another thing I am noticing is there are quite a few Japanese Names all over Ruby. Obviously, as Ruby was created by a Japanese person, this is to be expected. It is sad that we don't see the same amount of Solidarity within Indians. To some extent, this is our undoing.

The good thing is if it was created by a Japenese, then it will have a bigger acceptance in Japan.

Early days....lets see where we go from here.

Starting Ruby

Started with Ruby today...with installation.

I am using a Windows XP based Laptop. So used the One-click installation from
http://rubyinstaller.rubyforge.org

It is an interesting installer. Unlike the Sun JDK which requires you to download a separate IDE, the Ruby installer comes with SciTe IDE.

Lets just hope it is not a shite IDE :-).

Monday, June 13, 2005

Trip to Kinlochleven and Glencoe

I went to Kinlochleven this weekend with my family and friends. Graham did most of the driving so my wife Kate was able to enjoy the view for a change.

I got Graham to drop me off at Glen Coe on Saturday early in the morning at 6:00 AM. I spent the next 5 hours taking photographs of Buchaille Etive Mor and nearby waterfalls.

I thoroughly enjoyed it.

Later we got ready and left to Ben Nevis. The day was absolutely lovely. Unfortunately, I slept most of the way to Ben Nevis.

While coming back, I was awake and enjoyed the drive through Fort William.

On our way back, we stopped off at Lochleven and I got a few more photographs.

When we reached home, I went to see the Waterfalls that Graham kept on talking about. I must say I was not prepared for what I saw.

Not just the waterfall itself, but the road leading up to it too was soo beautiful that I think I could spend a good few months in that location and still there would be more on offer.

Hopefully I will be going back in either a couple of weeks or a month and spend more time there. Next time I will arm myself with something against the midges. They must have had a field day biting me.

Also, by the next time, I would have received the results from my snaps of this weekend as I was using Slide Film in addition to digital. So fingers crossed.