Five Inspirational Quotes on Leadership

Five Inspirational Quotes on Leadership

“Leadership is the capacity to translate vision into reality.”
— Warren G. Bennis

“Leaders must be close enough to relate to others, but far enough ahead to motivate them.”
— John C. Maxwell

“Affirmation without discipline is the beginning of delusion.”
— Jim Rohn

“Effective leadership is putting first things first. Effective management is discipline, carrying it out.”
— Stephen Covey

“Good management is the art of making problems so interesting and their solutions so constructive that everyone wants to get to work and deal with them.”
— Paul Hawken

Source: http://www.quotestreasure.com/topics/leadership.html

PHP Serialization vs JSON Encoding for an array

PHP Serialization vs JSON Encoding for an array

When I was working for saving huge array in database, an idea came to mind to look into serialization against JSON. So I searched on internet and found that serialization technique is fast and I also read somewhere that unserialization for huge data is slow as compared to json_decode.

So, I made a program and do an experiment to find out the complexity for space and time of both methods with respect to the data size. Now, I am sharing my results with you. Let see.

My program generates the statistics for serialize/unserialize and JSON encode/decode and also size of serialized and JSON encoded data.

Let see the graphs.

You can see that the json_encode() is very fast as compared to serialize(). But as we know that, encoding will be useless if decoding is slow for a method. So let see the decoding/unserialization graph.

If you look for less data size, you will find that the process is fast for unserialization and for data size larger than 25000, JSON decoding is going to be faster as compared to unserialize. So, it means that if you are working for huge data than use json_decode().

Ooopsss. . . space complexity for serialization method is too high.

Conclusion:
If you have small sized data then you can prefer serialization But for large data, serialization will be a worst choice if data is simple and just like an array.

I did this experiment for only arrays. May be results will be different for objects.

Program that I made for this experiment

	ini_set('max_execution_time', 0);
	
	function start_timer()
	{
		global $time_start;
		return $time_start = microtime(true);
	}
	
	function end_timer()
	{
		global $time_start;
		$totaltime = microtime(true) - $time_start;
		echo 'Process completed in ' . $totaltime*1000 . ' ms</br>';
		return $totaltime;
	}	
	
	function get_random_string($valid_chars, $length)
	{
		$random_string = "";
		$num_valid_chars = strlen($valid_chars);
		for ($i = 0; $i < $length; $i++){
			$random_pick = mt_rand(1, $num_valid_chars);
			$random_char = $valid_chars[$random_pick-1];
			$random_string .= $random_char;
		}
		return $random_string;
	}
	
	function save_csv($data)
	{
		$csvstring = implode(array_keys($data[0]),',')."\n";;
		
		foreach($data as $v)
		{
			$csvstring .= implode($v,',')."\n";
		}	
		
		file_put_contents('test_'.time().'.csv',$csvstring);
	}
	
	function runtest($datasize)
	{
		$stats_row = array();
		echo "<u>Making Test Data of size $datasize</u></br>";
		$array = array();
		for($i=0; $i<$datasize; $i++)
		{
			$array[] = array('id'=>$i, 
				'text'=>get_random_string('abcdefghi',16)
			);
		}
		
		$stats_row['datasize'] = $datasize;
		
		start_timer();
		echo '<u>Encoding in Json</u></br>';
		$jsonencodeddata = json_encode($array);
		$stats_row['encode_json'] = end_timer();
				
		$f = 'tmp/'.$datasize.'_json.dat';
		file_put_contents($f,$jsonencodeddata);
		$stats_row['json_size(MB)'] = filesize($f)/1048576;
		
		start_timer();
		echo '<u>Decoding from Json</u></br>';
		$jsondecodeddata = json_decode($jsonencodeddata);
		$stats_row['decode_json'] = end_timer();
		
		start_timer();
		echo '<u>Serialization of data</u></br>';
		$serializeddata = serialize($array);
		$stats_row['serialize'] = end_timer();
		
		$f = 'tmp/'.$datasize.'_serialize.dat';
		file_put_contents($f,$serializeddata);
		$stats_row['serialize_size(MB)'] = filesize($f)/1048576;
		
		start_timer();
		echo '<u>Unserialization of data</u></br>';
		$unserializeddata = unserialize($serializeddata);
		$stats_row['unserialize'] = end_timer();
		
		return $stats_row;
	}
	
	$stats = array();
	
	$files = glob('tmp/*'); // get all file names	
	foreach($files as $file){ // iterate files
	  if(is_file($file))
		unlink($file); // delete file
	}
	
	for($i=1000; $i<50000; $i+=1000)
	{
		$stats[] = runtest($i);
		echo '<hr>';
	}
	
	save_csv($stats);

If I am wrong at any place then guide me by placing a comment.

