Archive for April, 2009

Cloud computing

Friday, April 10th, 2009

Cloud computing is a style of computing in which dynamically scalable and often virtualised resources are provided as a service over the Internet.

A research paper released on October 8th, 2007 by Greg Boss, Padma Malladi, Dennis Quan, Linda Legregni, Harold Hall from IBM states: “Cloud computing is a term used to describe both a platform and type of application. A cloud computing platform dynamically provisions, configures, reconfigures, and deprovisions servers as needed. Servers in the cloud can be physical machines or virtual machines. Advanced clouds typically include other computing resources such as storage area networks (SANs), network equipment, firewall and other security devices.

Cloud computing also describes applications that are extended to be accessible through the Internet. These cloud applications use large data centers and powerful servers that host Web
applications and Web services. Anyone with a suitable Internet connection and a standard browser can access a cloud application.”

Simply said, if you don’t need to have operating system & other software application installed on your device, what you need is a device that support web browser. You can use the application through web browser. One of the good example is eyeOS. eyeOS is one of cloud OS  out there. It’s an opensource project. After spent some hours playing around with it, I’ve got the feeling that i’m in love with it. Here is the website of eyeOS: http://www.eyeos.info/

flexible constructor in JavaScript

Friday, April 10th, 2009

Javascript provides flexible constructor. Below are sample code that implement the flexible constructor:

var Student = function(_department, _course, _year){
	department = _department || "";
	course = _course || "";
	year = _year || "";

	this.set_department = function(_department){
		department = _department;
	}

	this.set_course = function(_course){
		course = _course;
	}

	this.set_year = function(_year){
		year = _year;
	}

	this.display_information = function(){
		console.log("Information of the student:");
		console.log("Department: " + department);
		console.log("Course: " + course);
		console.log("Year: " + year);
	}
}

//constructor
var obj_student = new Student("Computer Information Scince", "ICT", "2");
obj_student.display_information();

var another_obj_student = new Student();
another_obj_student.set_department("Technology");
another_obj_student.set_course("BIS");
another_obj_student.set_year("Foundation");
another_obj_student.display_information();

Sample output:

Information of the student:
Department: Computer Information Scince
Course: ICT
Year: 2
Information of the student:
Department: Technology
Course: BIS
Year: Foundation

Javascript inheritance

Monday, April 6th, 2009

Inheritance in javascript can be implemented easily using the concept of mixin. Below is an exmple to demonstrate javascript inheritance:

ClassA = function(){
	this.display = function(){
		console.log("here's a display function in ClassA");
	}

	this.str = function(){
		return "string in ClassA";
	}
}

ClassB = function(){
	ClassA.call(this);

//overriden method
	this.str = function(){
		return "string in ClassB";
        }
}

//instantiate object of ClassB
obj = new ClassB();

//calling display method from ClassA
obj.display();

//this will invoke str method in ClassB NOT in ClassA
console.log(obj.str());
here’s a display function in ClassA
string in ClassB string in ClassB

Javascript: delete property from object & element from array

Monday, April 6th, 2009

As we are working with object or array, sometimes, we need to delete it’s property of element. Below is an example of a simple way to do it.


var display_before = function (str){
    return "before delete " + str;
}

var display_after = function (str){
    return "after delete " + str;
}

var obj = {x:12, y:15};
console.log(display_before("obj.x") + " " + obj.x);

//delete property x from object
delete obj.x;
console.log(display_after("obj.x") + " " + obj.x);

//delete array[2]
var array = [2, 4, 6, 8, 10]
console.log(display_before("array: ") + array);

array.splice(2,1);    //delete value 6 from array
console.log(display_after("index 2 from array: ") + array);

Sample result (in firebug plugin):

before delete obj.x 12
after delete obj.x undefined
before delete array: 2,4,6,8,10
after delete index 2 from array: 2,4,8,10