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: googlestreetview
function googleStreetView($address,$thumbWidth=180,$thumbHeight=120){$width=400;$height=280;
$randomIDNumber=rand();
//$GLOBALS['GoogleAPIKey']='AIzaSyBSz9qJ82AN4P3l97FTgjJbxwbjvIA9tiI';Jun2020
//$_SERVER['SERVER_ADDR'] is 192.185.35.84
//YOU CANT HAVE SPACES in the address!!!
//Manual https://developers.google.com/maps/documentation/streetview/intro
$googleMapLink='https://maps.googleapis.com/maps/api/streetview?sensor=false&fov=100&key='.$GLOBALS['GoogleAPIKey'].'&';
$googleMapLink=$googleMapLink.'location='.$address.'%20Victoria%20BC&size='.($width*2).'x'.($height*2);
$googleMapLink='https://maps.googleapis.com/maps/api/streetview?size=400x400&location='.$address.', Victoria BC&sensor=false&key=AIzaSyBSz9qJ82AN4P3l97FTgjJbxwbjvIA9tiI';
$googleMapLink=str_replace(' ','%20',$googleMapLink);
$potentialImage='images/streetview/'.$address.'.jpg';
if( ! file_exists($potentialImage) ){
$curlResult=file_get_contents($googleMapLink);
$fp = fopen($potentialImage, 'wb');
fwrite($fp, $curlResult);
fclose($fp);
//echo( 'Result: '.var_export($curlResult,true).'
' );
die('Getting Pic for: '.$address);
/*
*/
}
return ''.
'
'.$address.'
'.''.
''.
'
'.
'
'.
$address.
'
'.
'
'.
$address.
'
'';
}
***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}