Wednesday, June 22, 2016

Modi Ka Samosa

India’s Prime Minister-Modi was found at a stall asking for Chai and Samosa. The man at stall greeted Modi and gave him a chair to sit and then asked him. Sir, will you take Green Chatni or the Red one. And being a Gujrati Modi likes things to be a bit sweet. So, he ordered Red Chatni.

Media, Congress and opposition created a hue and cry over the matter.

Digvijay Singh: I told you this guy is communal. He refused GREEN CHATNI.

Barkha Datt: He loves the color of Blood thats why he ordered Red Chatni.

AAP: We will protest against it by wearing skull caps and will paint our face green.

Mamta Benerjee: The whole of W.B. will drink and eat 1l Green Chatni every day. It is the cheep source of rich protein.

Owaisi: Modi wants to turn everything saffron. We won’t let him do that.

Aamir Khan: We are scared to order Green Chatni in India and will go to a different country to order green chatni.

Meanwhile the samosa vendor asked Modi, what is this shout all about? What for people have created hue and cry?

Modi: Tu Lal chatni de naa bhaai, inkaa roz kaa hai.

Thursday, June 9, 2016

My Views On #Udata Issue

In India, more than 1000 movies get released every year. Hardly 2 out of 10 movies are made with intention to give right message (I am not writing "good" because it's very relative word. By "right" i mean which lead society to better future) to society with proper impact. 

Among all audience, hardly 2 out of 100 people were able to understand actual message given by the movie and its maker. 30% of remaining people just watch for time pass. All other just take wrong message (base of their mindset).

A good movie can create lots of good people (patriots, sincere citizens, Nobel human beings). Similarly Bad movies also have reverse effect on human, society and country.

Media people should be very sensible and responsible on content they are creating and serving to people.

For example, we would love to go hotel which serve good and healthy food and not just tasty but unhealthy food. If we are so focus and active on checking items we consume for our physical strength, why should we not aware of what we are consuming for mental strength. 

As FSSAI doing great work in making sure we get healthy food for body, similarly CBFC does its job nicely to make sure for healthy food for mental health of society.

Wednesday, June 8, 2016

Top 10 Computer Languages in-demands in 2016

10) C
09) GO
08) PHP
07) Ruby
06) Swift
05) C#
04) C++
03) Python
02) JAVA
01) Java Script

NOTE: This is just based on my personal opinion.

Sunday, October 7, 2012

The teachings of Warren Buffet

What Warren Buffet says about basic investing, spending, savings are so true. Most of us know it, however too many of us do not live it.
If it does make a change in your life, thank HIM (I mean God) because this is common sense.

1. On Earning:
Do not depend on a single income. Invest and create a second/ third source of income:
This means when you are young your first task should be saving and investing. By creating a second source of income you are quickly reducing your dependence on your job. This could help you to set out on your own one day. The quicker you can do it, the better.

2. On Spending:
If you buy things that you do not need, you may soon have to sell things you need: It kind of summarizes Gen X’s reaction towards ‘luxuries’. As a part of Gen X we were perhaps criticised for some of our expenses, so it could be a generational thing even for WB. However, having goals and knowing where you are going, and not spending just to ‘show off’ are important lessons for all generations.

3. On Savings:
Do not spend what is left after spending, instead spend after you save/invest:
Also called ‘Pay Yourself First’. If you realise that investing in a pension plan or for your kid’s education is just helping you to save more later on. It is not a sacrifice, it is just postponing consumption. So understand, invest and then spend.

4. On taking Risk:
Never test the depth of the river with both your feet:
If you are doing something, do small. If you are a first gen investor, do not be carried away by equity lovers like me and put all your money in equity. Do a SIP with a small amount, and test the waters. Do a SIP of Rs. X (which could be 10% of your take home pay) for 5 years and then step up. And for heavens sake understand risk of inflation, and the concept of real returns

5. On Investing: 
Do not put all eggs in one basket:
Immaterial of who you are and how much you understand, create a portfolio. A full range lunch plate is always better than just one item. So create a portfolio with bonds, bond funds, PPF, NSC, equity, mutual funds, and on the risk side medical and term insurance.

