├── m1 ├── js │ └── boilerplate.js ├── html │ └── boilerplate.html ├── project.md ├── project-readme.md ├── oo │ └── example.js ├── css │ └── boilerplate.css ├── advanced.md ├── resources.md └── README.md ├── README.md ├── m3 ├── angular-routing │ ├── app.component.html │ ├── app.module.ts │ ├── restaurant-list.component.html │ ├── restaurant-create.component.ts │ └── restaurant-detail.component.ts ├── angular-forms │ ├── app.module.ts │ ├── styles.css │ ├── my-form.component.html │ └── my-form.component.ts ├── express-cors │ └── app.js ├── angular-http │ ├── app.module.ts │ ├── restaurant-list.component.html │ ├── restaurant-list.component.ts │ └── restaurant.service.ts ├── express-api-errors │ └── app.js ├── angular-app-layout │ └── app.component.html ├── project.md ├── typescript │ ├── types.ts │ └── interfaces.ts ├── angular-auth │ ├── app.component.html │ ├── guards │ │ ├── init-auth.guard.ts │ │ ├── require-anon.guard.ts │ │ └── require-user.guard.ts │ ├── app.component.ts │ ├── app.module.ts │ └── auth.service.ts ├── deployment │ ├── app.js │ └── readme.md ├── resources.md ├── angular-scss │ └── README.md ├── advanced.md ├── express-auth │ ├── auth.js │ └── rest-auth.postman_collection.json ├── project-readme.md └── README.md ├── extras ├── trends.md └── agile.md ├── m2 ├── express-apps │ ├── make-passport-user-available-for-templates.js │ ├── hbs-views-and-layouts.js │ ├── ejs-views-and-layouts.js │ ├── mongoose-connect.js │ ├── passport.js │ ├── bcrypt.js │ ├── flash.js │ ├── session.js │ ├── app.js │ └── helpers-passport.js ├── mongoose-models │ ├── review-as-subschema.js │ ├── home-with-owner.js │ ├── user-with-auto-timestamps.js │ ├── event-with-attendees.js │ ├── product-with-subschema.js │ └── restaurant-with-location.js ├── forms-css │ ├── form.html │ └── forms.css ├── project.md ├── es6 │ └── es6.js ├── mongoose-querys │ └── with-promises.js ├── resources.md ├── deployment.md ├── advanced.md ├── project-readme.md └── README.md ├── tools ├── eslint │ ├── README.MD │ └── .eslintrc.json ├── git │ ├── .gitignore │ └── README.md ├── shortcuts │ ├── chrome.md │ ├── terminal.md │ └── vscode.md └── vscode │ └── README.md └── .gitignore /m1/js/boilerplate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | debugger; 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cheat Sheet 2 | 3 | - [module 1](m1/) 4 | - [module 2](m2/) 5 | - [module 3](m3/) 6 | - [tools](tools/) 7 | -------------------------------------------------------------------------------- /m3/angular-routing/app.component.html: -------------------------------------------------------------------------------- 1 | ... 2 | 3 |
hello ${name}
45 | `; 46 | 47 | 48 | // -- destructuring 49 | 50 | const person = {name: 'Joe', age: 33}; 51 | let {name, age} = person; 52 | console.log(name, age); // Joe 33 53 | 54 | 55 | -------------------------------------------------------------------------------- /m3/angular-forms/my-form.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-my-form', 5 | templateUrl: './my-form.component.html', 6 | styleUrls: ['./my-form.component.css'] 7 | }) 8 | export class MyFormComponent implements OnInit { 9 | 10 | feedbackEnabled = false; 11 | error = null; 12 | processing = false; 13 | // ... model (e,g. username: String) 14 | 15 | constructor(/* inject required services */) { } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | submitForm(form) { 21 | this.error = ''; 22 | this.feedbackEnabled = true; 23 | if (form.valid) { 24 | this.processing = true; 25 | // this.someService.method(... data ...) 26 | // .then((result) => { 27 | // // ... handle result, reset form, etc... 28 | // // ... navigate with this.router.navigate(['...']) 29 | // // ... maybe turn this to false if your're staying on the page - this.processing = false; 30 | // }) 31 | // .catch((err) => { 32 | // this.error = err.error.error; // :-) 33 | // this.processing = false; 34 | // this.feedbackEnabled = false; 35 | // }); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /m2/express-apps/helpers-passport.js: -------------------------------------------------------------------------------- 1 | // note: use in conjunction with https://github.com/ByronGBP/ih-cheat-sheet/blob/master/snippets/express-apps/passport.js 2 | 3 | 'use strict'; 4 | 5 | const bcrypt = require('bcrypt'); 6 | const passport = require('passport'); 7 | const LocalStrategy = require('passport-local').Strategy; 8 | 9 | // NOTE: assumes that models/User exports an object with a "User" property 10 | const User = require('../models/user').User; 11 | 12 | function config () { 13 | passport.serializeUser((user, cb) => { 14 | cb(null, user._id); 15 | }); 16 | 17 | passport.deserializeUser((id, cb) => { 18 | User.findOne({ '_id': id }, (err, user) => { 19 | if (err) { return cb(err); } 20 | cb(null, user); 21 | }); 22 | }); 23 | 24 | passport.use(new LocalStrategy((username, password, next) => { 25 | User.findOne({ username }, (err, user) => { 26 | if (err) { 27 | return next(err); 28 | } 29 | if (!user) { 30 | return next(null, false, { message: 'Incorrect username' }); 31 | } 32 | if (!bcrypt.compareSync(password, user.password)) { 33 | return next(null, false, { message: 'Incorrect password' }); 34 | } 35 | 36 | return next(null, user); 37 | }); 38 | })); 39 | } 40 | 41 | module.exports = config; 42 | -------------------------------------------------------------------------------- /m2/mongoose-querys/with-promises.js: -------------------------------------------------------------------------------- 1 | const Place = require('../models/place'); 2 | 3 | // with promise variable 4 | router.get('/', (req, res, next) => { 5 | const promise = Place.find({ type: 'restaurant' }); 6 | promise.then((result) => { 7 | const data = { 8 | places: result; 9 | } 10 | res.render('place', data); 11 | }); 12 | promise.catch((error) => { 13 | next(error); 14 | }); 15 | }); 16 | 17 | router.post('/place', (req, res, next) => { 18 | const newPlace = { 19 | name: req.body.name, 20 | } 21 | const promise = Place.insertOne(newPlace); 22 | promise.then(() => { 23 | res.redirect('/'); 24 | }); 25 | promise.catch((error) => { 26 | next(error); 27 | }); 28 | }); 29 | 30 | 31 | // with chaining (no promise var) 32 | router.get('/', (req, res, next) => { 33 | Place.find({ type: 'restaurant' }) 34 | .then((result) => { 35 | const data = { 36 | places: result; 37 | } 38 | res.render('place', data); 39 | }); 40 | .catch((error) => { 41 | next(error); 42 | }); 43 | }); 44 | 45 | router.post('/place', (req, res, next) => { 46 | const newPlace = { 47 | name: req.body.name, 48 | } 49 | Place.insertOne(newPlace) 50 | .then(() => { 51 | res.redirect('/'); 52 | }) 53 | .catch((error) => { 54 | next(error); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /tools/vscode/README.md: -------------------------------------------------------------------------------- 1 | # chrome 2 | - `cmd + alt + arrow` (change between tabs) 3 | - `cmd + shift + i` (open inspector) 4 | - `cmd + r` (reload page) 5 | - `cmd + l` (focus on navigation bar) 6 | - `cmd + n` (open new window) 7 | - `cmd + t` (open new tab) 8 | - `cmd + w` (close current tab) 9 | - `cmd + shit + t` (open closed tab) 10 | - `cmd + q` (close chrome) 11 | 12 | # mac 13 | - `cmd + space + appName` (spotlight search) 14 | - `cmd + tab` (change between apps) 15 | 16 | # vs code (install extension Sublime Text Keymap) 17 | - `cmd + alt + arrow` (change between tabs) 18 | - `cmd + w` (close current tab) 19 | - `cmd + s` (save current file) 20 | - `cmd + atl + s` (save all open files) 21 | - `cmd + z` (undo) 22 | - `cmd + shift + z` (redo) 23 | - `cmd + c` (copy selected to clipboard) 24 | - `cmd + x` (cut selected to clipboard) 25 | - `cmd + v` (paste clipboard) 26 | - `cmd + d` (select the selected) 27 | - `cmd + backspace` (remove all to left) 28 | - `cmd + shift + d` (duplicate line) 29 | - `cmd + arrow` (go to arrow's direction) 30 | - `alt + arrow left/right` (move to next/previous word) 31 | - `alt + arrow up/down` (move line to) 32 | - `shift + arrow` (select) 33 | - `shift + alt + arrow` (select word) 34 | - `shift + cmd + arrow` (select from focus to arrow's direction) 35 | - `cmd + a` (select all) 36 | - `cmd + p` (search in project) 37 | - `cmd + /` (comment selected) -------------------------------------------------------------------------------- /m2/resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | ## Tools 4 | 5 | - [ESLint](https://eslint.org/docs/rules/) 6 | - [Postman](https://www.getpostman.com/) 7 | 8 | ## Documentation 9 | 10 | ### ES6 11 | 12 | - [ES6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_2015_support_in_Mozilla) 13 | - [ES6 online book](http://exploringjs.com/es6/) 14 | 15 | ### Node 16 | 17 | - [Node.js](https://nodejs.org/en/docs/) 18 | - [NPM](https://docs.npmjs.com/) 19 | 20 | ### Express 21 | 22 | - [ExpressJs](https://expressjs.com/en/4x/api.html) 23 | 24 | ### MongoDB 25 | 26 | - [MongoDB](https://docs.mongodb.com/) 27 | - [Query Selectors](https://docs.mongodb.com/manual/reference/operator/query/#query-selectors) 28 | - [Update Operators](https://docs.mongodb.com/manual/reference/operator/update/#id1) 29 | - [Mongoose](http://mongoosejs.com/docs/guide.html) 30 | 31 | ## Libraries 32 | 33 | - [Lodash](https://lodash.com/docs) 34 | - [EJS](http://ejs.co/) 35 | - [Handlebars](http://tryhandlebarsjs.com/) 36 | - [Passport](http://www.passportjs.org/) 37 | 38 | ## Websites 39 | 40 | - [HackerNoon](https://hackernoon.com/) 41 | - [Webapp](https://webapplog.com/) 42 | - [StrongLoop](https://strongloop.com/strongblog/) 43 | - [IBM Javascript](https://developer.ibm.com/node/category/javascript-language/) 44 | 45 | ## Specifications 46 | 47 | - [Promises A+](https://promisesaplus.com/) 48 | -------------------------------------------------------------------------------- /m1/css/boilerplate.css: -------------------------------------------------------------------------------- 1 | 2 | /* ---- reset ---- */ 3 | 4 | html { 5 | box-sizing: border-box; 6 | } 7 | *, *:before, *:after { 8 | box-sizing: inherit; 9 | } 10 | 11 | body { 12 | margin: 0; 13 | padding: 0; 14 | } 15 | 16 | 17 | /* ---- typography ---- */ 18 | 19 | body { 20 | color: #111; 21 | font-family: Helvetica, Arial, sans-serif; 22 | font-size: 16px; 23 | line-height: 147%; 24 | } 25 | 26 | h1 {} 27 | 28 | h2 {} 29 | 30 | h3 {} 31 | 32 | p { 33 | margin: 0; 34 | } 35 | 36 | 37 | 38 | /* ---- layout ---- */ 39 | 40 | #site-header { 41 | padding: 30px 0; 42 | color: white; 43 | background: #111; 44 | } 45 | 46 | #site-footer { 47 | color: white; 48 | padding: 60px 0; 49 | background: #111; 50 | } 51 | 52 | #site-main { 53 | margin-bottom: 60px; 54 | } 55 | 56 | .container { 57 | margin: 0 20px; 58 | } 59 | 60 | .section { 61 | margin-bottom: 20px; 62 | padding-top: 20px; 63 | } 64 | 65 | @media (min-width: 768px) { 66 | .container { 67 | max-width: 728px; 68 | margin: 0 auto; 69 | } 70 | } 71 | 72 | 73 | 74 | 75 | /* ---- components ---- */ 76 | 77 | .button { 78 | width: 100%; 79 | background-color: blue; 80 | color: #fff; 81 | border: 1px solid #fff 82 | } 83 | 84 | .button-alt { 85 | color: blue; 86 | background-color: #fff; 87 | } 88 | 89 | /* ---- section ---- */ 90 | 91 | section.testimonials { 92 | // ... 93 | } 94 | 95 | section.testimonials .button { 96 | margin-bottom: 10px; 97 | } 98 | -------------------------------------------------------------------------------- /m3/angular-scss/README.md: -------------------------------------------------------------------------------- 1 | # if you start from scratch 2 | 3 | - https://scotch.io/tutorials/using-sass-with-the-angular-cli 4 | - ng new my-sassy-app --style=scss 5 | 6 | # if you want to convert an existing app 7 | 8 | ## update your angular-cli configuration (for ng serve, ng new, etc...) 9 | 10 | Don't forget to restart `ng-serve` after this. 11 | 12 | It will print some errors until you fix the following 13 | 14 | // .angular-cli.json 15 | 16 | 17 | "styles": [ 18 | "styles.scss" // - our main file converted to scss 19 | ], 20 | 21 | "defaults": { 22 | "styleExt": "scss", // - extension for components we generate next 23 | 24 | 25 | ## convert your main file to scss 26 | 27 | // styles.css > styles.scss 28 | 29 | @import './scss/variables.scss'; 30 | 31 | body { 32 | color: $color-body; 33 | } 34 | 35 | 36 | 37 | ## convert your existing components to scss 38 | 39 | // src/app/components/some.component.ts 40 | 41 | @Component({ 42 | selector: 'app-some', 43 | templateUrl: './some.component.html', 44 | styleUrls: ['./some.component.scss'] // <- changed the extension 45 | }) 46 | 47 | 48 | // src/app/components/some.component.css > src/app/components/some.component.scss 49 | 50 | @import '../../../scss/variables.scss'; 51 | 52 | h1 { 53 | color: $color-title; 54 | } 55 | 56 | ## create your global scss files in a separate folder 57 | 58 | 59 | // src/scss/variables.scss 60 | 61 | $color-body: black; 62 | $color-title: green; 63 | 64 | 65 | -------------------------------------------------------------------------------- /m3/angular-http/restaurant.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpResponse } from '@angular/common/http'; 3 | 4 | // import { environment } from '../../environments/environment'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | 10 | export class RestaurantService { 11 | 12 | private baseUrl = 'http://localhost:3000/restaurants'; 13 | 14 | constructor(private httpClient: HttpClient) { } 15 | 16 | // options.withCredentials is always required 17 | // without it, the HttpClient service does not send cookies in a CORS context 18 | // cookies are required to keep a session in the Rest API 19 | 20 | getList(): Promise