Sep 4, 2010

Build you own Highly Available Cluster with 'Wackamole' and 'Spread'

By :


Yair Amir
Ryan Caudy
Ashima Munjal
Theo Schlossnagle









This application works on a bunch of virtaul IPs and sees that all these IP remain available on a bunch of machines hosting these IP's. Constraint is that these bunch of machines should be on same LAN. If one machine goes down 'Wackamole' ensures that rest of the machines take over those IP's and all 20 IP remain visible to outer world at all times.

More to come....

Sep 3, 2010

Developing Applications for Twitter using its API.

Twitter is widely used application and I use it a lot and sometime or other I have felt the need to build something of my own to facilitate my style of usage or to actuate upon my ideas. In this post I'll be sharing my journey from a newbie to twitter app developer by sharing each step as I go through.  Hope this helps all those new to twitter API.

Step 1: Register your application with twitter. Here is the link to do that :http://dev.twitter.com/apps/new

 After registration you will be provided with consumer and secret key to be used for authentication. Though during registration process twitter will ask you to provide domain name. It does not means that you need to commit your files to that domain, you can work locally too.

Step 2: Download OAuth library for the language that you'd be using for developement. I am using PHP and downloaded quite a few libraries to try namely : 
 http://classes.verkoyen.eu/twitter_oauth
http://github.com/themattharris/tmhOAuth/

Step 3: Apart from consumer key and secret key there are user_token and secret token, you can see them in your app>>My Access Token

Step 4 : First Example

As a first timer use this example :

and just copy and paste the code to get the feel of the API.
Step 4 : Replace blanks with appropriate values from your app of the following variables :
        'consumer_key'    => '',
        'consumer_secret' => '',
        'user_token'      => '',
        'user_secret'     => '',


Step 5 : Save the file and run in your web browser. I used xampp for server.
Step 6 : Voila !!!! you just updated the status from PHP API.

More to come...
 
 

Aug 29, 2010

What is Fault Tolerance ?

An application having n software modules and n servers is able to function properly even if any of the server or module fails is known as 'fault tolerant'.

What is five nine's availability ?

Very commonly we come across the figure 99.999 % uptime or availabilty. But what actually does it means in practical terms. Here is the explanation :
60 seconds * 60 minutes * 24 hours * 365 = 31,536,000 seconds.in a year
99.999/100*31,536,000 = 31535684.64 seconds
Now : 31,536,000 - 31,536,000 = 315.36 seconds of downtime or approximately 6 minutes of downtime in a year.

What is Scalability ?

In common terms, you develop an application expecting that it will at max can have a concurrency of 100 users or approx. 3000 hits per day and contrary to that, same application starts to get hit in excess of 10000 users daily and is increasing by day. 

If you are able to cover up this increase in no.of users by adding more machines then you are doing 'Horizontal Scaling' on the other hand if you are adding up more powerful CPU or RAM then you are doing 'Vertical Scaling'. Hence, scaling is nothing but increasing resources to accommodate the increase in load.
When a system or web application is able or flexible enough to allow this increase in resources it is known as 'Scalable' and is known to have 'Scalability'.

Aug 28, 2010

Installing Cassandra on Ubuntu

Installing Cassandra

Download and extract Thrift :

1. Install dependencies (Ubuntu)
sudo apt-get install libboost-dev automake libtool flex bison pkg-config g++
 
2. Change to Thrift Directory 
./configure
make
make install
This should install thrift on your system. 



1. Go to http://cassandra.apache.org. On home page there is a link to download the latest stable release. Download the latest version.

2. Save the downloaded file......lets say in /home/Downloads (ubuntu ) .

3. Extract the file to /whereveryoulike/. I use /home/Cassandra62.

4. Change into the directory ... $ cd cassandra62

5. $avemaria-laptop:/home/cassandra62 # : ls

6. Output should be something like this -

bin          conf     DISCLAIMER.txt  lib          NOTICE.txt  test
build.xml    contrib  interface       LICENSE.txt  README.txt
CHANGES.txt  debian   ivy.xml         NEWS.txt     src


_____________________


Now the installation of Cassandra which is pretty easy and straightforward :

cd into directory named 'bin' :
and ./cassandra -f
This will run your cassandra and the output will be shown of the foreground hence the flag -f.


If you see 'Cassandra Starting up' that means your Cassandra is up and running and you are ready to play with her...

Jun 6, 2008

I said more on PHP didn't I .....

Q. What is a query string?
A. A query string is attached to the end of the URL in a link. A query string can consists of as many name/value pairs as developer wants to supply.

