Log into database: mysql [db_name]
View a table: SELECT * FROM table_name;
Update a record in a table:
UPDATE [table_name] SET [table_column] = NOW() WHERE id = 1;
/** | |
* check if vals are objects | |
* if so. copy that object (deep copy) | |
* else return the value | |
*/ | |
function deepCopy(obj) { | |
const keys = Object.keys(obj); | |
const newObject = {}; | |
for (let i = 0; i < keys.length; i++) { |
// In JS `!!` can be used to convert any value to a boolean | |
// Similar to using the Boolean() function | |
(function() { | |
var foo = 'foo'; | |
console.log(typeof foo); | |
var bool = !!foo; | |
console.log(typeof bool); | |
console.log(bool); |
// `bind` and `this` | |
let dog = { | |
sound: 'woof', | |
talk: function() { | |
console.log(this.sound); | |
} | |
} | |
dog.talk(); // => 'woof' |
// Anonymous function: | |
// Ex.1 | |
(function() { | |
// We keep these variables private inside this closure scope | |
var myGrades = [93, 95, 88, 0, 55, 91]; | |
var average = function() { | |
var total = myGrades.reduce(function(accumulator, item) { | |
return accumulator + item; | |
}, 0); | |
return 'Your average grade is ' + total / myGrades.length + '.'; |
// JS has 5 data types that are assigned by value: | |
// `Boolean`, `String`, `Number`, `null`, `undefined` (primitives) | |
// JS has 3 data types that are assigned by reference: | |
// `Array`, `Function`, `Object` (objects) | |
var x = 1, y = '1', z = undefined; | |
// When we assign these vars to other vars we copy the value to the new var | |
var a = x, b = y, c = z; |
// Observer Pattern Notes | |
// The instance (subject) maintans a collection of objects (observers) | |
// The instance notifies the objects when changes to the state occur | |
class Observable { | |
// each instance starts with an empty array of observers that react to state changes | |
constructor() { | |
this.observers = []; | |
} | |
// Lifecycle phases: | |
// Initiialization: Defaults & initial values for `this.props` and `this.state` | |
// `getDefaultProps()` is called once and cached when the class is created | |
// We can't rely on `this.props` in `getDefaultProps()` | |
// `getInitialState()` is invoked once right before the mounting phase | |
var Counter = React.createClass({ | |
getDefaultProps: function() { | |
console.log('getDefaultProps'); |
// Passing a value of 0 to the `setTimeout` method deffers the callback to the end of the stack or until the stack is clear | |
setTimeout(function() { | |
console.log('test'); | |
}, 0); | |
// `setTimoeout` is not a guaranteed time to exucution, it's a minimum time to execution | |
// Passing a value of 0 to `setTimeout` doesn't run the code immediately, it runs the code as soon as the stack is clear (nextish) | |
// The event loop pushes any deffered executions in the task/callback que only after the stack is clear | |
// The stack can continue to run while waiting for a request from the web API | |
// The browser can't perform a render while code is running on the stack | |
// Avoid putting slow/heavy duty code on the stack because it prevents browsers from rendering the UI |
// Sessions | |
// A place to store data that you want access to across requests. | |
// Each user that visits your site has a unique session | |
// Sessions can be used to store and access user data as they access your application | |
// Sessions allow a web app to store state | |
// Simple session in Express: | |
import express from 'express'; | |
import session from 'express-session'; |