Skip to content

Instantly share code, notes, and snippets.

View yukeehan's full-sized avatar

Yukee Han yukeehan

  • Ottawa
View GitHub Profile
list = {
name: 'yukee'
}
// ES5
this.state = {
list: list,
};
// ES6
this.state = {
@yukeehan
yukeehan / hotModuleReplacement.js
Created December 3, 2018 19:09
Hot Module Replacement (HMR) is a tool for reloading your application in the browser without the page refresh.
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(
<App />,
document.getElementById('root')
);
@yukeehan
yukeehan / changingArrayAndObject.js
Last active December 3, 2018 16:54
changing array and obj without modify original one
// remove index-1 position component of array without modify the origin array
list = [1, 2, 3, 4, 5]
const removeCounter = (list, index) => {
return [
...list.slice(0, index),
...list.slice(index + 1)
];
}
removerCounter(list, 3); //[1, 2, 4, 5];
@yukeehan
yukeehan / creatStore from Scratch.js
Created December 3, 2018 16:14
creatStore from Scratch
const createStore = (reducer) => {
let state;
let listeners = []; // an array of listeners
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener()); // to notify every change listener by calling it
};
@yukeehan
yukeehan / .pipe( )
Created October 30, 2018 13:49
.pipe( ) function in JS
// pipe function: A pipe function takes an n sequence of operations; in which each operation takes an argument;
// process it; and gives the processed output as an input for the next operation in the sequence. The result of a
// pipe function is a function that is a bundled up version of the sequence of operations.
//======= two functions in pipe function =========
const pipe = (op1, op2) => {
return (arg) => {
const result1 = op1(arg);
return op2(result1);
}
}
@yukeehan
yukeehan / bind
Created October 18, 2018 01:22
bind
/* let dog = {
sound: 'woof',
talk: function(){
console.log(this.sound);
}
}
const Talk = dog.talk.bind(dog);
Talk(); */
@yukeehan
yukeehan / app.js
Created July 16, 2018 02:53
Login/Logout/Register using Passport-Local-Mongoose
var express = require("express"),
mongoose = require("mongoose"),
bodyParser = require("body-parser"),
User = require("./models/user"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose");
mongoose.connect("mongodb://localhost:27017/auth_demo_app", { useNewUrlParser: true });
var app = express();
@yukeehan
yukeehan / embed.js
Created July 12, 2018 16:00
Association by MongoDB (2 ways: embedding data & object reference)
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/blog_demo", { useNewUrlParser: true });
// POST - title, content
var postSchema = new mongoose.Schema({
title: String,
content: String
});
var Post = mongoose.model("Post", postSchema);
@yukeehan
yukeehan / app.css
Created July 11, 2018 20:35
Restful Route Blog App
#main_container{
margin-top: 7.0em;
}
#delete{
display: inline;
}
@yukeehan
yukeehan / chineseFood.js
Created July 6, 2018 17:34
Learning how to use Mongoose
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/food_app");
var foodSchema = new mongoose.Schema({
name: String,
taste: String,
isGood: Boolean,
price: Number
});