Search Stories: Google’s new look and feel of marketing campaign

As Google has about 70 percent market share in search, it hardly needs to attract users. But last week Google has launched half dozen of short videos called “search stories” which look suspiciously like commercials posted on its blog and YouTube.

Cheermobile (My Favorite)

This Search Stories are titled like Parisian Love, Mad to Live, Batman, Newbie, Potholes, and High School. Google has launched these videos in a common tag line “Search on” to have the look and feel of a marketing campaign and give the feel of belongingness of Google homepage to its users. IT also stresses a variety of Google products, such as mapping, video, price comparisons, email and more. Some people are smelling  that the Search Stories are for the $100 million marketing push by Microsoft launched for its Bing search service, but Google said that it was feeling all warm and fuzzy and decided to make some kids-let’s-put-on-a-show videos and simply avoided the debate.

CakePHP Advanced Pagination – sort by derived field

This is my second post on cake. Yesterday I was trying to implement pagination on my cakephp application and got frustrated as it can’t(?) sort by derived fields like SUM(), AVG(). I ransacked for the solution and got many alternate ways. Here is one from Andy Dawson: http://bakery.cakephp.org/articles/view/pagination. He has done a great job. But I wanted to do it by the core pagination method and didn’t feel interested to add a new component as cake has already provided with this feature.

Here comes struggling – I spent a couple of hours to find out a way… and finally got it! yes it is possible to sort by derived fields using the built-in pagination feature of cakephp! Let’s talk about the solution a little later, first I’d like to introduce you with the exact problem I faced.

I was trying to show the list of products in a tabular format with product name and lowest price. The product title is from products table (Product model) and the lowestprice is the MIN of price field from products_of_merchants table(ProductsOfMerchant model). Each Product belongsTo a certain SubCategory and hasMany ProductsOfMerchant selling them on different price(s).

Controller code segment

$this->paginate = array(
	'conditions' => array('Product.sub_category_id' => $subcategory['SubCategory']['id']),
	'fields' => array(
		'Product.id',
		'Product.title',
		'MIN(ProductsOfMerchant.price) AS lowestprice'
	),
	'order' => array('lowestprice' => 'asc'),
	'limit' => 10,
	'group' => 'Product.id'
);
$products = $this->paginate('Product');
$this->set(compact('products'));

It works fine for the first time as default order by lowestprice asc. In the view, I wanted to sort the lowestprice (derived field) column interactively asc/desc.

View code segment

<?php echo $paginator->sort('Lowest Price', 'lowestprice'); ?>

Also tried with

<?php echo $paginator->sort('Lowest Price', 'ProductsOfMerchant.lowestprice'); ?>

I clicked the ‘Lowest Price’ link to sort by desc, no luck! cos it’s a derived field and in debug mode there is no “ORDER BY” clause at the end of the query. I found a lot of ppl looking for the solution of this same issue and here is the solve (+backstage scenes) I’m gonna share with you.

From the cake book I found this Custom Query Pagination.
First I added this function in the Product model for debugging.

Product Model code segment

function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
	print_r(func_get_args()); // for debugging
	$group = $extra['group'];
	return $this->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'group'));
}

Here is the output when I tried to sort by ‘lowestprice’ desc by clicking the ‘Lowest Price’ column header link:

Array
(
    [0] => Array
        (
            [Product.sub_category_id] => 5
        )

    [1] => Array
        (
            [0] => Product.id
            [1] => Product.title
            [2] => MIN(ProductsOfMerchant.price) AS lowestprice
        )

    [2] => Array
        (
        )

    [3] => 10
    [4] => 1
    [5] => 1
    [6] => Array
        (
            [group] => Product.id
        )
)

You can see when you try to sort by a derived field the order by array (array key=2) is empty. This is definitely a bug of the pagination method, but for now we need a patch/fix to get it work and you know it’s never a good idea to modify the core of any framework. The interesting part of the paginate function is it takes an $extra argument which contains an array with ‘group’ key. I added a dummy key-value array to the $paginate array in the controller and wow! it’s automagically appended with the $extra argument of the paginate function in the model. Now all I need is to pass the sort key somehow via the $extra array. This is exactly what I did:

