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: thumbnailexists
function thumbnailExists($filePath='',$width=null,$height=null,$zoom=false){$thumbMasterFolder='images/thumbs/';
$requestedFile=basename($filePath);
$pageFolder=dirname ($filePath).'/';//get the first folder
if($width!=null && $height==null){
if( ! file_exists($filePath) ){
$filePath='.'.$filePath;
}
if( ! file_exists($filePath) ){
$filePath=str_replace('..','',$filePath);
}
if(filesize($filePath) > 0){
list($originalWidth, $originalHeight) = @getimagesize($filePath) or die('Error: Unable to the Get Original Image Size: '.$filePath.'');
}else{
$originalWidth=15;
$originalHeight=15;
}
$height=round(($width*$originalHeight/$originalWidth));
}
if($zoom!==false){
$height=$width;
}
if(strpos( $filePath,'/images/videoSlides/')!==false){
$mode='A';
$thumbLocation='../images/videoSlides/'.$requestedFile;
}else if(strpos( $filePath,'quick')!==false){//ISSSSSSSSSsSS QUICK
$mode='B';
$thumbLocation=$thumbMasterFolder.$width.'x'.$height.'/quick/'.$requestedFile;
}else if(strpos($pageFolder,'./themes/public/images/')!==false){//
$mode='C';
$thumbLocation='/'.$thumbMasterFolder.$width.'x'.$height.'/'.str_replace('./themes/public/images/','',$pageFolder).$requestedFile;
//images/thumbs/120x67/collages/simpsonsArtParody
}else if(strpos($pageFolder,'/')!==false){//
$mode='D';
$path=$thumbMasterFolder.$width.'x'.$height.'/';
$thumbLocation=$path.$requestedFile;
}else{
$mode='E';
$thumbLocation=$thumbMasterFolder.$width.'x'.$height.'/'.$pageFolder.$requestedFile;
}
//echo '
thumbnailExists
'.$thumbLocation.'';
if(file_exists('.'.$thumbLocation) ){
//echo '
thumbnailExists
filePath='.$filePath.'requestedFile='.$requestedFile.'
pageFolder='.$pageFolder.'
mode='.$mode.'
thumbLocation='.$thumbLocation.'
';
return ''.$thumbLocation;
}
//echo '
thumbnailExists
filePath='.$filePath.'requestedFile='.$requestedFile.'
pageFolder='.$pageFolder.'
mode='.$mode.'
thumbLocation='.$thumbLocation.'
';
return false;
}
***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}