6. On Expectation:
Honesty is expensive, do not expect it from cheap people:
Not everybody is honest, nor does everybody want to be honest. Honest advisers are difficult to find especially in Health and Wealth, be careful.

Thursday, April 28, 2011



Once upon a time there was a painter who had just completed his course. He took 3 days and painted beautiful scenery. He wanted people's opinion about his caliber and painting skills.

He put his creation at a busy street-crossing. And just down below aboard which read -"I have painted this piece. Since I'm new to this profession I might have committed some mistakes in my strokes etc. Please put a cross wherever you see a mistake."

While he came back in the evening to collect his painting he was completely shattered to see that whole canvass was filled with Xs
(crosses) and some people had even written their comments on the painting.

Disheartened and broken completely he ran to his master's place and burst into tears.
This young artist was breathing heavily and master heard him saying"I'm useless and if this is what I have learnt to paint I'm not worth becoming a painter. People have rejected me completely. I feel like dying"

Master smiled and suggested "My Son, I will prove that you are a great
artist and have learnt flawless painting. Do as I say without questioning it. It WILL work."

Young artist reluctantly agreed and two days later early morning he presented a replica of his earlier painting to his master. Master took that gracefully and smiled.

"Come with me. " master said.

They reached the same street-square early morning and displayed the same painting exactly at the same place. Now master took out another board which read -

"Gentlemen, I have painted this piece. Since I'm new to this profession I might have committed some mistakes in my strokesetc. I have put a box with colors and brushes just below. Please do a favor. If you see a mistake, kindly pick up the brush and correct it."

Master and disciple walked back home.

They both visited the place same evening. Young painter was surprised to see that actually there was not a single correction done so far. Next day again they visited and found painting remained untouched. They say the painting was kept there for a month for no correction came in.!

Moral of the Story:
It is easier to criticize, but DIFFICULT TO IMPROVE.! Don't get carried away or judged yourself by someone's criticism and feel depressed. Judge Yourself.! You are your best judge....

Sunday, November 1, 2009

Thursday, July 9, 2009

Image crop component for CakePHP


* Images component for CakePHP.
* @author Amit Chavda <>
* @copyright Amit Chavda
* @link CakePHP
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <>.