Controller code segment

$this->paginate = array(
	'conditions' => array('Product.sub_category_id' => $subcategory['SubCategory']['id']),
	'fields' => array(
		'Product.id',
		'Product.title',
		'MIN(ProductsOfMerchant.price) AS lowestprice'
	),
	'order' => array('lowestprice' => 'asc'),
	'limit' => 10,
	'group' => 'Product.id',
	'passit' => $this->passedArgs // pass via $extra
);
$products = $this->paginate('Product');
$this->set(compact('products'));

I hope you know what does $this->passedArgs do. If not, no worry, you can see the output of pr($this->passedArgs) from any controller/view.

Here is the patch I applied to the paginate function in the model:

Product Model code segment

function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
	if(empty($order)){
		// great fix!
		$order = array($extra['passit']['sort'] => $extra['passit']['direction']);
	}
	$group = $extra['group'];
	return $this->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'group'));
}

And finally it worked great!

Oh! I forgot, there is a little pain in the view section. I’ve already said this is a patch, the paginate function can’t detect the current sorting direction of the derived fields automatically. The link with the derived field’s sorting column always remains direction:asc no matter you change it manually from the address bar to asc or desc! Here is the fix for view section:

View code segment

<?php
// echo $paginator->sort('Lowest Price', 'lowestprice');
// Use $html->link, not $paginator->sort
echo $html->link(__('Lowest Price', true), array(
	'controller' => 'sub_categories',
	'action' => 'view',
	'page' => $this->passedArgs['page'],
	'sort' => 'lowestprice',
	'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
	'limit' => $this->passedArgs['limit']
));
?>

Please turn off debugging by Configure::write(‘debug’, 0) otherwise you may see some annoying warnings and notices of undefined variables. Or you may use isset to check if the vars are set or not and modify the view code accordingly. To me it’s less important and didn’t bother to fix it.

It’s almost perfect now and worked happily ever after.. ;)

If you have any better idea or suggestion please share in the comments.

Zynga’s revenue has touched the sky in 2009

Zynga is the number one social gaming company on the web. Popular social online games by zynga are Cafe World, Dragon Wars, FarmVille, Fashion Wars, FishVille, Mafia Wars, PetVille, Pirates, Roller Coaster, Scramble, Special Forces, Street Racing, Vampires, Word Twist, YoVille, Zynga Poker and so on. No download is required for Zynga games, and Zynga uses Facebook, MySpace, Bebo, Friendster, Hi5, and iphone as platform for these games and social networking.

Zynga logo

When Zynga got 5 million users its goal had been to get to 12 million daily active users by the end of the year 2009, but now they have ended 2009 with around 65 million users.

Zynga’s revenue has increased like boom with its users. According to Zynga CEO Mark Pincus, ZYnga’s revenue run rate has increased by additional 246 percent to 260 percent in the year 2009. So, Zynga’s annualized revenue run rate is now more than $300 million in 2009. And, earlier this month, the company closed a $180 million round of funding.

Based on preliminary sales trend on virtual goods, Zynga will likely do at least $200 million in revenues this calendar year through virtual farm games only.

Social networks like Facebook, Twitter may face more sophisticated attacks in 2010

McAfee warned that Social networks will face increasingly sophisticated hacker attacks in 2010. McAfee said, “The explosion of applications on Facebook and other services will be an ideal vector for cybercriminals, who will take advantage of friends trusting friends to click links they might otherwise treat cautiously,”

In its 2010 Threat Predictions report, McAfee expected that hackers were expected to try to take advantage of the proliferation of URL shortening services such as bit.ly and tinyurl.com. It has also expected to see increased threats to banking security, Adobe products (especially Acrobat Reader and Flash), Chrome computer operating system by Google, and Microsoft Office applications and email remained vulnerable for its increasing popularity among individual users, corporations, and government institutions. However, the Santa Clara, California, computer security firm said that they are expecting to see an increase in the effectiveness of law enforcement to fight back against cybercrime in 2010.

HAVING clause in CakePHP find query