Q. What is HTML form element?
A. The user fills out the various text boxes and clicks a submit button when ready, the information that is supplied is then bundled up in one of the two ways and sent to the web server. The web server can then pull out this information and supply it to the PHP engine. PHP manipulates the information and sends it back as a part of HTTP response to the browser. Values submitted in form are always string.

Q. Can we use more than one submit button?
A. Yes, by changing their name.

Q. How can we submit form without the submit button?
A. We can use simple java script code linked to an event trigger of any form field. documetn.form.submit()

Q. In how many ways can we retrieve the data from result set of mysql?
A. As individual objects or as set of arrays.

Q. How many types of tags are available in PHP?
A. Four
standard tags, short tags, script tags, ASP tags.

Q. How does PHP limits the use of whitespaces?
A. We cannot have any whitespaces between We cannot break apart keywords.
We cannot break apart variable names and function names.

Q. How many types of data types are there?
A. Scalar and composite.

Q. What is NULL ?
A. NULL indicates that the variable has no value. A variable is considered to be NULL if it has been assigned the value NULL, or if it has not yet been assigned a value at all although in latte case PHP may output a warning if we attempt to use the variable.

Q. What is resource data type?
A. The resource data type is used to indicate external resources that not used natively by PHP but that have special meaning in the context of a special operation. We cannot convert any value to resource however a resource can be converted to a numeric or string data type in which case PHP will return the numeric ID of the resource.

Q. What is variables variable or $$?
A. It is a variable whose name is contained in another variable.

Q. How do we determine if variable exists?
A. A call to isset() will return ture if a variable exits and has a value other than NULL.

All about Php and more to come........

  1. Difference between Echo and Print?


Ans. Print return its success as a boolean and echo does not returns anything.


  1. How can I remove spaces from around the string?

Ans. By using TRIM function.


  1. How do I calculate MD5 hash of a string?

Ans. $md5=md5($text); md5 is a secure hashing function. No matter how long data stream it converts into a digest of a fixed size.


  1. How do I convert newlines to HTML line break tags?

Ans. Nl2br is used for this.


  1. How do I fetch metatags from page using PHP?

Ans. $gettags = get_meta_tags(“http://...................”);

foreach ($gettags as $i => $value)

echo .........;

  1. How do I remove trailing whitespace?

Ans. By using CHOP function.


  1. How do I turn a sting into an array?

Ans. $string= “ array”;

$array=explode(“,'',$sring);


  1. What is the difference join and implode in PHP?

Ans. Both are just variants of same thing


  1. What is an Echo function?

Ans. Echo function is actually not a function but a language construct, meaning that it doesnt need parentheses to contain arguments and it doesnt require a return a value.


  1. How do online PHP programs run?

Ans online php programs run when a request is made to the Web server. The request tries

to get to the web server to retrieve and send the file requested. But before the response is composed, the php engine has chance to process the php code in the file. Only a single php file can run at a given time because only one file can be requested at a time from the server.


  1. How can we convert data types in PHP?

Ans The php function gettype() can be used to determine the current type of the variable and settype() forces a variable to be of particular type.


  1. What is the difference between Unary operator and binary operator?

Ans Operator that need only one operand are known as Unary operator like ++ , -- . Operators that need two operands are called binary operators like $a = $b;


13 what is strlen() function?

Ans. The strlen() function finds the length of the string it counts all the characters and returns the total.


  1. what is strstr() function?

Ans. Gets any part of the string thats after the first instance of a particular characters or string within a string returns True or False.


  1. What is chr() function?

Ans. Returns a string character value corresponding to the decimal ASCII value entered as a argument.


  1. What are Arrays?

Ans. Arrays are variables of type array. Technically, arrays are lists made up of keys the index and values. They are almost like mini relational database that is dynamic.


  1. Is array() a functin or a language construct?

Ans. The array() function is a language construct not a function. It is used to create an array and accepts the values as arguments. PHP arrays always keep index numbers.


  1. What is print_r ?

Ans. It enables us to print the entire contents of an array along with the name of each indexed elements.


  1. what is count() function?

Ans. It is used to count the total no. elements in an array.


  1. What is array_count_values ?

Ans. It returns the frequency of occurences of matching values.


  1. What is array_flip() ?

Ans . It is used to swap value for key name and vice-versa.


  1. What is the difference between sort and asort?

Ans. The sort function rebuilds the index into the proper order whereas changing the order of the elements on the other hand asort does not change the index values.


  1. What are superglobal arrays?

Ans. The predefined arrays which can be accessed from anywhere in a PHP prog. Without having to use global keyword and without regard for scope.