jQuery event handling best practice

Anonymous functions are usually used extensively in jQuery events handling, however, anonymous functions are difficult to debug, maintain, test, or reuse.

A better way is to use object literals as in this example:

 

//BAD
$(document).ready(function() {
  $('.status .delete').click(function(e) {
    //Do something
  });

  $('.status').dblclick(function(e) {
    //Do the same thing
  });
});

//GOOD
var bindingObject = {
  onReady : function() {
    $('.status .delete').click(bindingObject.deleteTweet);
    $('.status').dblclick(bindingObject.deleteTweet);
  },
  deleteTweet : function(e) {
    //Do something
  }
};

$(document).ready(bindingObject.onReady);

 

10 Symfony 1.4 best practices

Here is a list of 10 Symfony 1.4 best practices:

  1. Manage the view withing the view, try to avoid the use of view.yml, this will simplify future interventions by designers who are not necessary familiar with YML.
  2. Always call a redirect after posting data, this will inhence security and avoid content duplication in the database.
  3. The template must contain PHP alternative templating syntax.
  4. Only deploy production front controllers in production.
  5. Change the session_name param under the storage section in factories.yml
  6. Make sure a csrf_secret is defined in the settings.yml file.
  7. always apply Symfony coding standards http://trac.symfony-project.org/wiki/HowToContributeToSymfony
  8. Always create custom 404 and 500 error pages.
  9. Use sfLogger for debugging instead of echoing variables
  10. Use Symfony tasks system for CLI batch sripts.

TEDxOujda

One month and a half after the first TEDx event took place in Oujda, Morocco (for more information about TED and TEDx you may go to http://www.ted.com and http://www.ted.com/tedx) am still feeling inspired by the ideas I saw that day, and by the speakers I met, it was an unforgettable experience, this was the first TEDx event in the city and the 3rd in the country.

I was honored to be a member of TEDxOujda organizers team.

Dsc_2341

RTL your CSS style

Suppose we have a CSS file called style.css, now create a separate CSS file, let's call it style-rtl.css for example, the first file contains all of our CSS properties, the other one will only contains the flipped CSS rules.

For example, if we are styling links in style.css as:

a{color:red; margin-left:10px;}

in the styles-rtl.css stylesheet we'll only include the flipped rule:

a{margin-right:10px;}

And then we link both:

<link rel="stylesheet" type="text/css" href="styles.css"/>
<link rel="stylesheet" type="text/css" href="styles-rtl.css"/>

Make sure you include the overriding stylesheet after the original one to ensure the rules are overridden.

But notice that the link in RTL now has a margin-left of 10px AND a margin-right of 10px which is not what we want. We want the margin-left to be a margin-right. In that case we "reset" the margin-left like below:

a {margin-left:0; margin-right:10px;}

 

Google Days Maghreb, an amazing experience

Back from Google Days Maghreb, it was really an amazing experience ! so much information, great people (specially the Googlers :D) and most of all, diving inside the "Google culture", it was an unforgettable three days, full of techie conferences, workshops and fun :) I hope that this will be just the beginning of Google here in Morocco. 

Dsc05709