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: getquerysignature
function getQuerySignature($queryParams) {/* creates an array that contains url encoded values
Example: "parameter=encoded%20value"
All Variables are rawurlencode() */
if(! $queryParams) return 'ERROR: No Query Parameters Sent';
$encoded_values = array();
foreach($queryParams as $key=>$val) {
$encoded_values[$key] = rawurlencode($key) . '=' . rawurlencode($val);
}
/* Add Mandatory query parameters that are needed for every query, if they do not already exist */
if(! isset($encoded_values['AssociateTag'])){$encoded_values['AssociateTag']= 'AssociateTag='.rawurlencode($GLOBALS['MY_ASSOCIATE_ID']);}
if(! isset($encoded_values['AWSAccessKeyId'])){$encoded_values['AWSAccessKeyId'] = 'AWSAccessKeyId='.rawurlencode($GLOBALS['MY_PUBLIC_KEY']);}
if(! isset($encoded_values['Service'])){$encoded_values['Service'] = 'Service=AWSECommerceService';}
if(! isset($encoded_values['Timestamp'])){$encoded_values['Timestamp'] = 'Timestamp='.rawurlencode(gmdate('Y-m-d\TH:i:s\Z'));}
if(! isset($encoded_values['Version'])){$encoded_values['Version'] = 'Version=2011-08-01';}
ksort($encoded_values);
$uri = '/onca/xml'; //used in $sig and $url
$method = 'GET'; //used in $sig
/* implode the encoded values and generate signature
depending on PHP version, tildes need to be decoded
note the method, server, uri, and query string are separated by a newline */
$query_string = str_replace("%7E", "~", implode('&',$encoded_values));
$sig = base64_encode(hash_hmac('sha256', "{$method}\n".$GLOBALS['AMAZON_SERVER']."\n{$uri}\n{$query_string}", $GLOBALS['MY_PRIVATE_KEY'], true));
/* build the URL string with the pieces defined above
and add the signature as the last parameter */
$url = "https://".$GLOBALS['AMAZON_SERVER']."{$uri}?{$query_string}&Signature=" . str_replace("%7E", "~", rawurlencode($sig));
return $url;
}
***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}