SQL Coding Standards
A Sample of My Coding Functions, for Quick Reference.Updated 1 year ago
Coding and Naming Standards:
On every project I've worked on, people have discussed coding & Naming Standards, but we always eventually realize that nobody has written these things down. So I have started these proposed standards:
- Names: like_this
- ID: Must be (INT) Named like: table_id
Coding Analogies
- Variable- Cooking ingredient
- Switch - Train switching station. or a choose your own adventure
- If - For in the road
- Break - Exit out of current Loop
- Exit (or Die)- Quit IMMEDIATELY, and print something to the screen
Regex GEdit:
Delete every other line.([^\n]*\n)[^\n]*\n\1
Regex tester for Search AND Replace:
RegExe.comMake all Links open in a New Window jquery.
<script>$("#content a[href^='http://']").attr("target","_blank");</script><script>$("#content a[href^='https://']").attr("target","_blank");</script>
SQL Queries
Count all Table Rows
SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = "adamwith_main";Hwo to assign an array to two variables
I always forget :Plist($first, $second)=array(1,2);
Geo IP Location:
You are in: Columbus, United StatesMy Commonly Used Functions:
View Function: usererrorhandler
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars=array('EmptyArrayToRemoveWarning') ) {//From https://www.php.net/manual/en/function.set-error-handler.php
//$dt = date("Y-m-d H:i:s (T)");
$errortype = array (
E_ERROR => 'Error',
E_WARNING => 'Warning',//Wait only want to error on these 3
E_PARSE => 'Parsing Error',
E_NOTICE => 'Notice',//Wait only want to error on these 3
E_CORE_ERROR => 'Core Error',
E_CORE_WARNING => 'Core Warning',
E_COMPILE_ERROR => 'Compile Error',
E_COMPILE_WARNING => 'Compile Warning',
E_USER_ERROR => 'User Error',//Wait only want to error on these 3
E_USER_WARNING => 'User Warning',//Maybe these 2
E_USER_NOTICE => 'User Notice',//Maybe these 2
E_STRICT => 'Runtime Notice',
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
8192=>'Run Time Error>???'
);
// set of errors for which a var trace will be saved
$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
// echo 'ERRoR#'.$errno.' '.var_dump($errortype[$errno]);
if( isset($errno)&& isset($errortype[$errno])&& ($errortype[$errno]!==NULL) ){
$errHTML = ''.$errortype[$errno].'
'."\n";
$errHTML .= ''.$filename.' @ Line #'.$linenum .'
'."\n";
$errHTML .= ''.$errmsg.''."\n";
$errHTML .= ''.'('.humanTiming().' ago)'.''."\n";
if (in_array($errno, $user_errors)) {
$errHTML .= 'User Errors:' . wddx_serialize_value($vars, "Variables") . '
'."\n";
}
}else if (isset($errortype[$errno]) ){
$errHTML = 'Error #'.$errortype[$errno].' '.'
'."\n";
}else{
$errHTML = 'ErrOr #'.$errno.' '.'
'."\n";
}
//To prevent WAY too much info, and running out of memory:
//$varsToSend=array_slice($vars,0,1);
//$errHTML .= '' . prettyArrayReturn($varsToSend,'Vars') . '
'."\n";
$GLOBALS['CaughtErrors']= $errHTML;
}
***Declared In:/home4/adamwith/public_html/includes/functions/adamwithers.ca.php
Add a hyphen to lists when Copying & Pasting
const prependChar = "-"; document.addEventListener("copy", function(e) { const selected = getSelectionHtml(); if (selected.html.includes("
- ${html}