JSON
Posted on December 11, 2008

JSON (JavaScript Object Notation) is a lightweight data-interchange format.
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

Area of use:Sending and Fetching AJAX request and response.

Advantage over XMLResponse Object: JSON doesn’t need a bit extra code to be manipulated by JavaScript on Client side, while manipulation of XML objects need minimum 4kb of script. As the number of browser in compatibility issue increases the size of script increases.

Sample PHP code:

$arr = array (’a'=>1,’b'=>2,’c'=>3,’d'=>4,’e'=>5);
echo json_encode($arr); // encode array to JSON string

Output:

{”a”:1,”b”:2,”c”:3,”d”:4,”e”:5}

Decode:

$json = ‘{”a”:1,”b”:2,”c”:3,”d”:4,”e”:5}’;
json_decode($json);

For further ref: JSON

CODE

function jsonRun(){
var myFirstJSON = eval({’myname’: ‘nirbhab’, ‘myfrnd’: ‘ankesh’});
var x;
for (x in myFirstJSON)
{
document.writeln(myFirstJSON[x]);
}
}

NOTE: Some servers doesn’t have json_encode() and json_decode functionality.
You can also use PEAR Service_JSON Class instead.
PEAR

Refer URL for advance Learning on JSON : http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

Multiple Main Method
Posted on December 11, 2008

One Of the Classes must have Main method as a member. This is what we normally expect.

But C# includes a feature that enables us to define more than one class with Main method.

As all of we know that Main is the entry point for program execution, but in C# we can have now more than one entry points .In fact there should be only one.

The very problem can be resolved by specifying which main is to be used to the Compiler at the time of compilation.

csc filename.cs/main: classname

Filename- Name of file where code is stored.
Classname- Name of class containing main which we would like to be entry point for our execution.
To explain it further
Application with multiple main method

Using system;
Class class A
{
Public static void main()
{
Console.writeline(“class A”);
}
}

Class class B
{
Public static Void main()
{
Console.writeLine(“Class B”);

}
}
During compilation we can decide which main method we have to use or we want to use by switching as.

/main:classA or /main:class B

Cron
Posted on November 25, 2008

In UNIX OS we have time based scheduling, means you can configure your system to do cleaning or repairing job, when you are away.
cron is driven by a crontab, a configuration file that specifies shell commands to run periodically on a given schedule.
Fields

# +—————- minute (0 - 59)
# |  +————- hour (0 - 23)
# |  |  +———- day of month (1 - 31)
# |  |  |  +——- month (1 - 12)
# |  |  |  |  +—- day of week (0 - 6) (Sunday=0 or 7)
# |  |  |  |  |
*  *  *  *  *  command to be executed

Different domain control panel have different interface, but all does the same task.
Any shell command can be used to run on specific time with certain interval.

Sample: php /path/to/script.php