Posted by: Asit | November 19, 2009

Pranav Mistry: Master of SixthSense Technology

Pranav Mistry demoed some sixth sense technology enabled tools TEDIndia. He showed that how a physical device can interact with the world of data and information. The interesting part is that he started working on his concept tools from using the motion sensors of an ordinary computer mouse.
With the full development and the implementation of his concept devices one can:
* watch the news as TV news printed on news paper,
* find more details of any physical object just by taking them in one’s hands,
* take pictures just by making frames using one’s fingers,
* pick any picture or block of data like a physical object and drop them on your computer screen or any other paper to modify them and a lot more.
Microsoft’s “Surface” is also based on multi-touch and gesture recognition, but has some limitations. The concept tools presented by Pranav are really  awesome and brilliant. The constructive use of this technology will bring a revolution in the future world.
I think the best use of this technology to help the physically challenged people. Just imagine how helpful it would be if we can make:
* Sixth sense enabled paper helping the deaf to display what others say,
* Sixth sense enabled earphones which tell a blind about an object name, type, size and distance,
* A speaking device which plays the dialogs which a dumb want to say and a lot more.
I really appreciate Pranav to come up with this brilliant idea.
Posted by: Asit | November 16, 2009

Basic Questions on PHP Part2

After getting a very good response on my earlier compilation “Basic Questions on PHP “, I am back with a new compilation of basic PHP questions on arrays.
1- How to check if a value exists in an array?
Ans- Use in_array() function for this.
Example:
<?php
$sample = array(“banana”,”apple”,”pear”,”banana”);
$newvalue = “pear”;
if (in_array($newvalue,$sample)) { echo “$newvalue is already in the array!”; }
?>
2- How to create an array of consecutive numbers and array of alphabets?
Ans:
<?php
$arr_of_numbers = range(1,10);//$arr_of_numbers = array(1,2,3,4,5,6,7,8,9,10)
$arr_of_letters = range(a,m); //$arr_of_letters = array(a,b,c,d,e,f,g,h,i,j,k,l,m)
?>
3- How to reset an array?
Ans: The reset() function does this and returns the first element of the array.
$sample = array(‘itm1′,’itm2′,’itm3′,’itm4′);
$first = reset($sample);
echo $first; //itm1
4- How to count the frequency a value appears in an array?
Ans: array_count_values() function does this operation. It returns an associative array with values as keys and their fequencies as values.
<?php
$sample_arr = array(1,0,1,2,0,2,2,2,3,4,2,5,2,3,5,3,1,5);
$most_popular = array_count_values($sample_arr);
print_r($most_popular);
?>
output: Array(
[1] => 3
[0] => 2
[2] => 6
[3] => 3
[4] => 1
[5] => 3
)
5- How to remove last element of an array?
Ans: array_pop() function does this.
$sample = array(“One”,”Two”,”Three”,”Four”,”Five”,”Six”);
$last = array_pop($sample);
echo “last element is “.$last; //last element is Six…
6- How to sort an array with alphanumeric values?
Ans: natsort() function will do this.
Example:
<?php
$sample = array(“1.gif”,”2.png”,”20.jpg”,”10.gif”);
natsort($sample);
print_r($sample);
?>
Output:
Array (
[0] => 1.gif
[1] => 2.png
[3] => 10.gif
[2] => 20.jpg
)
7- How to change an array into string?
Ans: We can achieve this using “implode()” function.
Example:
<?php
$sample = array(“I”,”love”,”PHP”);
$sample_to_string = implode(” “, $sample);
echo “$sample_to_string”;//I love PHP
?>
8- How to remove duplicate values from an array?
Ans: The array_unique() function will do this.
Example:
<?php
$sample = array(“pear”,”apple”,”pear”,”banana”);
$sample_to_unique = array_unique($sample);
print_r($sample_to_unique);
?>
Output:
Array
(
[0] => pear
[1] => apple
[2] => banana
)
9- How to interchange key to values and visa versa of an array?
Ans: We can do this using array_flip() function.
Example:
<?php
$sample = array(“John”,”Alice”,”Boby”);
print_r($sample);
$flipped = array_flip($sample);
print_r($flipped);
?>
Output:
Array
(
[0] => John
[1] => Alice
[2] => Boby
)
Array
(
[John] => 0
[Alice] => 1
[Boby] => 2
)
10- How to add an element at the begining of an array?
Ans: The array_unshift() does this. This function returns the number of elements in the array after additions of the new element.
Example:
<?php
$sample = array(2,3,4,5,6);
$no_sample = array_unshift($sample,1);
echo “Number of elements: $no_sample \n\n”;
print_r($sample);
?>
Output:
Number of elements: 10
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Hope these questions will help the PHP folks. I will come soon with some new PHP stuff.
Posted by: Asit | November 13, 2009

I Love Firefox

