Tuesday, February 24, 2009

Facebook Apps: Viral Marketing on Steroids

First there were invites by email. I still get those *friend* wants you to join *website* on my email inbox. If that was not annoying enough, then try Facebook and wait till you get hundreds of invites on you notification pane. Inviting people to join an app is just a simple click away. No more typing email addresses or signing in to your email accounts. This should be a good thing (at least for app developers), but often times you get those notifications 10x a day that say you've been poked or someone has done something to you, inviting you to see what it is.

Recently there was much buzz about Facebook changing it's terms of agreement. If you think about it, you've *already* given much of your personal information to a lot of third parties - everytime you use a new Facebook app. So regardless of Facebook's terms of agreement, your information is already stored on servers outside of Facebook's control. What really bothers me is that Facebook aims to be a social networking platform based on your real identity, yet it is the easiest platform to harvest personal information by using viral marketing. Always think twice before clicking that "Allow Access" button.

Tuesday, February 3, 2009

Enhancing CakePHP's debug() function for null, false, and empty string

CakePHP's debug() function is great. Aside from printing out the variable content, it also displays from which line it is called. If you call out debug() in different places, knowing which line saves a lot of time tracking something.

What bothers me sometimes is it doesn't tell you if the variable is NULL, false, or an empty string, so I end up using var_dump() to double check. So how to fix this? Right! We'll edit something inside the cake folder ;) This is usually bad practice but this is a safe one (we'll just plug something in.. kinda), and it won't break your stuff in case you upgrade your cake library. Here you go:

Add this function at the bottom of app/config/core.php:
# this prints out booleans, nulls, and empty strings
# will be called inside cake's debug() on cake/basics.php
function debug2($var)
{
if(is_null($var) || is_bool($var))
{
var_dump($var);
}
else if( is_string($var) )
{
if( '' == trim($var) )
{
var_dump($var);
}
}
}
Here's the dirty part! open cake/basics.php and find the debug() function (line ~104). Add this code before print_r is called: (only the bold part)

if(function_exists('debug2')) {
debug2($var);
}
$var = print_r($var, true);

Now when you call debug(NULL), it will now look like this:
app\app_controller.php (line 72)
NULL

Have fun baking!