Thanks.

How does helicopter tilt?

How does helicopter tilt?

Our helicopter has been up in the air since last post “How does helicopter go up in the air?” But how it can be moved forward or backward or tilt right or left? Its mechanism is little complex but really interesting.

Note: If you don’t know what is tilt then please goto google.com and search “tilt” and see the result. 🙂
As my nature, I always try to find the answer with thinking without making any search on internet.
Let me share my thoughts. I thought, helicopter can make down one side of its rotor that tilts the helicopter in other side but it is useless thing because if we try to make down one side of rotor then rotor will balance again itself in air and helicopter will be tilted but will not be moved one side as effectively as it must be because rotor’s center is a mounted point.
After that I thought that maybe there is a moveable weight that changes the center of gravity of helicopter that tilts the helicopter in one direction. It seems good point but not much effective. So, then I think about angle of blades because I know the angle of blades is the main thing that makes the helicopter up in the air. But how? I found the really amazing thing on Wikipedia. Let me describe this thing in my own words.

There are two swash plates. One is fixed but tiltable using controlling rods and the other one is rotatable. The Fixed one is tiltable in all four directions that changes the angle of blades individually. Rotatable plate is just rotating parallel to fixed plate. Let understand the working in four tilting directions.

Forward Tilt: Angle of blades will be zero at back and will be max downward at front.
Backward Tilt: Opposite of Forward Tilt.
Left Tilt: Angle of blades will be zero at right and will be max at left.
Right Tilt: Opposite of Left Tilt.

It is because of rods connected from swash plate to blades. Tilting of swash plate pull the rods located on one side and push the rods up on other side.

See these pictures for better understand the process.

You can see in second picture that when a blade goes in left top side (picture ref.), its angle decreases towards zero and increase when this blade comes to right bottom. This is how the swash plate works and makes helicopter to be tilted in one direction. When this tilt occurs, blades pushes air downward from one side at fast speed and on other side with low speed and in response helicopter tilts. See this picture

The combination of all four tilting points that make helicopter be tilted in any direction (North to East to South to West).

Now, we can go to meet our beloved friends using our helicopter. Hope you have enjoyed it. 🙂

Source: wikipedia.com

How does helicopter go up in the air

How does helicopter go up in the air

Helicopter is an aircraft that flies with the help of a rotor like fan that push the air downwards and in response helicopter goes up. Rotor is big enough to lift the weight of Helicopter. The mechanism of rotor is very simple and I think everyone can understand in a single preview of working. I am just describing some aspects of rotor that enable the helicopter to be flying.

There are two rotors in basic type of helicopter. One is mounted on top (Main Rotor) that enable the helicopter to be up in the air and other one is on the tail (Tail Rotor) that balances the torque produced by Main Rotor as a side effect.
Each rotor has two blades at 180(deg) and can also be rotatable at its own axis that makes lift. See this picture.

If blades are at 0 (deg) then there will be no lift in helicopter and if blades are at max angle then Helicopter goes up fast. You can easily understand by imagining this scenario.

Now, about Tail Rotor, Tail Rotor’s main purpose is to balance the torque produced in the response of Main Rotor’s motion. It is also used to rotate the helicopter along the axis perpendicular to the Earth by decreasing and increasing the angles of its blades. See this picture.

In this picture, you can see that Main Rotor is rotating about its mounted point. Main Rotor’s rotates by the force applied by helicopter in anti-clockwise, because of this force, an opposite force will be generated by Main Rotor to helicopter because of resistance produced due to inertia and air and some other factors. This opposite force tries to rotate the helicopter in opposite direction that’s called torque. This process is so fast that’s why this force produces much torque as soon as the rotor speed increases. So balancing of this force is necessary to make the helicopter stable in a direction otherwise helicopter will also rotates and I think, no one will want to enjoy this adventure. So, Tail Rotor is assembled vertically in tail of helicopter that rotates and cancels out the torque to make the helicopter stable. Imagine this whole process. It is really easy to understand.

Now, our helicopter is up in the air. 🙂

Source: wikipedia.com

A tip to access the domain during propagation period

A tip to access the domain during propagation period

When you purchase/change the webhosting for a domain, it requires 24 to 72 hours to be propagated all over the world. There is a simple technique to access this domain during this period. Open the file ‘hosts’ located at this path ‘WINDOWS\system32\drivers\etc\’ and add the ip address and your domain name as shown in given example

64.90.xx.xx example.com

you can also do the same for sub domains

64.90.xx.xx mysql.example.com

Note: The file ‘hosts’ may be readonly if you didn’t touch it before so first change the readonly. In Windows 7, there may be an issue of security while saving, so the simple technique it to open the Notepad with administrative rights and open the ‘hosts’ file from file->open.