\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{cripto560} \pdfinfo{ /Title (cis350.pdf) /Creator (Cheatography) /Author (cripto560) /Subject (CIS350 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CIS350 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{cripto560} via \textcolor{DarkBackground}{\uline{cheatography.com/79053/cs/19212/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}cripto560 \\ \uline{cheatography.com/cripto560} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 28th March, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Software design principles}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Modeling: identify concepts, properties, behaviors, and their relationships} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Choose the right architecture} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Create/Use appropriate data structures} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Use design patterns when appropriate} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Refactor (change the design) as necessary} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Android}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{AndroidManifest.xml contains all activities \newline % Row Count 1 (+ 1) extends AppCompatActivity \newline % Row Count 2 (+ 1) {\bf{onCreate(Bundle savedInstanceState)\{}} \newline % Row Count 3 (+ 1) \seqsplit{super.onCreate(savedInstanceState);} \newline % Row Count 4 (+ 1) {\bf{setContentView(R.layout.activity\_main);\}}} \newline % Row Count 5 (+ 1) \textless{}Button android:id="@+id/title" \newline % Row Count 6 (+ 1) {\bf{android:onClick="onClearButtonClick" /\textgreater{}}} \seqsplit{//onClearButtonClick(View} v) in the class \newline % Row Count 8 (+ 2) {\bf{Button b = (Button) findViewById(R.id.title);}} \newline % Row Count 9 (+ 1) {\bf{Intent i = new Intent(this, AnotherActivity.class)}} // args = context, class \newline % Row Count 11 (+ 2) i.putExtra ("key", "value"); //getStringExtra("key") in other class \newline % Row Count 13 (+ 2) {\bf{startActivityForResult(i, AnotherActivity\_ID);}} \newline % Row Count 15 (+ 2) {\bf{onFinishButtonClick(View v)\{}} \newline % Row Count 16 (+ 1) Intent i = new Intent(); \newline % Row Count 17 (+ 1) i.putExtra("NUM\_CLICKS", num\_clicks); \newline % Row Count 18 (+ 1) {\bf{setResult(RESULT\_OK, i);}} \newline % Row Count 19 (+ 1) {\bf{finish();}} \newline % Row Count 20 (+ 1) \} \newline % Row Count 21 (+ 1) //in the returning activity... \newline % Row Count 22 (+ 1) {\bf{onActivityResult}}(int requestCode, int resultCode, Intent intent)\{ \newline % Row Count 24 (+ 2) switch (requestCode) \{ \newline % Row Count 25 (+ 1) case AnotherActivity\_ID: \newline % Row Count 26 (+ 1) \}\} \newline % Row Count 27 (+ 1) Toast.makeText(context, text, duration).show(); \newline % Row Count 28 (+ 1) \seqsplit{//getApplicationContext()} for context \newline % Row Count 29 (+ 1) //Toast.LENGTH\_LONG for duration% Row Count 30 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{What's wrong with Monolith?}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{analyzability: main method can be fairly long and hard to read/understand} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{changeability: hard to find the code you want to change} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{stability: hard to know whether a change in one place will affect other places} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{testability: if something goes wrong, hard to find the bug} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{hard to reuse any of the code} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Javascript}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{push, unshift (front); pop, shift (front) \newline % Row Count 1 (+ 1) if a is array of size 3 \newline % Row Count 2 (+ 1) a{[}-5{]} = 'elephant' adds key value mapping to array \newline % Row Count 4 (+ 2) a{[}5{]} = 'elephant' adds elephant at index 5 with element at index 4 = undefined \newline % Row Count 6 (+ 2) function print(n) \{ \newline % Row Count 7 (+ 1) console.log(n)\} \newline % Row Count 8 (+ 1) nums.forEach(print); \newline % Row Count 9 (+ 1) function square(n)\{ \newline % Row Count 10 (+ 1) return n*n;\} \newline % Row Count 11 (+ 1) var squares = nums.map(square); \newline % Row Count 12 (+ 1) // returns the array of squares \newline % Row Count 13 (+ 1) var myDog = \{ \newline % Row Count 14 (+ 1) name: 'Cooper', \newline % Row Count 15 (+ 1) type: 'dog'\} \newline % Row Count 16 (+ 1) pet{[}'status'{]} = 'good boy'; \newline % Row Count 17 (+ 1) var add = function (a,b)\{...\} \newline % Row Count 18 (+ 1) add(3,5); \newline % Row Count 19 (+ 1) var teacher = \{ \newline % Row Count 20 (+ 1) name: 'name', \newline % Row Count 21 (+ 1) greet: function () \{...\} \newline % Row Count 22 (+ 1) \} \newline % Row Count 23 (+ 1) teacher.greet(); \newline % Row Count 24 (+ 1) //this is called a prototype \newline % Row Count 25 (+ 1) function Teacher (name, subject)\{ \newline % Row Count 26 (+ 1) this.name = name; \newline % Row Count 27 (+ 1) this.subject = subject; \newline % Row Count 28 (+ 1) this.greet = function() \{...\} \newline % Row Count 29 (+ 1) \} \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Javascript (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{var t1 = new Teacher('Kate', 'math'); \newline % Row Count 1 (+ 1) var t2 = new Teacher('Mike','science'); \newline % Row Count 2 (+ 1) set.has(...); \newline % Row Count 3 (+ 1) set.delete/add("fox"); \newline % Row Count 4 (+ 1) for (let v of set.values()) //iterate \newline % Row Count 5 (+ 1) map.set("dog", "rover"); //has " instead of ' \newline % Row Count 6 (+ 1) map.get(...) \newline % Row Count 7 (+ 1) for (let {[}key, val{]} of map.entries()) \newline % Row Count 8 (+ 1) let square = function (n) //same as \newline % Row Count 9 (+ 1) let square = n =\textgreater{} \{\}% Row Count 10 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{MongoDB}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{var mongoose = require('mongoose'); \newline % Row Count 1 (+ 1) \seqsplit{mongoose.connect('mongodb://localhost:27017/myDatabase');} \newline % Row Count 3 (+ 2) var Schema = mongoose.Schema; \newline % Row Count 4 (+ 1) {\bf{var personSchema = new Schema(\{}} \newline % Row Count 5 (+ 1) name: \{type: String, required: true, unique: true\}, \newline % Row Count 7 (+ 2) age: Number\} ); \newline % Row Count 8 (+ 1) module.exports = mongoose.model('Person', personSchema); \newline % Row Count 10 (+ 2) var Person = require('./Person.js); \newline % Row Count 11 (+ 1) app.use('/create', (req, res) =\textgreater{} \{ \newline % Row Count 12 (+ 1) var newPerson = new Person (\{ \newline % Row Count 13 (+ 1) name: req.body.name, \newline % Row Count 14 (+ 1) age: req.body.age,\}); \newline % Row Count 15 (+ 1) {\bf{newPerson.save( (err) =\textgreater{} \{}} \newline % Row Count 16 (+ 1) if (err) \{ \newline % Row Count 17 (+ 1) \seqsplit{res.type('html').status(500);} \newline % Row Count 18 (+ 1) res.send('Error: ' + err); \newline % Row Count 19 (+ 1) else\{ \newline % Row Count 20 (+ 1) res.render('created', \{person: newPerson \});\} \newline % Row Count 21 (+ 1) \}); \}); \newline % Row Count 22 (+ 1) {\bf{all within app.use}} \newline % Row Count 23 (+ 1) {\bf{Person.find( (err, allPeople) =\textgreater{} \{}} \newline % Row Count 24 (+ 1) if (err) \{ \newline % Row Count 25 (+ 1) \seqsplit{res.type('html').status(500);} \newline % Row Count 26 (+ 1) res.send('Error: ' + err); \newline % Row Count 27 (+ 1) else\{ \newline % Row Count 28 (+ 1) res.render('showAll', \{ people: allPeople \}); \newline % Row Count 29 (+ 1) \} \}); \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{MongoDB (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Person.findOne( \{name: searchName \}, (err, person) =\textgreater{} \{}} \newline % Row Count 2 (+ 2) if (err) \{...\} \newline % Row Count 3 (+ 1) else if(!person) \{ \newline % Row Count 4 (+ 1) \seqsplit{res.type('html').status(200);} \newline % Row Count 5 (+ 1) res.send('No person named ' + searchName); \newline % Row Count 6 (+ 1) else\{ \newline % Row Count 7 (+ 1) res.render('personInfo', \{person:person\});\} \newline % Row Count 8 (+ 1) \}); \newline % Row Count 9 (+ 1) {\bf{to update the database, combine both findOne and save}}% Row Count 11 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ES6}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ES6 adds classes (to replace prototypes), sets (distinct and ordered), maps (set of keys and values), and arrow functions among other things.% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Three-Tier Architecture}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{User Interface: get input, show output} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Processor/Controller: process data, searching and filtering} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Data Management: storing/retrieving data} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Express}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{var express = require('express'); \newline % Row Count 1 (+ 1) var app = express(); \newline % Row Count 2 (+ 1) app.use('/', (req, res) =\textgreater{} \{ \newline % Row Count 3 (+ 1) {\bf{res.send('Hello World!');}} \newline % Row Count 4 (+ 1) {\bf{res.json('Hello World!');\});}} \newline % Row Count 5 (+ 1) //res.json is identical to res.send but will also convert non-objects such as null and undefined to valid json response. \newline % Row Count 8 (+ 3) \seqsplit{res.status(404).send('Not} found!'); \newline % Row Count 9 (+ 1) //invoke the function when request for '/' is received \newline % Row Count 11 (+ 2) //res represents the HTTP response \newline % Row Count 12 (+ 1) app.listen(3000, () =\textgreater{} \{ \newline % Row Count 13 (+ 1) console.log('Listening on port 3000');\}); \newline % Row Count 14 (+ 1) //listens for incoming HTTP requests \newline % Row Count 15 (+ 1) app.use('/public', \seqsplit{express.static('files'));} \newline % Row Count 16 (+ 1) //express.static middleware for serving static files locally stored \newline % Row Count 18 (+ 2) {\bf{?name=Lydia\&returning=true in the URL}} \newline % Row Count 19 (+ 1) var query = req.query; \newline % Row Count 20 (+ 1) var name = query.name; \newline % Row Count 21 (+ 1) {\bf{body parser middleware}} \newline % Row Count 22 (+ 1) var bodyParser = require('body-parser'); \newline % Row Count 23 (+ 1) app.use(bodyParser.urlencoded(\{extended: true\})); \newline % Row Count 24 (+ 1) {\bf{\textless{}form action = "/handleForm" method = "post"\textgreater{}}} \newline % Row Count 25 (+ 1) app.user('/handleForm', (req, res) =\textgreater{} \{ \newline % Row Count 26 (+ 1) {\bf{var whatever = req.body.inputNameInHTMLForm;}} \newline % Row Count 27 (+ 1) var name = req.body.username; \newline % Row Count 28 (+ 1) var animals = {[}{]}.concat(req.body.animal); \newline % Row Count 29 (+ 1) //don't have to worry about null \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Express (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{res.type('html').status(200);}} \newline % Row Count 1 (+ 1) //start constructing response \newline % Row Count 2 (+ 1) {\bf{res.write('Hello');}} \newline % Row Count 3 (+ 1) //write but don't send yet \newline % Row Count 4 (+ 1) res.write('\textless{}ul\textgreater{}'); \newline % Row Count 5 (+ 1) animals.forEach( (animal) =\textgreater{} \{ \newline % Row Count 6 (+ 1) res.write('\textless{}li\textgreater{}' + animal + '\textless{}/li');\}); \newline % Row Count 7 (+ 1) res.write('\textless{}/ul\textgreater{}'); \newline % Row Count 8 (+ 1) {\bf{res.end();}} \newline % Row Count 9 (+ 1) //send response \newline % Row Count 10 (+ 1) \} \newline % Row Count 11 (+ 1) app.set('view engine', 'ejs'); \newline % Row Count 12 (+ 1) app.get('/', (req, res) =\textgreater{} \{ \newline % Row Count 13 (+ 1) {\bf{res.render('welcome', \{username: 'Olivia'\});\});}} \newline % Row Count 15 (+ 2) //render the welcome.ejs file in views/ subdirectory \newline % Row Count 17 (+ 2) //EJS will execute any JavaScript that appears between \textless{}\% and \%\textgreater{} when generating the HTML page on the server. \newline % Row Count 20 (+ 3) //\textless{}\%= username \%\textgreater{} \newline % Row Count 21 (+ 1) //allows you to not have to do a lot of res.writes with html in your javascript% Row Count 23 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Singleton}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{public class MyClass\{ \newline % Row Count 1 (+ 1) private MyClass()\{...\} \newline % Row Count 2 (+ 1) private static final MyClass instance = new MyClass(); \newline % Row Count 4 (+ 2) public static MyClass getInstance()\{ \newline % Row Count 5 (+ 1) return instace;\} \newline % Row Count 6 (+ 1) public void smthng()\{...\}% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Factory Method}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{public abstract class Proc\{ \newline % Row Count 1 (+ 1) protected Reader r; \newline % Row Count 2 (+ 1) public Proc()\{ r = createReader\} \newline % Row Count 3 (+ 1) protected abstract Reader createReader(); \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) public class fileProc extends Proc\{ \newline % Row Count 6 (+ 1) protected Reader createReader()\{ \newline % Row Count 7 (+ 1) return new fileReader();\} \newline % Row Count 8 (+ 1) \}% Row Count 9 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}