Show Menu
Cheatography

CST8285 Cheat Sheet (DRAFT) by

Prepping for a final exam at Algonquin College!

This is a draft cheat sheet. It is a work in progress and is not finished yet.

GIT commands

git init
initialize an existing directory
git clone [url]
retrieve an entire repository
git status
show modified files in working directory
git add [file]
add a file as it looks now to your next commit
git reset [file]
unstage af ile while retaining the changs in working directory
git diff
diff of what is changed but not staged
git commit -m "­[commit messag­e]"
commit your staged content as a new commit snapshot
git branch
list your branches, current has a *
git branch [branch name]
create a new branch at the current commit
git checkout
switch to another branch
git merge [branch name]
merge the specified branch into current one
git log
show all commits
git push
transmit local branch commits to remote repo
git pull
fetch and merge any commits from the remote repo

Regex

^ or \A
Start of string
$ or \Z
end of string
\b
word boundary
\B
Not word boundary
\s
white space
\S
not white space
?=
look ahead
?!
negative lookahead
*
0 or more
+
1 or more
?
0 or 1
{3}
exactly 3
{3,}
3 or more
{3,5}
3, 4, or 5
[a-z]
lowercase a - z
[A-Z]
uppercase A-Z
[^abc]
not (a or b or c)
[0-7]
digits from 0 to 7
(a|C)
a or C

JavaScript String Objects

length
property
charAt(n)
method
charCo­deAt(n)
method
l
et a = "­10"; let b = 20; consol­e.log(a + b)
1020
let a = "­10"; let b = 20; consol­e.l­og(+a + b)
30
let a = "­10"; let b = 20; consol­e.log(a - b)
-10
let a = "­10"; let b = 20; consol­e.log(a * b)
200
l
et a = “CST82­85"; let b = 20; consol­e.log(a - b)
NaN
 

PHP - database connection

MYSQLi connection
$dbc = mysqli­_co­nne­ct(­$host, $user, $pw, $db);
Query
$result = mysqli­_qu­ery­($dbc, $query);
Close
mysqli­_cl­ose­($dbc);

JavaScript Math Objects

Math.r­ound(x)
x to nearest integer
Math.p­ow(x,y)
x to the power of y
Math.s­qrt(x)
square root of x
Math.a­bs(x)
absolute |x|
Math.r­andom()
random number between 0 (inclu­sive) to 1(excl­usive)

JavaScript Arrays

array.s­or­t(f­unc­tio­n(a­,b)­{return a-b})
array.s­or­t((a,b) =>{­a-b})
a-b = positive
b sorted before value a
a-b = negative
a sorted before value b
a-b = 0
items stay inthe same spot
array.f­il­ter­(fu­nct­ion­(el­ement) {return (compa­rison)}
array.f­il­ter­((e­lement) => {return (compa­ris­on)};
array.m­ap­((i­tem­)=>­arr­ay.k­ey);
new array containing only items with key
array.p­us­h(v­alue)
add value to end of array
array.p­op()
remove value at end of array, returning value
array.u­ns­hif­t(v­alue)
add value at start of array
array.s­hift()
remove value at start of array, returning value
array.s­pl­ice­(st­art­ing­Index, totalE­lem­ent­sTo­Delete, values­ToAdd)
add or remove elements anywhere in the array and returns deleted elements if any

PHP functions

isset()
test if variable exists
empty()
tests for empty variable
mysqli­_fe­tch­_ar­ray­($r­esult)
fetch each row of query $result
exit()
end script immedi­ately
trim($­string)
remove leading and trailing whitespace
file($fn)
read contents of $fn, returns array of strings
file_g­et_­con­ten­ts($fn)
returns single string
file_p­ut_­con­ten­ts($fn, data, mode)
write content from data to $fn, using mode)
file_e­xis­ts($fn)
checks if $fn exists
scandi­r($­path)
returns array of lists of files and direct­ories if $path is valid, else false
glob()
returns array of all file names that match pattern, with path
getcwd()
returns string of current working dir
 

Cookies & Session

Cookies
- limited in size by browser
- stored client­-side
- can be disabled
Sessions
- limited by server space
- stored server­-side
- expire when browser closed
- cannot be modified by users

PHP Session Commands

sessio­n_s­tart()
start a session
$_SESS­ION­["va­ria­ble­Nam­e"]
store session variable
unset(­$_S­ESS­ION­["va­ria­ble­Nam­e"]
remove session variable
sessio­n_d­est­roy()
destroy session and all session variables

JSON

easy to parse and generate
can contain both object and array structures
contain key and value pairs
keys are always strings
values can be string, number, Boolean, null, object, or array
HAS no version, very stable, strictly in UNICODE
Example object: $json = ' { "­Nam­e": "­Ale­x", "­Age­": 37, "­Adm­in": true } ' ;

JSON in PHP

json_e­ncode()
convert PHP array to JSON array
JSON_F­ORC­E_O­BJECT
changes above to reult in indexed array
json_d­ecode( $json, true))
JSON string to PHP array
json_d­ecode( $json, false) (default)
JSON string to PHP object
JSON.s­tri­ngify()
take JS object and produce JSON string
JSON.p­arse()
take JSON string and produce JS object

PHP Error Reporting

error_­rep­orting
types of errors reported
displa­y_e­rrors
whether messages displayed in browser
log_errors
on server or somewhere else

var | let | const

VAR
LET
CONST
functi­on-­scoped
block-­scoped
block-­scoped
updatable
updatable
not updatable
redecl­arable
not redecl­arable
not redecl­arable
hoisted null
not hoisted