Skip to content

Instantly share code, notes, and snippets.

View anovsiradj's full-sized avatar

MDMCDC anovsiradj

View GitHub Profile
// @param st: The string that will be trimmed. @default whitespace
String.prototype.strim = function(st) {
st = st || "\\s";
return this.replace(new RegExp("^"+st+"+|"+st+"+$",'g'),'');
}
/*
example:
"alorem ipsuma".strim('a'); // return "lorem ipsum"
" lorem ipsum ".strim(); // return "lorem ipsum"
@anovsiradj
anovsiradj / valid-username.php
Last active August 28, 2015 09:40
Regex validate username with PHP.
<?php
/**
* @version 20150828
*/
function username($str) {
$bool = preg_match('/^[a-zA-Z][a-zA-Z0-9_]+$/', $str);
$status = ($bool ? "<b>Good</b>" : "Bad");
echo $status." : ".$str."\n";
}
$kind = array(
@anovsiradj
anovsiradj / v2.sql
Last active August 26, 2015 03:40
method that work for: mysql left join that count joined table
-- work, but the result not accurate
SELECT c.user_id,
c.user_fname,
COUNT(cc.user_id) AS total_child,
COUNT(ccc.user_id) AS total_consul
FROM drpp_user c
LEFT JOIN drpp_child cc
ON cc.user_id = c.user_id
LEFT JOIN drpp_consul ccc
ON ccc.user_id = c.user_id