Recently I’m in love with Cake. Yes it’s true cake is too much addictive. ;) As a novice it’s not that comfortable to start with cakephp framework, cos most of the stuffs from the cake book hardly work perfectly, it’s good they update their code too frequently, but not the cake book. I’ll write several posts on cakephp issues for beginners with solutions in the coming days. Still a lot of ingredients of the cake are mysterious to me, but there is no doubt, I won’t hesitate to give them two thumbs up with 5 star rating :)

Right now I’m working on a price-comparison project using cakephp. This is the first time I’m using cake. I know you’d say why didn’t I try a smaller project first, actually I like to take risk (once my astrologist friend Imon told me this).

Whatever, lets get back to the “title” of this post. One of my queries needed HAVING clause, but did not find any way to use HAVING clause with cakephp find() function. I searched a lot on google, didn’t find anything, even very few people asked for it on popular groups/forums like google/nabble! The SQL query I wanted to run is:

SELECT `Product`.`id` , `Product`.`title` , `Product`.`image_link` , MIN( `ProductsOfMerchant`.`price` ) AS lowest_price, AVG( `ProductReview`.`rating` ) AS average_rating, COUNT( DISTINCT (
`ProductReview`.`id`
) ) AS total_reviews
FROM `products` AS `Product`
LEFT JOIN `products_of_merchants` AS `ProductsOfMerchant` ON ( `ProductsOfMerchant`.`is_active` =1
AND `ProductsOfMerchant`.`product_id` = `Product`.`id` )
LEFT JOIN `product_reviews` AS `ProductReview` ON ( `ProductReview`.`is_approved` =1
AND `ProductReview`.`product_id` = `Product`.`id` )
WHERE `Product`.`is_active` =1
GROUP BY `Product`.`id`
HAVING total_reviews & gt ; =2
ORDER BY `average_rating` DESC
LIMIT 4 

I added the “HAVING” in ‘group’ key of the find() function’s parameters. This is the cakephp code I used and it worked great!

$highRatedProducts = $this->find('all', array(
	'fields' => array('Product.id', 'Product.title', 'Product.image_link', 'MIN(ProductsOfMerchant.price) AS lowest_price', 'AVG(ProductReview.rating) AS average_rating', 'COUNT(DISTINCT(ProductReview.id)) AS total_reviews'),
	'conditions' => array('Product.is_active' => 1),
	'order' => 'average_rating DESC',
	'group' => 'Product.id HAVING total_reviews >= 2',
	'limit' => 4)
);

Please share in comments if you know any better(proper) “Cake way” to accomplish this.

WPtouch iPhone Theme (part 2)

This a continuation from my previous post on WPtouch. In that post I explained how to add additional user agent support by modifying the wptouch.php. Also I mentioned the pain associated with this method – each time you update the plugin you have to edit the $useragents array. I suggested to give an option in the admin panel to add extra user agents. I’m not sure – may be after seeing my post WPtouch decided to give an option for that in the admin panel ;)

Here is the good news – yes now you can add “Custom User-Agents” to WPtouch! Below is a screen-shot from ABCoder’s WPtouch settings:

WPtouch iPhone Theme - new settings for adding extra user agents

I’ve added these user-agents:

playstation, samsung, wap, windows ce, wm5 pie, iemobile, symbian, series60, series70, series80, series90, blackberry, midp, wml, brew, brew, xiino, blazer, pda, nitro, netfront, sonyericsson, ericsson, sec-sgh, docomo, kddi, vodafone

A really handy way to check whether it is working or not – add webkit at the end (certainly with a comma before it) and visit your site from Google Chrome. If you see the iPhone version everything is perfect! Don’t forget to remove “webkit” before you go live.

Google Chrome for Mac and Linux operating system now on air

Google has released a version of its popular web browser Google Chrome on December 8, 2009 for Macintosh computers. Google’s target is to challenge Safari Web browser offered by Apple to its users. Google also released a beta version of Chrome for computers running on open-source Linux operating systems on the same day.

Google claimed its extra effort to build a fast and polished browser for Mac. The Macintosh version of Chrome is still in ‘beta’ version and yet to unveil in full swing. While using the beta version, Macintosh users do not yet have customization features such as allowing extension programs or bookmark management.
Google has also planned that Linux and Windows compatible versions of Chrome could be customized with features such as mini “extension” programs. Already the beta version of Google Chrome for windows has a lot of extensions available to download from Google Chrome Extensions (beta).

