[MySql] FIND_IN_SET() function

Objectif: update multiple rows in mysql

Quick Solution (for example):

UPDATE my_table SET my_field=first_value WHERE id=1;
UPDATE my_table SET my_field=second_value WHERE id=2;
UPDATE my_table SET my_field=third_value WHERE id=3;
...

Problem : performance

Other solution with function FIND_IN_SET() :

UPDATE `my_table`
SET my_field = find_in_set(id, 'first_value, second_value, third_value, ...')
WHERE id IN (1, 2, 3, 4, ...)

Find more explaination :
http://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php

Jquery Ajax error handling to ignore aborted

Error comes from when the web page refresh too much fast than it can load.

For example, a web page load a huge data, even with ajax pagination, and users refresh multiple times of this page

 

Solution which resolved this problem :

var unloaded = false;
$(window).bind('beforeunload', function(){
    unloaded = true;
});

$(document).ajaxError(function(event, request, settings) {
    if (unloaded || request.statusText == "abort") {
        return;
    }
    ...
}

Ref.
http://stackoverflow.com/questions/4807572/jquery-ajax-error-handling-to-ignore-aborted

[css] Table set fixed column width

Background : Using JQuery Datatable generated dynamically table but push columns off the layout.

Example :
Image 1

Solution :
Add table-layout to the css, and of course give width to each column :

table-layout: fixed;
word-wrap:break-word;

The reason why :
Fixed table layout algorithm:
The horizontal layout only depends on the table’s width and the width of the columns, not the contents of the cells
Allows a browser to lay out the table faster than the automatic table layout
The browser can begin to display the table once the first row has been received

Ref from : w3schools

[Framework] Pourquoi utiliser un framework ?

Pourquoi utiliser un framework ?

Un framework permet de réduire les temps de développement des applications en répondant de façon efficace aux problèmes les plus courants rencontrés par les développeurs. Il inclut généralement de nombreuses fonctionnalités prêtes à l’emploi dont les implémentations sont bien rodées et utilisent des modèles de conceptions standard et bien implémentés. Le temps ainsi gagné sur les questions génériques pourra être mis à profit pour les parties spécifiques de l’application.

De plus, l’utilisation d’un même framework dans différents projets contribue à l’industrialisation du processus de développement : la structure de l’application et les méthodes de programmation sont standardisées, les compétences des développeurs sont réutilisables dans chaque projet.

L’utilisation d’un framework est très fortement recommandée, afin de ne pas avoir à réinventer la roue et d’éviter les erreurs de conception classiques qui créent des problèmes de sécurité ou tout simplement des bugs.

Source depuis : http://www.smile.fr

[Git] Git diff without comparaison file mode

Issue when execute git diff command on a file and got :

diff --git a/your_file b/your_file
old mode 100644
new mode 100755

If you see this, it is because the permissions of your_file has changed.
For information, the unix file permission mode(644=rw_r__r__ which means read and write for user, only read for group and only read for others, the same for 755=rwxrw_rw_, x for executable).

To disable the comparaison of file mode, the command to execute :

git config core.filemode false

[PHP] PHP code showing on the page instead of being executed

Environment :
Ubuntu Server 14.04
PHP 5.5.9

Problem :
PHP code showing on the page instead of being executed

Reason :
The reason that I met this problem is because the PHP file I used begin with (<?) instead of (<?php) which the short tag is deprecated by default.

Solution :
Find php.ini in /etc/php5/apache2, make sure the option short_open_tag=On, if not, change if to On.

Another solution more complete from stack overflow : http://stackoverflow.com/a/5121589/740546

[Bash shell] Display the output with color

In bash shell, we have multiple ways to display the output, but do u know how to do this with color ?
Like this :
Image 8

It’s not so hard to do, the only thing we need to understand is  : ANSI escape code

An example of correspondence between the code and the color :

Black        0;30     Dark Gray     1;30
Red          0;31     Light Red     1;31
Green        0;32     Light Green   1;32
Brown/Orange 0;33     Yellow        1;33
Blue         0;34     Light Blue    1;34
Purple       0;35     Light Purple  1;35
Cyan         0;36     Light Cyan    1;36
Light Gray   0;37     White         1;37

The example in bash shell

#!/bin/bash

NC='\033[0m' 		# No color
RED='\033[0;31m'	# red
PURPLE='\033[0;35m'	# purple

printf "My ${PURPLE}name${NC} is ${RED}BO${NC} \n"

Do this in shell, and launch your script, you will get the same from the image in the beginning of this article.