ff
Nov 09th is the birthday of Firefox and this year it has completed 5 years. I can say these five years firefox has  shown continuous growth to success and popularity. Being a web developer I can bet that firefox is the best internet
browser among others. Most of the open source web developers prefer to use this as default web browser. I can recall that I used IE only once just to download firefox on my personal computer. Our most of the development time goes in fixing design related bugs on IE and this is really frustrating.
Many many thanks to the firefox development community.
Posted by: Asit | November 12, 2009

Credit Card Traps

cardThe credit card is one of the very good facilities offered by banks. But some times this facility becomes a hassle for you and you feel like trapped. I’ve been through same kind of experience last month.
I got last month’s credit card statement. I was shocked to see that the bank added Rs.2000 for annual card fee, Rs.1000 for add-on card annual fee and some Rs.400 for the service tax against these annual charges. That made mycredit card due shoot-up to almost double.
I called to the bank customer care to resolve the issue. The executive told me the same story written in the statement. I claimed that this was not mentioned at the time of applying for the card. The executive then assured me that they are waving off those extra charges. She then said, “Sir we have a very good offer for the heath insurance policy. Just listen this offer”. I thought that there is no harm at least in listening the offer. She forwared the call to other (insurance) company executive, they tied up with. Then he started explaining the company health insurance offer. The guy was so smart and I don’t know when he snared me. He was about the activate the health policy and was going to deduct the policy premium from my credit card.
I scent that I am in trap, I suddenly stopped him. I totally refused to activate any policy linked to my credit card.
Then I came to know, why the bank added that extra amount. If one gets those extra charges and doesn’t call them, then he will have to pay that amount. If he calls regarding this, the bank will try to snare him in some offers. In both the cases the bank takes the benifit.
I would suggest everyone to be very careful with the use of credit cards. If you are smart enough, you will enjoy it’s benefits. In other case the facility will become hassle for you.
Posted by: Asit | November 12, 2009

AJAX Request Using YUI

Ajax stands for “Asynchronous Javascript And XML”. The interactions between client and server in the standard web applications are “synchronous”. This means that one request has to wait for other to complete. In asynchronous request scenario the multiple requests and responses are independent of each other. That means one request will not have to wait for the other to complete.
Yahoo User Inertface provides a good way to generate the XMLHttpRequest (Ajax request) through its “Connection Manager“. Here I am giving a very simple example to use YUI connection manager for this:

<html>

<head>

<title>Simple Ajax Request</title>

<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js”></script>

<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/event/event-min.js”></script>

<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/connection/connection-min.js”></script>

</head>

<body>

<h1>Simple Example of creating Ajax Request</h1>

<script>

//The callback function:

var callback = {

success: function(a){

//Assign the resonse to the HTML element

document.getElementById(‘response’).innerHTML = a.responseText;

},

failure: function(a){

//Alert the failure message

alert(a.statusText);

}

}

//Make the Ajax request:

function ajaxRequest(){

var newRequest = YAHOO.util.Connect.asyncRequest(‘GET’, ‘Request/Url’, callback);

}

</script>

<!–The div element in which the resonse will be shown –>

<div id=”response”></div>

<input type=”button” value=”Create Request” onClick=”ajaxRequest();”>

</body>

</html>

Hope this example helped in better understanding of Ajax using YUI.

Posted by: Asit | November 5, 2009

YUI Profiler

Yahoo User Interface (YUI) provides a very good feature to profile your javascript code. One can measure the performance of their code in the terms of the number of times the function call, average time, minimum time,
maximum time taken by a code block or script to execute. The best feature I feel with YUI code profiler is the ability to profile a specific code block like functions. Here I am going to present how to create a profile using YUI profiler for a code block:
Include the code profiler source file in your script:
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo.js”></script>
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/profiler/profiler-min.js”></script>
HTML block:
<div id=”p_report”></div>
<input type=”button” name=”d_profile” id=”d_profile” value=”Create Profile”>
JavaScript:
YAHOO.util.Event.on(‘d_profile’, ‘click’, function(){
YAHOO.tool.Profiler.registerFunction(“pObject.sayHello”);
var pObject = {
sayHello : function(){
return “Hello”;
}
};
//register method on a global object – no second argument needed
YAHOO.tool.Profiler.registerFunction(“pObject.sayHello”);
//alternate – providing second argument
YAHOO.tool.Profiler.registerFunction(“pObject.sayHello”, pObject);
//call this function
var hello = pObject.sayHello();
var calls = YAHOO.tool.Profiler.getCallCount(“pObject.sayHello”);
var max = YAHOO.tool.Profiler.getMax(“pObject.sayHello”);
var min = YAHOO.tool.Profiler.getMin(“pObject.sayHello”);
var avg = YAHOO.tool.Profiler.getAverage(“pObject.sayHello”);
YAHOO.tool.Profiler.unregisterFunction(“pObject.sayHello”);
document.getElementById(‘p_report’).innerHTML =
“pObject.sayHello(): was called ” + calls +” times.<br>”+
“The average time was ” + avg + “ms.”+”<br>”+
“The max time was ” + max + ” ms.” +”,<br>”+
“The min time was ” + min + ” ms.”;
});