Google Chrome for Mac runs on Mac OS X and the Linux version of Chrome supports Debian, Ubuntu, Fedora & openSUSE Linux.

Google Chrome Screenshoot from Mac OS X

Google Chrome Screenshoot from Linux

Google Chrome Extensions available in beta

Here are a few fun facts from the Google Chrome for Mac team:

  • 73,804 lines of Mac-specific code written
  • 29 developer builds
  • 1,177 Mac-specific bugs fixed
  • 12 external committers and bug editors to the Google Chrome for Mac code base, 48 external code contributors
  • 64 Mac Minis doing continuous builds and tests

And here are some from the Google Chrome for Linux team:

  • 60,000 lines of Linux-specific code written
  • 23 developer builds
  • 2,713 Linux-specific bugs fixed
  • 12 external committers and bug editors to the Google Chrome for Linux code base, 48 external code contributors

Download Google Chrome for Mac/Linux

Download Google Chrome for Mac
Download Google Chrome for Linux

Google product manager Brian Rakowski believes that the betas of Google Chrome for Mac, Linux and extensions will fulfill some sort of e-wishes of internet users.

The world’s fastest supercomputer introducing by IBM

In 2010, IBM will release a radical new chip which may become the world’s fastest supercomputer named Blue Waters. It will be able to do massively complex calculations in an instant and it is being housed in a special building on the Urbana-Champaign campus in a water-cooled rack to pull the heat out. It’ll be capable of achieving 10 petaflops (Petaflop is the key indicator of supercomputer performance, A petaflop = 1 quadrillion floating point operations per second) about 10 times as fast as the fastest supercomputer today. IBM is going to turn on the supercomputer in 2011.

Blue Waters by IBM

The Supercomputer uses Power7 fuses, the flagship Power chip design with key technology from a separate “Cell” processor that was part of IBM’s Roadrunner system at the Los Alamos National Laboratory. It integrates eight processing cores in one chip package and each core can execute four tasks makes the Power7 chip special. These threads can turn an individual chip into a virtual 32-core processor. As a yardstick, Intel’s high-end Xeon processors typically have two threads per processing core. It is also using novel memory technology. In this super computer IBM has avoided ballooning and costly chip counts and elected to use a technology called E-DRAM, keeping the total number of transistors to 1.2 billion. IBM said E-DRAM will help to get the performance up of the computer. Most of the crash tests are now done on these machines. Now it’s ready to unveil.

CSS Equal Height Columns

Once upon a time people used tables for designing website layout. Definitely table tag has many advantages but it’s not that flexible & extensile. You can not use proper positioning or floating attributes css style for table based layout. It’s not that commodious to handle table width/height from Dreamweaver, the layout gets messy when you drag any border of table, td or tr as the dimensions automatically get changed. The most important incentive for the current web sphere is SEO (Search Engine Optimization) which is dramatically & automatically mended when DIV based layout is used where TABLE based layout is toilsome for search bots to crawl & takes much page loading time. And at some point it makes more sense to use table for displaying tabular formatted data only, for example gmail uses table for the email list, this could be done using UL/LI, but table is more appropriate in this case.

Lately most web designers use DIV for page layout designing for its flexibility and robustness. Unlike table div has a big problem (in fact it’s the nature of div) when you want to give same height to multi-columns div based page layout, you can not do that very easily. I always used javascript for this purpose, but wished if I could do it with css, cos when the javascript is disabled the page layout will be not as expected in most of the cases.

Yes it is possible to create equal height columns with css! You can make the height of multiple floated divs equal using CSS only and no javascript or invalid css. Before beginning I assume you have adequate knowledge on HTML, CSS, javascript and you have already Firebug add-on installed on your Firefox :)

Lemme start from the beginning:

Default three column layout

default-three-column-layout
Link to the HTML page

When you apply float left and fixed width to multiple adjacent divs, by default the layout looks like the above screen shot. You can see it from browser or have a look at the source code (html/css) on the following link above. You see as the contents are not same in the 3 divs, the height is different.
The next example is making the height of the 3 divs same using javascript (jQuery).

