View gist:d9dce3062e75a9972f54c552d2d0cb38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createStore = (reducer) => | |
{ | |
let state; | |
let listeners = []; | |
const getState = () => state; | |
const dispatch = (action) => | |
{ | |
state = reducer(state , action); |
View modeling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For categories: | |
ID | Name | Parent_ID | |
(Parent ID is for category tree) | |
For products: | |
ID | Category_ID | Name | Description | Other | |
Let's say the category tree is like |
View redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createStore = (reducer) => | |
{ | |
let state; | |
let listeners = []; | |
const getState = () => state; | |
const dispatch = (action) => | |
{ | |
state = reducer(state , action); |
View Reduxagain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function todo(state, action) | |
{ | |
switch(action.type) | |
{ | |
case 'ADD_TODO': | |
return { | |
id: action.id, | |
text: action.text, |
View promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
httpGetUser('http://localhost:3000/users') | |
.then(response => | |
{ | |
console.log('First resolve callback'); | |
console.log('~~~~~~~~~~'); | |
var user = JSON.parse(response); | |
user = user.find((user) => user.name == 'Nerhbest'); | |
return user.name; |
View memoize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function memoize(func) | |
{ | |
let cache = {}; | |
return function(x ,y) | |
{ if(Object.keys(cache).length == 0) | |
{ | |
cache.res = func(x,y ); | |
cache.x = x; |
View middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let middlewares = [{ | |
handle(requesst , next) | |
{ | |
console.log(`Username is: ${request.name}`); | |
next(request); | |
} | |
}, | |
{ | |
handle(request ,next) | |
{ |
View reverse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr1 = [1,2,3,4,5]; | |
let arr2 = [1,2,3,4,5,6,7,8,9,10]; | |
function reverse(arr) | |
{ | |
var len = arr.length; | |
var middle = Math.floor(len / 2); | |
var start = 0; | |
var end = len - 1; | |
View PipeandReduce.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let statement = "wELCOME | lower | capitalize"; | |
let another = "welcome | upper"; | |
let handlers = { | |
lower : (val) => val.toLowerCase(), | |
upper: (val) => val.toUpperCase(), | |
capitalize: (val) => val.slice(0,1).toUpperCase() + val.slice(1) | |
}; |
View gitconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all | |
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all | |
lg = !"git lg1" | |
[core] | |
editor = vim |
OlderNewer