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: getcollageandimagemap
function getCollageAndImageMap($directoryName,$matching=''){$thumbLocation= './images/thumbs/quick/';
if( file_exists($thumbLocation) ){
$rand=rand(1, 222222222);
//var_dump ( file_exists('./images/thumbs/') );die('aaa'.$thumbLocation);
$toReturn="\n".''."\n";
$HTMLFileName1='./images/thumbs/quick/'.str_replace('/','',str_replace('/themes/public/images/','',$directoryName)).'.html';
$HTMLFileName2='./images/collages/'.$directoryName.'.html';
//die('Output #45ydfg: getCollageAndImageMap('.$directoryName.', '.$matching.')
'.$HTMLFileName1.'
'.$HTMLFileName2);
if(file_exists($HTMLFileName1) ){
$mapHTML=file_get_contents($HTMLFileName);
$toReturn.=str_replace('"collageMap"','"collageMap'.$rand.'"',$mapHTML);
$HTMLFileName=$HTMLFileName1;
}else if(file_exists($HTMLFileName2) ){
$mapHTML=file_get_contents($HTMLFileName2);
$toReturn.=str_replace('"collageMap"','"collageMap'.$rand.'"',$mapHTML);
$HTMLFileName=$HTMLFileName2;
}else{
$toReturn.='';
}
if($matching!='' ){
//$toReturn.= '$directoryName='.$directoryName.'
';
$directoryName=((substr($directoryName,-1)=='/')?substr($directoryName,0,-1):$directoryName);
//$toReturn.= '$directoryName='.$directoryName.'
';
$directoryName=((substr($directoryName,0,7)=='images/')?substr($directoryName,7):$directoryName);
//$toReturn.= '$directoryName='.$directoryName.'
';
$HTMLFileName= $thumbLocation.($directoryName==''?'index':$directoryName).'.'.$matching.'.html';
}else if(substr($directoryName,0,7)=='images/'){
$HTMLFileName= $thumbLocation.($directoryName==''?'index':substr($directoryName,7)).'.html';
//$toReturn.='lll'.$HTMLFileName.'
';
}else{
$HTMLFileName= $thumbLocation.($directoryName==''?'index':$directoryName).'.html';
//$toReturn.='kkk'.$HTMLFileName.'
';
}
//$toReturn.=$HTMLFileName.'
';
if( file_exists($HTMLFileName) ){
$toReturn.=str_replace('collageMap','collageMap'.$rand,file_get_contents($HTMLFileName) );
}
}else{
$toReturn='Error # 2342923: Unable to Get HTML for Collage: '.$thumbLocation.' in: '.getcwd();
}
return $toReturn;
}
***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}