Some coding tips
Blogs20132013-10-06
Some coding tips
Here I list some tips from my coding for quick retrieving:
//Useful in a virtualbox env:
# setsebool httpd_can_network_connect 1
# setsebool httpd_can_network_connect_db 1
//remove from git remote repository:
git rm -r --cached vendor
git rm --cached .gitingore
// document_root/.htaccess file as routers
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [L]
//Leverage Browser Caching
<IfModule mod_expires.c>
# Enable Expirations
ExpiresActive On
# Default Expiration Time
ExpiresDefault "access plus 1 month"
# Expiration for CSS
ExpiresByType text/css "access plus 1 month”
# Expiration for JavaScript
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
// steps required after installing redis-server and mongod
$ sudo groupadd mongod redis
$ sudo useradd -s /sbin/nologin -g mongod -d /var/lib/mongo
-M -r -c "MongoD daemon" mongod
$ sudo adduser -s /sbin/nologin -g redis -d /var/lib/redis
-M -r -c "Redis Server" redis
//a typical JS closure: nextId()
var nextId=(function() {
var counter = 1;
return function() {
return counter ++;
};
}());
// ajax should write like this:
$.ajax({
type:'POST', url:'',
data: JSON.stringify(post_data),
contentType: "application/json; charset=utf-8",
dataType: "json"
}) //promise
.done(function(data) {}) //then
.done(function(data) {}) //...
.fail(function (jqxhr, textStatus, errorThrown) {})
.always(function (data) {});
// dynamic loading js:
var url="http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js";
$.getScript(url, function() {
$("#go").click(function(){
$(".block").animate( { backgroundColor: "pink" }, 1000)
.delay(500)
.animate( { backgroundColor: "blue" }, 1000);
});
});