select2 3.* insert data without replace content

<li class="list-group-item" data-id-user="3"><span class="badge">+</span>Song Ph'"a'"m</li>
<input type="hidden" name="partners" value="" class="multiselect-partner" style="width:100%"/>
<script type="text/javascript">
window.dataPartners = [
{ id: 4, text: "Xuân Hồng" },
{ id: 5, text: "Văn Luyện" },
{ id: 6, text: "Sau Ngu" },
$(document).ready(function () {
     * select2 function
    if ($().select2) {
            multiple: true,
            query: function (query){
                var data = {
                    results: window.dataPartners
            dropdownCssClass: "multiple", // apply css that makes the dropdown taller
            escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
		$newItem = $('.list-group-item');
		$newItem.on('click', function () {
			var isValid = true,
				$me = $(this),
				$fieldMultiselect = $('.multiselect-partner'),
				objectData = {
					id: $'id-user'),
					text: $me.text().substr(1)
			$.each(window.dataPartners, function (index, value) {
				if ( == $'id-user')) {
					isValid = false;
					return false;
			if (isValid === true) {
				window.dataPartners.push(objectData); /* update list dataPartners */
				 * insert this user to group chat
				var data = $fieldMultiselect.select2('data');
				$fieldMultiselect.select2("data", data, true);

Sửa lỗi facebook api: Problem with the SSL CA cert (path? access rights?)

Download file pem
Và đặt ở đâu đó trên server.
Sửa file php.ini đoạn:
curl.cainfo = PATH_TO_PEM/cacert.pem;
service httpd restart

Sử dụng custom font trên cross browser

Quy trình bình thường thì đợi font face load xong thì css mới đc load, nhưng với cách này thì chúng ta sẽ load async css, sau khi load css xong thì mới add vào font vào css trên header:

(function() {
    var headID = document.getElementsByTagName("head")[0],
    fontNode = document.createElement('link');
    fontNode.type = 'text/css';
    fontNode.rel = 'stylesheet';
    fontNode.href = /css/fonts.css'; = 'screen';

Continue reading

Protected: SEO Step by Step

This content is password protected. To view it please enter your password below:

Javascript set style element on load

var w = window.innerWidth;
document.getElementById("navbar-collapse-left").setAttribute("style","width: " + ((window.innerWidth / 2) - 96 - 27) + 'px');


At the end of your day, write down the tasks you need to complete tomorrow
Look at the list when you start the next day.
End your day by creating another list for tomorrow.

Continue reading

Tránh filesort khi query mysql

Quy tắc là chỉ nên where 1 field thôi, nếu where 2 field trở lên thì mysql khó work như ý chúng ta:

Load combobox cha con


    <td valign="top">
    <td valign="top">
        <div class="form-group">
            <select name="city" class="form-control">
                <option value="1" > TP. Hồ Chí Minh</option>
                <option value="2" > Hà Nội</option>
                <option value="3" > Đà Nẵng</option>
    <td valign="top">
    <td valign="top">
        <div class="form-group" id="selectDistrict"></div>

Continue reading

Protected: Xây dựng chat application với Node Js, Socket.IO và PHP

This content is password protected. To view it please enter your password below:

Connect với firebase

Để chạy được firebase ta cần tạo 1 acc trên firebase website. Sau khi tạo xong, thì My First App là project của chúng ta, ta sẽ test dựa trên project này. Mỗi app có 1 unique host-name riêng, ta chỉ việc dùng nó và gán vào url project chúng ta.

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Firebase Chat Application</title>
    <link rel="stylesheet" href="">
        .container {
            max-width: 700px;
        #comments-container {
            border: 1px solid #d0d0d0;
            height: 400px;
            overflow-y: scroll;
        .comment-container {
            padding: 10px;
            background: #f5f5f5;
            font-size: 13px;
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            border-radius: 5px;
        .comment-container .label {
            margin-right: 20px;
        .comment-container:last-of-type {
            border-bottom: none;
    <div class="container">
		<h1>Firebase Chat Application</h1>
		<div class="panel panel-default">
			<div class="panel-body">
				<div id="comments-container"></div>
			<div class="panel-footer">
				<form role="form">
					<div class="form-group">
						<label for="comments">Please enter your comments here</label>
						<input class="form-control" id="comments" name="comments">
					<button type="submit" id="submit-btn" name="submit-btn" class="btn btn-primary">Send Comments</button>
					<button type="reset" class="btn btn-default">Clear Comments</button>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
	var fireBaseRef = new Firebase(""); /* firebase url */
	$("#submit-btn").bind("click", function(event) {
		var comment = $("#comments"),
			commentValue = $.trim(comment.val());
		if (commentValue.length === 0) {
			alert('Comments are required to continue!');
		} else {
			fireBaseRef.push({comment: commentValue}, function(error) {
				if (error !== null) {
					alert('Unable to push comments to Firebase!');
	fireBaseRef.on('child_added', function(snapshot) {
		var uniqName =;
		var comment = snapshot.val().comment;
		var commentsContainer = $('#comments-container');
		$('<div/>', {class: 'comment-container'})
			.html('<span class="label label-info">Comment ' + uniqName + '</span>' + comment)