class ImagesComponent extends Object {
* The Upload Directory
* @access public
* @var string
var $upload_dir = "";

* The Upload Directory Path
* @access public
* @var string
var $upload_path = "";

* New name of the large image & New name of the thumbnail image
* @access public
* @var string
var $large_image_name = "resized_pic.jpg";
var $thumb_image_name = "thumbnail_pic.jpg";

* The Max File Size. Approx 1MB
* @access public
* @var string
var $max_file = "1148576";

* The Max width allowed for the large image
* @access public
* @var string
var $max_width = "500";

* The Width of thumbnail image
* @access public
* @var string
var $thumb_width = "100";

* The Height of thumbnail image
* @access public
* @var string
var $thumb_height = "100";

//Image functions
//You do not need to alter these functions
function resizeImage($image,$width,$height,$scale) {
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
$source = imagecreatefromjpeg($image);
chmod($image, 0777);
return $image;

//You do not need to alter these functions
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
$source = imagecreatefromjpeg($image);
chmod($thumb_image_name, 0777);
return $thumb_image_name;

//You do not need to alter these functions
function getHeight($image) {
$sizes = getimagesize($image);
$height = $sizes[1];
return $height;

//You do not need to alter these functions
function getWidth($image) {
$sizes = getimagesize($image);
$width = $sizes[0];
return $width;


class ImagesController extends AppController {

var $components = array('Images');
var $helpers = array('Html', 'Form', 'Ajax');

function index() {
$error = '';
$this->Images->upload_dir = WWW_ROOT . 'files' . DS . 'upload_pic' . DS;
//Image Locations
$large_image_location = $this->Images->upload_dir.$this->Images->large_image_name;
$thumb_image_location = $this->Images->upload_dir.$this->Images->thumb_image_name;

//Create the upload directory with the right permissions if it doesn't exist
mkdir($this->Images->upload_dir, 0777);
chmod($this->Images->upload_dir, 0777);

//Check to see if any images with the same names already exist
if (file_exists($large_image_location)){
$thumb_photo_exists = 'files/upload_pic/'.$this->Images->thumb_image_name;
$thumb_photo_exists = "";
$large_photo_exists = 'files/upload_pic/'. $this->Images->large_image_name;
$this->set('current_large_image_width', $this->Images->getWidth($large_image_location));
$this->set('current_large_image_height', $this->Images->getHeight($large_image_location));
} else {
$thumb_photo_exists = '';
$large_photo_exists = '';
$this->set('large_photo_exists', $large_photo_exists);
$this->set('thumb_photo_exists', $thumb_photo_exists);
$this->set('thumb_width', $this->Images->thumb_width);
$this->set('thumb_height', $this->Images->thumb_height);

if(!empty($this->data)) {

if(isset($this->data['Image']['image'])) {
//Get the file information
$userfile_name = $this->data['Image']['image']['name'];
$userfile_tmp = $this->data['Image']['image']['tmp_name'];
$userfile_size = $this->data['Image']['image']['size'];
$filename = basename($this->data['Image']['image']['name']);
$file_ext = substr($filename, strrpos($filename, '.') + 1);

//Only process if the file is a JPG and below the allowed limit
if((!empty($this->data['Image']["image"])) && ($this->data['Image']['image']['error'] == 0)) {
if (($file_ext!="jpg") && ($userfile_size > $this->Images->max_file)) {
$error= "ONLY jpeg images under 1MB are accepted for upload";
$error= "Select a jpeg image for upload";
//Everything is ok, so we can upload the image.
if (strlen($error)==0){
if (isset($this->data['Image']['image']['name'])){

move_uploaded_file($userfile_tmp, $large_image_location);
chmod($large_image_location, 0777);

$width = $this->Images->getWidth($large_image_location);
$height = $this->Images->getHeight($large_image_location);
//Scale the image if it is greater than the width set above
if ($width > $this->Images->max_width){
$scale = $this->Images->max_width/$width;
$uploaded = $this->Images->resizeImage($large_image_location,$width,$height,$scale);
$scale = 1;
$uploaded = $this->Images->resizeImage($large_image_location,$width,$height,$scale);
//Delete the thumbnail file so the user can create a new one
if (file_exists($thumb_image_location)) {
//Refresh the page to show the new uploaded image
$this->redirect(array('controller' => "images", 'action' => 'index'));

if(isset($this->data['Image']['x1'])) {
//Get the new coordinates to crop the image.
$x1 = $this->data['Image']["x1"];
$y1 = $this->data['Image']["y1"];
$x2 = $this->data['Image']["x2"];
$y2 = $this->data['Image']["y2"];
$w = $this->data['Image']["w"];
$h = $this->data['Image']["h"];
//Scale the image to the thumb_width set above
$scale = $this->Images->thumb_width/$w;
$cropped = $this->Images->resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale);
$this->redirect(array('controller' => "images", 'action' => 'index'));
$this->set('error', $error);

function deleteImage() {
$this->Images->upload_dir = WWW_ROOT . 'files' . DS . 'upload_pic' . DS;
//$large_image_location = $this->Images->upload_dir.$this->Images->large_image_name;
$thumb_image_location = $this->Images->upload_dir.$this->Images->thumb_image_name;

/*if (file_exists($large_image_location)) {
if (file_exists($thumb_image_location)) {
$this->redirect(array('controller' => "images", 'action' => 'index'));


class Image extends AppModel {
var $name = 'Image';
var $useTable = false;


echo $javascript->link('jquery-pack');
echo $javascript->link('jquery.imgareaselect-0.3.min');
//Only display the javacript if an image has been uploaded
//$current_large_image_width = getWidth($large_image_location);
//$current_large_image_height = getHeight($large_image_location);?>
<script type="text/javascript">
function preview(img, selection) {
var scaleX = <?php echo $thumb_width;?> / selection.width;
var scaleY = <?php echo $thumb_height;?> / selection.height;

$('#thumbnail + div > img').css({
width: Math.round(scaleX * <?php echo $current_large_image_width;?>) + 'px',
height: Math.round(scaleY * <?php echo $current_large_image_height;?>) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'

$(document).ready(function () {
$('#save_thumb').click(function() {
var x1 = $('#x1').val();
var y1 = $('#y1').val();
var x2 = $('#x2').val();
var y2 = $('#y2').val();
var w = $('#w').val();
var h = $('#h').val();
if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
alert("You must make a selection first");
return false;
return true;

$(window).load(function () {
$('#thumbnail').imgAreaSelect({ aspectRatio: '1:1', onSelectChange: preview });

function checkform(){
document.getElementById('ImageX1').value = document.getElementById('x1').value;
document.getElementById('ImageY1').value = document.getElementById('y1').value;
document.getElementById('ImageX2').value = document.getElementById('x2').value;
document.getElementById('ImageY2').value = document.getElementById('y2').value;
document.getElementById('ImageW').value = document.getElementById('w').value;
document.getElementById('ImageH').value = document.getElementById('h').value;
return true;

<?php }?>
<h1>Photo Upload and Crop</h1>
//Display error message if there are any
if(isset($error) and strlen($error)>0){
echo "<ul><li><strong>Error!</strong></li><li>".$error."</li></ul>";
if(strlen($large_photo_exists)>0 && strlen($thumb_photo_exists)>0){
echo "<p><strong>NOTE:</strong> If the thumbnail image looks the same as the previous one, just hit refresh a couple of times.</p>";
echo '<img src="'.$large_photo_exists.'" style="float: left; margin-right: 10px;" id="thumbnail" alt="Main" /> <img src="'.$thumb_photo_exists.'" style="float: left; margin-right: 10px;" id="thumbnail" alt="Thumbnail" />';
echo "<p>".$html->link('Delete Images', array('controller'=>'images', 'action'=>'deleteImage'))."</p>";
<h2>Create Thumbnail</h2>
<div align="center">
<img src="<?php echo $large_photo_exists;?>" style="float: left; margin-right: 10px;" id="thumbnail" alt="Create Thumbnail" />
<div style="float:left; position:relative; overflow:hidden; width:<?php echo $thumb_width;?>px; height:<?php echo $thumb_height;?>px;">
<img src="<?php echo $large_photo_exists;?>" style="position: relative;" alt="Thumbnail Preview" />
<br style="clear:both;"/>
<?php echo $form->create('Image', array('action' => 'index', 'name'=>'thumbnail', 'onsubmit'=>'return checkform()'))?>
<?php echo $form->hidden('x1');?>
<?php echo $form->hidden('y1');?>
<?php echo $form->hidden('x2');?>
<?php echo $form->hidden('y2');?>
<?php echo $form->hidden('w');?>
<?php echo $form->hidden('h');?>

<input type="hidden" name="x1" value="" id="x1" />
<input type="hidden" name="y1" value="" id="y1" />
<input type="hidden" name="x2" value="" id="x2" />
<input type="hidden" name="y2" value="" id="y2" />
<input type="hidden" name="w" value="" id="w" />
<input type="hidden" name="h" value="" id="h" />
<!--<input type="submit" name="upload_thumbnail" value="Save Thumbnail" id="save_thumb" />-->
<?php echo $form->submit('Save Thumbnail', array('div' => false));?>
<?php echo $form->end(); ?>
<hr />
<?php } ?>
<h2>Upload Photo</h2>
<?php echo $form->create('Image', array('action' => 'index', 'name'=>'photo', 'type'=>'file'))?>
Photo <?php echo $form->file('image');?> <?php echo $form->submit('Upload', array('div' => false));?>
<?php echo $form->end(); ?>
<?php } ?>

All The Best,
Amit Chavda