Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / gist:3380600
Created August 17, 2012 17:00
php: export data to excel
<?php
// php-export-data by Eli Dickinson, http://github.com/elidickinson/php-export-data
require 'php-export-data.class.php';
$exporter = new ExportDataExcel('browser', 'test.xls');
$exporter->initialize();
$exporter->addRow(array("This", "is", "a", "test"));
$exporter->addRow(array(1, 2, 3, "123-456-7890"));
$exporter->finalize();
exit();
@ekka21
ekka21 / gist:3374133
Created August 16, 2012 22:20
sql: change varchar to DATE format without loosing any data in the column.
- add tmp column to have DATE format
ALTER TABLE requests
ADD tmp DATE;
/update Varchar format of mm/dd/yyyy
UPDATE requests
SET
tmp = STR_TO_DATE(date_due,'%m/%d/%Y');
//drop date_due column
@ekka21
ekka21 / gist:3371834
Created August 16, 2012 17:25
php: convert strings to table fixed columns
<?php
/**
* @Desc: Convert str1,str2,str3,str4,str5,....... to fix table columns
* @param string, delimiter, number of column
* @return Table markup fix columns
*/
function pre_table($str, $del = ',', $numCols = '3'){
$cnt = 0;
$arr = explode($del,$str);
$out_str = "<table width='100%'>";
@ekka21
ekka21 / gist:3371726
Created August 16, 2012 17:07
Javascript: fix column table
// @Desc: Convert str1,str2,str3,str4,str5,....... to fix table columns
// @Param: String, delimiter, number_col
// @Return: Table markup - fixed columns
function prep_table(str,del,numCols){
var cnt = 0;
var arr = str.split(del);
var loop = arr.length;
var out_str = "<table width='100%'>";
for (cnt=0; cnt<loop; cnt++)
{
@ekka21
ekka21 / gist:3316966
Created August 10, 2012 19:08
Wordpress: hide acf admin menu
/**
* Hide ACF menu item from the admin menu
*/
function hide_admin_menu()
{
global $current_user;
get_currentuserinfo();
if($current_user->user_login != 'admin')
@ekka21
ekka21 / gist:3291612
Created August 8, 2012 02:47
php: regular expression regex
If you would like to remove a tag along with the text inside it then use the following code.
<?php
preg_replace('/(<tag>.+?)+(<\/tag>)/i', '', $string);
?>
example
<?php $string='<span class="normalprice">55 PKR</span>'; ?>
<?php
@ekka21
ekka21 / gist:3227450
Created August 1, 2012 14:46
jQuery: alert box when leaving the site
// If the link being clicked is external the user will be prompted
// to confirm they wish to leave the site. Confirmation results in
// the external link being opened in a new window
$('a')
.bind('click', function(event) {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
@ekka21
ekka21 / gist:3180107
Created July 26, 2012 03:39
jQuery: check all checkboxes
// First way
$('#checkBox').attr('checked');
// Second way
$('#edit-checkbox-id').is(':checked');
//input name array
$('input[name=SOME_NAME\\[\\]]').is(':checked')
@ekka21
ekka21 / gist:3180102
Created July 26, 2012 03:38
Linux: restart apache
sudo service httpd graceful
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 reload
@ekka21
ekka21 / gist:3180101
Created July 26, 2012 03:37
Linux: Add new user
useradd -m -d /home/USER_NAME -g wheel USER_NAME
usermod -G GROUP1,GROUP2 USER_NAME