Skip to content

Instantly share code, notes, and snippets.

View phamquocbuu's full-sized avatar
💻

Buu Pham phamquocbuu

💻
View GitHub Profile
var a = document.createElement('a');
a.download = filename; // Set the file name.
a.style.display = 'none';
document.body.appendChild(a);
a.click();
delete a;
@phamquocbuu
phamquocbuu / Zend_Debug_Dump_lastQueryProfile.php
Created November 19, 2013 09:34
Zend Debug dump last query profile
$db = Zend_Registry::get('db');
$db->getProfiler()->setEnabled(true);
Zend_Debug::dump($db->getProfiler()->getLastQueryProfile());
@phamquocbuu
phamquocbuu / jQuery.custom.function.js
Created November 22, 2013 02:20
jQuery create custom function
(function($) {
$.fn.myPlugin = function() {
return this.each(function() {
//Do stuff
});
};
}(jQuery));
@phamquocbuu
phamquocbuu / Zend_Upload_File.php
Created November 22, 2013 09:13
Zend Revieve Upload Image via File upload
$upload = new Zend_File_Transfer_Adapter_Http();
$uploaded_dir = APPLICATION_PATH.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'staff'.DIRECTORY_SEPARATOR.'photo'.DIRECTORY_SEPARATOR.$id;
if (!is_dir($uploaded_dir))
@mkdir($uploaded_dir, 0777, true);
$upload->setDestination($uploaded_dir);
// $upload->addFilter('Rename', APPLICATION_PATH.'/../public/images/avatars/'.$id.'.jpg');
try {
// This takes care of the moving and making sure the file is there
@phamquocbuu
phamquocbuu / Bootstrap.php
Created December 17, 2013 12:43
Zend Routes to sub-dir
protected function _initRoutes()
{
$this->bootstrap('frontcontroller');
/**
* @var Zend_Controller_Front $front
*/
$front = $this->getResource('frontcontroller');
/**
* @var Zend_Controller_Router_Rewrite $router
*/
@phamquocbuu
phamquocbuu / .htaccess
Created December 31, 2013 06:56
.htaccess Redirect all traffic to one page
RewriteEngine On
RewriteBase /bbs
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REQUEST_URI} !/website_maintenance.png$
RewriteRule $ /bbs/maintenance.html [R=302,L]
@phamquocbuu
phamquocbuu / curl_data_port.php
Created January 2, 2014 03:41
PHP CURL post data, port, useragent
<?php
$url = "http://new.sell.dev/distributor";
$post_data = array (
"key" => "jAun729*hA6T6sE2nP3!m3@a4hw",
);
$ch = curl_init();
@phamquocbuu
phamquocbuu / trim_and_remove_multiple_whitespace.php
Created July 7, 2014 08:10
PHP Trim and remove multiple whitespace from string
<?php
trim(preg_replace(array('/\s{2,}/', '/[\t\n]+/'), ' ', $title));
@phamquocbuu
phamquocbuu / CosDb.php
Created July 23, 2014 02:35
Custom class for Database connecting and executing sql query
<?php
class CosDb {
private $DB_HOST;
private $DB_PORT;
private $DB_NAME;
private $DB_USER;
private $DB_PASS;
private $link;
public function __construct($user, $pass, $db_name, $host = 'localhost', $port = null) {
@phamquocbuu
phamquocbuu / CosDB.php
Created August 20, 2014 09:21
Mysql Connect Wrapper
<?php
class CosDb {
public $DB_HOST;
public $DB_PORT;
public $DB_NAME;
public $DB_USER;
public $DB_PASS;
private $link;
public function __construct($user, $pass, $db_name, $host = 'localhost', $port = null) {