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: getweather
function getWeather($city='Central Saanich,CA'){$APIKey='a9c2bd7e240cfd88be64274291081f4a';
$type='accurate'; // 'accurate'returns exact match values'like'returns results by searching for that substring.
//Params:https://openweathermap.org/current
//Example:https://www.wdrfree.com/110/how-to-weather-with-php-openweathermap-in-3-easy-steps
$request = 'https://api.openweathermap.org/data/2.5/find?type='.$type.'&units=metric&mode=jsoâân&APPID='.$APIKey.'&q='.$city.'&';
//$request = 'https://api.openweathermap.org/data/2.5/weather?q='.$type.'&mode=jsoâân&APPID='.$APIKey.'&q='.$city.'&';
$contents = file_get_contents($request);
$weatherData=json_decode($contents);
$weatherInfo=array(
'lat'=>$weatherData->list[0]->coord->lat,
'lon'=>$weatherData->list[0]->coord->lon,
'desc'=>$weatherData->list[0]->weather[0]->description,
'main'=>$weatherData->list[0]->weather[0]->main,
'icon'=>$weatherData->list[0]->weather[0]->icon.".png",
'pressure'=>$weatherData->list[0]->main->pressure,
'humidity'=>$weatherData->list[0]->main->humidity,//Humidity, %
'temp_cur'=>$weatherData->list[0]->main->temp,
'temp_max'=>$weatherData->list[0]->main->temp_max,
'temp_min'=>$weatherData->list[0]->main->temp_min,
'wind_speed'=>$weatherData->list[0]->wind->speed,
'wind_deg'=>$weatherData->list[0]->wind->deg,//Wind direction
'clouds'=>$weatherData->list[0]->clouds->all,//Cloudiness, %
'time_stamp'=>$weatherData->list[0]->dt,
'country'=>$weatherData->list[0]->sys->country,
'city_id'=>$weatherData->list[0]->id,
'city_name' =>$weatherData->list[0]->name,
'rain'=>$weatherData->list[0]->rain,//Rain volume for the last 3 hours
'snow'=>$weatherData->list[0]->snow,//Snow volume for the last 3 hours
);
return $weatherInfo;
}
***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}