Skip to main content

Posts

Showing posts from November, 2014

Recursion and Tail Recursion

Consider a simple factorial function
Here is a simple Java implementation that uses recursion:
1 2 3 4 5 6 7 8 9 10publicvoidfactorial(intn){if(n<=1){return1;}else{returnn*factorial(n-1);}}
If you called factorial(5), this is how recursion evaluate.
factorial(5)
5 * factorial(4)
5 * (4 * factorial(3))
5 * (4 * (3 * factorial(2)))
5 * (4 * (3 * (2 * factorial(1))))
5 * (4 * (3 * (2 * 1)))
120
Note how every recursive call has to complete before the java interpreter begins to actually do the work .
Here's a tail-recursive version of function that add N Integers.
1 2 3 4 5 6 7 8 9 10publicstaticintsum(inta,intb){if(a==0){returnb;}else{returnsum(a-1,b+a);}}
Here's the sequence of events that would occur if you called sum(5,0).
sum(5, 0)
sum(4, 5)
sum(3, 9)
sum(2, 12)
sum(1, 14)
sum(0, 15)
15
In the tail-recursive case, with each evaluation of the recursive call, the b is updated.

Robotframework running on jenkins CI

This is sample video which running Robotframework project on Jenkins CI , On request I will provide Full tutorials .


Installing rails on ubuntu

Ruby on Rails is one of the most popular application stacks for developers wishing to create sites and web apps. The Ruby programming language, coupled with the Rails development framework, makes app development simple.

Since Ruby on Rails doesn't come in a neatly packaged format, getting the framework installed used to be one of the more difficult parts of getting started. Luckily, tools like rvm, the Ruby Version Manager, have made installation simple.

Before any other step install mpapispublic key (might need gpg2) (see security)

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Install RVM (development version):

\curl -sSL https://get.rvm.io | bash  you need to do is source the rvm scripts by typing:

source ~/.rvm/scripts/rvm

The Quick Way

The quickest way of installing Ruby on Rails with rvm is to run the following command as a regular user:

\curl -sSL https://get.rvm.io | bash -s stable --rails

You will be prompted for your regular user&#…

symbols in ruby

Symbols are good way to save memory,What's that mean?. When object is created each time in ruby it is allocated with a memory,when we instantiate same object again and again it will also create a additional new memory.But symbols don't lets look in to a example

When ever we instantiated the same object in each time the object_id of that string object gives different memory locations but in case of symbols memory location are same.Thats means symbols can hold the same for each call but string cannot.

Integers and floats in ruby

Numbers in ruby are divided in to integers and floating point number and they are called Decimal numbers.You can do all kinds of mathematic operations in ruby.

These are integer operation Bignum and fixnum are two subclass of integers


Floating numbers are decimal numbers always returns a floating number.

variable in ruby

Variables are temporal space for assigning a value in programs.It is like when we assign value in some variable in algebraic equation back in schools.In ruby we can assign any value in to variable.

Here x = 10 that means a value of 10 is assigned to variable x and y is assigned a value of 20.When a variable assigned with a particular type of object the variable also act a like type of that object so when we call "x.class" it will return fixnum. When we call variable that is not initialized,it will return with message uninitialized local variable z.

class in Ruby

"class is a blueprint of an Object" What's that mean? Object and class,An object is a package which are called at the runtime which cannot modified at run time,So what we defined in class are converted to object and this object are called at runtime execution.
so we can call class as a blue print of an object.In class we actually designing our program for the output what we required.We can include method inside the class so methods need variable declaration for their operations,Programmers can decide these methods and variables should be kept as private for outside the class.All kinds of designing are done inside the class.Lets look at an example how class and object are created at ruby.
To crate a class in ruby, use the key word class and class name should start with capital alphabetic letter and to create a object use the keyword new


In this program Animal is the class and dog is the method inside method there is a message of string type,When we call this class as…