Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@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: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: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: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:3381924
Created August 17, 2012 19:42
Javascript: allow only digits zipcode zip
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
<input type="text" onkeypress="return isNumberKey(event)" maxlength="5" placeholder="Search by Zip" id="addressInput">
@ekka21
ekka21 / Javascript e.preventDefault();
Created August 18, 2012 15:13
Javascript: e.preventDefault()
var normal = document.querySelector('.normal'),
prevent = document.querySelector('.prevent');
prevent.addEventListener('click', function(ev) {
alert('fabulous, really!');
ev.preventDefault();
}, false);
normal.addEventListener('click', function(ev) {
alert('fabulous, really!');
@ekka21
ekka21 / sql create view
Created August 22, 2012 17:52
sql create view
CREATE VIEW `table_view`
AS
select
*
from
table
where
id=...
@ekka21
ekka21 / gist:3465530
Created August 25, 2012 13:17
Linux: tar
#Creating an archive using tar command
*c – create a new archive
*v – verbosely list files which are processed.
*f – following is the archive file name
*z – filter the archive through gzip
Note: .tgz is same as .tar.gz
//compress
tar cvf archive_name.tar dirname/
@ekka21
ekka21 / linux find permission
Created August 25, 2012 15:30
Linux: find file permission
//find all with permission 777
find / -type f -perm 0777
//find all without permission 777
find / -type f ! -perm 0777
//Wordpress chmod permission
define('FS_METHOD', 'direct');
@ekka21
ekka21 / gist:3512582
Created August 29, 2012 13:34
Javascript: confirm delete alert box
var confirmDel = confirm("Are you sure? This is your last chance!");
if(confirmDel === true)
{
return true;
} else {
return false;
}