[@messageCenter]

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.com

Make 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 :P
list($first, $second)=array(1,2);

Geo IP Location:

You are in: Columbus, United States

My Commonly Used Functions:

addorremovebitmapperm
array_map_assoc
arrayfromdb
arraytodb
backlink
bg
blackorwhitetext
buildsortstatement
buildwherestatement
bytestosize
cad
camelcasetowords
carousel
carouselyoutube
checkbox
checktable
cleanforanchorlink
cleanfordatabasefield
cleanforshorturl
cleanfortitle
cleanupmultifilearray
columntable
comparebydesc
convertcurrency
convertsmartquotes
createslideshowquickthumbnaildirectories
daysdifference
debugfilenotexist
decodebitmap
deletedirectory
dieonerrror
difficultytag
drawpagewithcontents
drawtable
emailabstract
emoji
fileexists
findpicfromanyextension
floatingblueimagebox
formatdollars
formatsize
getallguesses
getamazonpics
getbingimages
getcelebbox
getcelebpic
getcollageandimagemap
getcollageimg
getcurrencyrates
getcurrentquerystring
getdaysbetween
getfileextension
getfunctioncode
getidea
getimagefromandsaveto
getimagetype
getkey
getmetapic
getmovies
getparts
getquerysignature
getquestion
getrandompic
getscriptnamewithoutparams
getthumbnailoffilesin
getthumbnailpicsin
geturlpath
getvariablename
getweather
getweatherbox
googlestreetview
grammardate
hd
hextorgbcolour
hideemail
hitcounter
humantiming
imagecolorallocatebyname
imagettfstroketext
in_arrayresursive
incrementfilenameifexists
infopopup
isassoc
isdirectoryempty
ismobile
iso8859_1_to_utf8
isprivatecookieloggedin
isvalidpicextentions
isvalidurl
listbox
load404
loadsettings
locbox
lostfunction
makecollage
makeinsertstring
my_autoloader
phoneabstract
phptojavascriptarray
prettyarray
prettyarrayreturn
printbreadcrumb
privatebox
quickceleb
quickdbbutton
quickdbentryget
quickdbform
quickdbscript
quickdbtable
quickfetch
quickparse
quickparts
quickparts2
refreshbrokenpics
remotefiletype
removefileextension
returnshortenedstring
rgbtohexcolour
rootpage
runjswhenpicsloaded
show_ordinal
showdate
showitemsincategory
shuffleassoc
simpleslideshow
smartdate
strposa
subtractyearfrommovie
thumbnailexists
totaluplist
updatedatebox
url_exists
usd
usererrorhandler
videopopup
workinprogressbanner
yesno

View Function: getimagefromandsaveto

function getImageFromAndSaveTo($params,$saveTo,$site='imdb',){
if( ! function_exists('stealImageURLFromWebsite') ){
die('Error #234sd56ntyu6: You forgot to include stealImageURLFromWebsite in /includes/siteRipper.php');
}
$stolenImageInfo=stealImageURLFromWebsite($site,$params,$dieIfNotFound=false,900);
//die('Err2342asdf $stolenImageInfo: '.var_export($stolenImageInfo) );
if(isset($stolenImageInfo['picURL']) && $stolenImageInfo['picURL']!=''){
$fp = @fopen($_SERVER['DOCUMENT_ROOT'].$saveTo, 'w') or die('Error# 223232asd3: Directory probably doesn\'t exist:'.$_SERVER['DOCUMENT_ROOT'].$saveTo);
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);

$context = stream_context_create($options);
@fwrite($fp, file_get_contents($stolenImageInfo['picURL'], false, $context)) or die('Error: Wikipedia["'.$params['name'].'"] Returned invalid picURL of:'.$stolenImageInfo['picURL']);
fclose($fp);
if(isset($stolenImageInfo['picURL']) && $stolenImageInfo['picURL']=='<' ){
echo('Error #32231a3: picURL is equal to "<"
'."\n");
}else if(!filter_var($stolenImageInfo['picURL'], FILTER_VALIDATE_URL)){
echo('Invalid Wiki Image URL:'.$stolenImageInfo['picURL'].'
For:'.$saveTo.'
');
}
return true;
}
return false;
}
***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("
  • ")) { const ul = selected.container.querySelectorAll("li"); Array.from(ul).forEach(c => { if (c.tagName === "LI") { c.innerText = prependChar + " $$$ " + c.innerText; } }); // Remove unwanted whitespace const html = selected.container.innerHTML.replace(/(^|>)[ \n\t]+/g, ">\n"); const list = `
      ${html}
    `; const wrap = document.createElement("div"); wrap.innerHTML = list; e.clipboardData.setData("text/plain", wrap.textContent); e.clipboardData.setData("text/html", list); e.preventDefault(); } }); function getSelectionHtml() { let html = ""; let container; if (typeof window.getSelection !== "undefined") { const sel = window.getSelection(); if (sel.rangeCount) { container = document.createElement("div"); for (let i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); } html = container.innerHTML; } } else if (typeof document.selection !== "undefined") { if (document.selection.type === "Text") { html = document.selection.createRange().htmlText; } } return { html, container }; }