The HTML part will display a button “Create Profile”. Clicking on that button will generate the report of the pObject.sayHello() function call and display the result in the div with id “p_report”.

This is just an example of how to use YUI code profiler.  Hope this will help creating code profiles.

Posted by: Asit | April 7, 2009

Badi Mushkil se Duniya me Dost Milte Hai….

This is a line of a famous Hindi song by Kishor Da. This line completely fits to my friends. 

My father got a major heart attack and I was in Bangalore. I had to rush to my native place, Kanpur. Before leaving, I just informed one of best friend around me about my arrival. I informed other and he booked the flight ticket on-line. I reached Delhi then from there I took train and reached Kanpur. I was trying to grab an auto, but what I saw another friend already waiting for me. He took me directly to the hospital where papa was admitted. Within half an hour all my true friends gathered at the hospital and offered to stay there for any kind of requirement.

We 5 guys stayed at the hospital for full 7 nights without a single nap for a single minute. In that span of time all of them slept just for 2-3 hours in day time. Although all of them were very busy in there work schedule and one of them was fasting for 8 days due to Navrata, they took care of my dad with me. Although they are not strong financially, they offered the financial support. But at that time I required moral support very badly which they provided just by their presence.

Now my dad is out of danger and about to be released from the hospital within 2-3 days. After being assured about papa’s health, I came back to Bangalore, but friends are still there supporting my family. I will not give thanks to them for their efforts but will pray to God to make me available whenever any of my friends seeks my presence.

Posted by: Asit | March 26, 2009

Funny things about Ghajini:

Amir Khan’s latest released movie Ghajini is the biggest Bollywood hit of the year 2008. I have seen the movie and appreciated a lot. I could find good humor in the happy part of the movie. but the kids of this generation are smarter and more humorous than the adults. Want to know how? Just read below….

fun in Ghajini

Humor in Ghajini

Here I am going to show how one can create breadcrumbs in the web application based on Zend Framework. This can be achieved by creating a helper method. Before creating helper method, we need to do the following exercise:

  • Create Zend view object,
  • Add view script path,
  • Add the default helper path to the view object,

Now lets start step by step:

Creating Zend view object:

$view = Zend_View();

Adding view script path:

$viewPath = “path/to/viewsDirectory”;
$view->addScriptPath($viewPath);

Adding the default helper path to the vew object:

$helperPath = “path/to/helperDirectory”;      Zend_Controller_Action_HelperBroker::getStaticHelper(‘viewRenderer’)->setView($view);
$view->addHelperPath($helperPath, ‘Helper_’);

Now creating the class for the breadcrumbs:

class Helper_BreadCrumbs {

public function breadCrumb(){
$cFront = Zend_Controller_Front::getInstance();
$module = $cFront->getRequest()->getModuleName();
$module = strtolower($module);

$controller = $cFront->getRequest()->getControllerName();
$controller = strtolower($controller);

$action = $cFront->getRequest()->getActionName();
$action = strtolower($action);

if($module == “default” && $controller == “index” && $action == “index”){
return;
}
//Home link
$home = ‘<a href=”/”>Home</a>’;

//start breadcrumbs
$bCrumbs = $home . “::”;
if($action == “index”){
$bCrumbs .= $controller;
}
else{
$bCrumbs .= “<a href=’/$controller’>$controller</a>::
<a href=’/$controller/$action’>$action</a>”;
}

return $bCrumbs;
}
}

Hope this article will help the web application users to indicate “where are you”.

Posted by: Asit | March 20, 2009

Zend Framework:: Caching the database query results

Caching is basically used to improve the performance of the application. Your application may consists of multiple expensive queries ruining the application performance.  The Zend_Cache component of Zend Framework provides a good feature to improve the page performance by caching the database query results. Here is the sample code :

// Creating the cache options
$frontend = array(
‘lifetime’ => 86400, // cache lifetime of 24 hours (time is in seconds)
‘automatic_serialization’ => true  //default is false
);

$cachedir = /path/to/cacheDirectory;
if(!is_dir($cachedir)){
mkdir($cachedir,0755);
}

$backend = array(‘cache_dir’ => $cachedir);

// Getting a Zend_Cache_Core object
$zend_cache = Zend_Cache::factory(‘Core’, ‘File’, $frontend, $backend);

$result = run_query($zend_cache);
print_r($result);

function run_query($cacheObj){
$q = “Database query”;
if(!$result = $cacheObj->cache->load(“myresult”)){
$db = Zend_Db::factory(DB_connection_parameters);
$result = $db->fetchAll($q);
$cacheObj->save($result, “myresult”);
}
else {
echo “This result is from cache.”;
}
return $result;
}

Caution: You should give the unique name in the “load(‘name’) and save(‘name’)” functions.
Otherwise you will get the same result on the pages where the query is intended to produce
different results.

Older Posts »

Categories