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: getbingimages
function getBingImages($limit,$query,$resizeW=300,$resizeH=300,$maxsize=3000,$bigImages=true,$crop=false,$showTitles=true,$saveFileName=null){//https://adamwithers.ca/ripBingImages
//echo('$query='.$query.'
');
$query=str_replace(' ','%20',$query);
$query=str_replace("\t",'%20',$query);
$query=str_replace('%20%20','%20',$query);
$url = 'https://www.bing.com/images/search?q='.$query.'';//MUST be Escaped!!
if($bigImages){
$url.='&qft=+filterui:imagesize-large;';
}
//die('$query='.$query);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$content= curl_exec($ch);
curl_close($ch);
preg_match_all('!!',$content,$urlMatches);
$i=0;
$toReturn='Matches:'.sizeOf($urlMatches[2]).'
'.$query.'
';
if(sizeOf($urlMatches[2])<=0){
$toReturn='No Results';
}
foreach($urlMatches[2] as $urlMatch){
if($limit!=null){if($i>=$limit){continue;} }
$alt='';
$urlMatch=str_replace('&','&',$urlMatch);
if( $crop===false){
$urlMatch=str_replace('&c=1','',$urlMatch);
}
$picURL=str_replace('&w=42','&w='.$maxsize,$urlMatch);
$picURL=str_replace('&h=42','&h='.$maxsize,$picURL);
$picSRC=$urlMatch;
if( ! $resizeW){
$picSRC=str_replace('&w=42','',$picSRC);
}else{
$alt.='&w='.$resizeW;
$picSRC=str_replace('&w=42','&w='.$resizeW,$picSRC);
}
if( ! $resizeH){
$picSRC=str_replace('&h=42','',$picSRC);
}else{
$alt.='&h='.$resizeH;
$picSRC=str_replace('&h=42','&h='.$resizeH,$picSRC);
}
//$picURL=str_replace('th?','adam?',$picURL);
$picAlt=$urlMatches[4][$i];
$divWidth='';
if( $resizeW){
$divWidth='width:'.(300).'px;';
}
if($saveFileName!==null){
$saveFileNameTooAdd='saveFileName='.str_replace(' ','%20',$saveFileName).'&';
}else{
$saveFileNameTooAdd='';
}
$toReturn.=
''."\n";
$i++;
}
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}