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: getamazonpics
function getAmazonPics($query,$tag='LARGEIMAGE'){//Tag Examples: LARGEIMAGE, MEDIUMIMAGE, SMALLIMAGE
//The First Image is probably the one you want
$signed_url = getQuerySignature($query);
//die('$signed_url: '.$signed_url);
/* Use CURL to retrieve the data so that http errors can be examined */
$ch = curl_init($signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 7);
$xml_string = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
if($curl_info['http_code']!=200) {
return '
ERROR:
Check the $curl_info [below] to discover why AWS returned an error
$xml_string may still contain valid XML, and may include an informative error message'. var_export($curl_info,true);
}else {
//$debugArray = new SimpleXMLElement($xml_string);prettyArray($movies);die('a');
$p = xml_parser_create();
xml_parse_into_struct($p, $xml_string, $vals, $index);
xml_parser_free($p);
//echo "
Index array
\n"; print_r($index);//echo "
Vals array
\n";print_r($vals);$toReturn=array();
foreach($vals as $i=>$key){
if($key['tag']==$tag){//Get the NEXT Tag
if(isset($vals[$i+1]['value']) ){
$toReturn[]= $vals[$i+1]['value'];
}
}
}
}
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}