Category Archives: Tips

Javascript Object to String

Javascript is a little hard to debug, Firebug helps a lot, but sometime you just to need to convert a javascript object into a string.
In order to do that (in firefox) you could use the toSource() method.
Here is how you do it:


// create an object
var anyObject = {'someAtt':'someValue', 'otherAtt' : 'otherValue'};
// get the object to source
var anyObjectToString = anyObject.toSource() ;
// now write the string
document.writeln(anyObjectToString );

Here is the printout of this code in firefox:

In Internet Explorer and Chrome this will generate a Javascript error – but this is not for production so using it in Firefox would do fine.

CakePHP Ajax/JSON calls fail? Try turning debug output off

ajax CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. CakePHP provides several Ajax features, but if cakephp debug is not turned off, most Ajax calls and JSON encoding would fail.

The problem / symptoms

When calling a server side cakephp method through Ajax calls usualy in combination with JSON encoding, the call fails. The server returns HTTP 200 and everything seems fine, but the Ajax call just doesn’t work.

Continue reading

Useful JQuery Plugin to Display Errors, Messages, and Alerts: Gritter

Real estate on your web page could be as important as real estate in real life. You got very little space on your client screen and need to use every inch (or pixels). Errors and messages take up valuable space that could be better used for more important things.

That is why Gritter is a great JQuery plugin – it saves real estate on your page by showing alerts, messages and errors in a floating bubble way, that is both informative and (because you can configure Gritter to fade away after a few seconds) non intrusive:

This image was taken from one of our new site’s design, we decided to use Gritter instead of putting the errors and notification inline.

Check out Gritter’s demo site and project site and, for CakePHP developers, here is an article about integrating Gritter with CakePHP.

It is open source, looks great, easy to integrate, and is very useful!

How to: Automatic User Login in CakePHP

Sometimes you need to enable silent (implicit) login for your users. A good example of this would be this – after a registration process, you would want to automatically login the user, rather then having him retype the user name and password.

In CakePHP there is a simple method in the Auth components that lets you login on the user’s behave.

Here is how it is done:


// assuming $password is the clear text password
$this->data["User"]["password"] = $this->Auth->password($password);
$this->data["User"]["username"] = $username;

// do the login
$login = $this->Auth->login($this->data);

// $login is true is login went well.
// now we can redirect the user to any page:
if($login){
$this->redirect(array('controller' => "anycontroller",
'action' => "any_secure_action", null));
}

This will be implemented in the next CakeOTP release.

6 Useful Things Google Search Provides That Are Not Search / Useful Google Search Tools

Lately it is kind of popular to trash Google. Very much like Microsoft, people love to complain about companies that take an important part of their daily life. Google is now an integral part of our life not only for search but for many other things. A good friend saw me convert foreign exchange on Google search and was very surprised you can do that. So here is a list of things I do in Google search which are not search related.

Looking up What’s the Time in Other Places Around the World

Living in a far away island in the pacific with friends in Europe and America, this tool is a great help.

Continue reading

How I Save Time Filtering Spam Comments with Mollom


I get spam comments all the time, it drives me crazy and make me wish I didn’t have a web site at all. Spam really bring the evil side of most site owners.

Yesterday, I finally had enough, I got 300 spam comments and only 4 real ones – I had to go over 3 pages and read bogus comments like:

“I have a question [link to gambling site]”

or “nice post [link to viagra]”

and the ho-so-known “dgsdgsdghsdfhdf [link to a SEO company]”.

I went to drupal and looked for the most popular anti-spam module they listed and found Mollom.

Mollom is a web service that helps you identify content quality and, more importantly, helps you stop spam on your blog, social network or community website. When site moderation becomes easier, you have more time and energy to interact with your community.
Continue reading

How to check where your site visitors come from using javascript

Where do my visitors come from? That is always a question bloggers, site owners and advertisers want to know. Knowing who has referred the visitor to my site tells you a lot about that visitor. This information might help you drive better, more finely tuned content to this user.

Demo

Code


<script type="text/javascript">
if(document.referrer){
document.write("Hello, Thank you for arriving from: " + document.referrer);
}else{
document.write("Hello, Thank you for arriving directly to this page");
}
</script>

This topic is covered in detailed in this interesting article.

Apache Crashes on Windows – Check Your Ports

Apache is one of the most popular web servers in the market today. It usually runs on Linux-based machines but lately there are more and more deployments, for development as well as other reasons, of Apache on Windows. Nowadays, running Apache web server on Windows is very common for PHP developers. Many developers develop their PHP application on their home windows or Mac and deploy to a remote Linux server.
Continue reading

How to Get Free Open Source Photos for Your Website and Presentations



Visuals aids such as photos, are very important because they help you pass information and feelings, attract attention, maintain concentration, and help explain abstract concepts. Most professional presenters use photos and other images in their presentation. I personally find that the audience is better tuned when I present images than words.
The problem is that most images cost money – most photographers want you to pay royalties for the images you use.
Lucky enough, there are many images released under an open source license called creative commons
Continue reading