Skip to content

Instantly share code, notes, and snippets.

View phamquocbuu's full-sized avatar
💻

Buu Pham phamquocbuu

💻
View GitHub Profile
@phamquocbuu
phamquocbuu / email.php
Created November 6, 2012 15:44 — forked from michaelaguiar/email.php
PHP - Send Email
<?php
// Configuration
$myEmail = 'YOUR EMAIL HERE';
$error = '';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
@phamquocbuu
phamquocbuu / Stop Youtube player
Created May 23, 2013 03:50
JavaScript with Youtube
$('[id*="tab-item"]').click(function(){
$('iframe').each(function(index){
if ( $(this)[0] !== undefined ) {
iframe = $(this)[0].contentWindow;
iframe.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
}
});
});
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function ($) {
var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
jQuery('a').on('click', function (event) {
var el = jQuery(this);
var track = true;
var href = (typeof (el.attr('href')) != 'undefined') ? el.attr('href') : "";
function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
@phamquocbuu
phamquocbuu / README.txt
Last active December 19, 2015 23:29
Format numbers as money in JavaScript
And use it with :
(123456789.12345).formatMoney(2, '.', ',');
If you're always going to use '.' and ',', you can leave them off your method call, the method will default them for you.
(123456789.12345).formatMoney(2);
If your culture has the two symbols flipped (i.e. Europeans), just paste over the following two lines in the formatMoney method:
@phamquocbuu
phamquocbuu / TextMan.php
Last active December 22, 2015 21:19
Text manipulation
<?php
/**
* Xử lý chuỗi
* @author phamquocbuu
* @version 1.0
*/
class TextMan {
/**
* Chuyển sang tiếng Việt không dấu
* @author phamquocbuu
@phamquocbuu
phamquocbuu / .htaccess
Created September 14, 2013 02:46
.htaccess rewrite to remove index.php from url
RewriteEngine on
RewriteBase /ci
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
@phamquocbuu
phamquocbuu / check_post.php
Created September 14, 2013 07:36
Check if any required fields in $_POST empty or not
$required = array('id', 'name');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
@phamquocbuu
phamquocbuu / get_ip_addr.php
Created September 20, 2013 03:39
Get User's IP Address
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}