Skip to content

Instantly share code, notes, and snippets.

View Gyumeijie's full-sized avatar
🎯
Focusing

YuMeiJie Gyumeijie

🎯
Focusing
View GitHub Profile
@Gyumeijie
Gyumeijie / redux middleware
Last active March 9, 2018 13:47
some beautiful design
1. 中间件接口
{dispatch, getState} => next => action => your code
中间件串联在一起时,在需要的时候通过调用next来调用下一个中间件,因此需要建立各个中间件next参数之间的连接(类似数据结构中链表节点中next);
compose(...chain)(store.dispatch)语句相当于从后建立起了各个中间件next参数之间的连接关系,其中最后一个中间件的next的值为store.dispatch
使用compose函数合成多个函数的时候,内层函数的返回值称为外层函数的参数,外层函数可以通过这个参数引用内层函数的的返回值
@Gyumeijie
Gyumeijie / eventloop
Last active March 19, 2018 08:37
node
1. 为什么JavaScript是单线程? ---为什么不是多线程呢
JavaScript的单线程,与它的用途有关。作为浏览器脚本语言,JavaScript的主要用途是与用户互动,
以及操作DOM。这决定了它只能是单线程,否则会带来很复杂的同步问题。
如果排队是因为计算量大,CPU忙不过来,倒也算了,但是很多时候CPU是闲着的,因为IO设备(输入输出设备)
很慢(比如Ajax操作从网络读取数据),不得不等着结果出来,再往下执行。
JavaScript语言的设计者意识到,这时主线程完全可以不管IO设备,挂起处于等待中的任务,先运行排在后面的任务。
等到IO设备返回了结果,再回过头,把挂起的任务继续执行下去。
@Gyumeijie
Gyumeijie / tmux.md
Created May 3, 2018 16:32 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

function addQueryParameters (url, parameters) {
const separator = /\?/.test(url) ? '&' : '?'
const names = Object.keys(parameters)
if (names.length === 0) {
return url
}
return url + separator + names
.map(name => {