Three column layout – equal height using jQuery

Three column layout - equal height using jQuery
Link to the HTML page

This is mostly and widely used for making equal height columns using javascript. I’ve used jQuery here. You may have a look at the source code from the link above.

$(function(){
	var H = 0;
	$("div").each(function(i){
		var h = $("div").eq(i).height();
		if(h > H) H = h;
	});
	$("div").height(H);
});

Now here comes the css equal height technique! The mantra is to use a large amount of bottom padding and the same amount of negative bottom margin to the floated divs and keep them inside an overflow hidden div. That’s all, and the magic happens!

Three column layout – equal height using pure CSS

CSS Equal Height - three column layout
Link to the HTML page

Let me get into details on how to do it. At First have a look at this link. Here I’ve used a huge amount (9000px) of bottom padding and the same amount of negative bottom margin (-9000px). But this makes the columns look so long and still not equal height at bottom. Now on this link I’ve used a holder div with overflow:hidden and that’s it, it is doing the magic by hiding the overflow section.

body{margin-bottom:50px}
div.holder { overflow:hidden }
div.holder div { float:left; width:30%; background-color:#9C0; margin-right:5px; padding:10px; padding-bottom:9000px; margin-bottom:-9000px }

Hope it’s clear now.

There is another method which use a background image with 1px height and color matched with the div’s bg color and body’s bg color. Please have a look at the html link, it’s self-explanatory.

Three column layout – equal height using pure CSS with Background Image

CSS Equal Height - three column layout using bg image
Link to the HTML page

Now I’ll try border to the columns and we’ll see the problem and it’s solution.

Three column layout – equal height with border

CSS Equal Height - three column layout using border
Link to the HTML page

Here you can see bottom border is missing which is obvious as we’ve used a huge bottom padding, from Firebug if you turn off overflow:hidden to the holder div and scroll down at the bottom of the page you’ll see the bottom border there but not equal height.
So how to solve this issue? There are 2 ways to do it – using a bg image in a tricky way or another pure tricky css hack.

Three column layout – equal height with bottom border fix using bg image

CSS Equal Height - three column layout using border fix
Link to the HTML page

Here I’ve used a 1px bg image for the background image and placed it at left-bottom of the bottom-border div with no-repeat and also applied 1px bottom padding. The holder div is inside the bottom-border div. Please feel free to play around with firebug!

This is the last method for bottom border fix without any bg image, just pure css.

Three column layout – equal height with bottom border fix using pure css and no bg image

CSS Equal Height - three column layout using border fix
Link to the HTML page

I’m not gonna explain the details of this last method, find it out yourself! :)

New Phonetic keyboard in Gmail

Gmail is continuously surprising us with its out of the box features, enormous flexible options and outstanding super-simple user interface. Everyday so many users being fade up with yahoo are going towards gmail. Like Yahoo, Gmail also show ads but they are never that annoying as they’re just simple text ads, no funky flash or image ads, no forcing for being a paid subscriber (Gmail don’t have any paid subscription, it’s totally free! :P). All these simplicities are the main attraction of Gmail which are driving Yahoo users towards it. The recent update in Gmail themes is “Random Themes” option. It’s really boring when you have to read and reply hundreds of emails a day. The “random” gmail theme automatically rotates the eye-catching collection of themes after every 1-2h which makes “gmailing” fun! “Random theme” is my personal favorite.
The free Xoopit plugin added an extra gear to Gmail which is no more as Yahoo bought the service. Here we can feel the acute cold war between Gmail & Yahoo evidently. Yesterday I tried Google Wave and it certainly will re-shape the concept of classical email system.

Gmail Phonetic KeyboardTyping in Gmail's Phonetic Keyboard

This morning I was typing an email on gmail and found a new symbol on top left of the compose box editing panel (Rich formatting mode). I clicked it and saw a drop-down menu with 12 languages options including Bengali, Hindi, Arabic and so on. OMG! it’s phonetic keyboard! I tried some text with it, simply awesome!! I hope gmail will keep going on with its passion for the “ease of use”. Bravo! love you Gmail.