Skip to content

Instantly share code, notes, and snippets.

@mutongwu
mutongwu / gist:c0832c3312afae6d0cdc62fd8bacd6a2
Created September 30, 2016 06:19 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@mutongwu
mutongwu / test.md
Created February 16, 2017 03:25
test

###sfsfsf

@mutongwu
mutongwu / test.md
Created February 16, 2017 03:25
test

###sfsfsf

@mutongwu
mutongwu / tinypromise
Created April 24, 2018 09:57
a tiny promise polyfill
function isThenable(obj){
if(obj && typeof obj.then === 'function'){
return true;
}
return false;
}
function ChainedPromise(promise, rv, rj){
this.success = [rv];
this.fail = [rj];
this.promise = promise;
@mutongwu
mutongwu / index.html
Last active August 10, 2018 07:10
dnd tree example by using dragula.js
<!DOCTYPE html>
<html>
<head>
<title>progressCanvas</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="./bootstrap.min.css" />
<link rel="stylesheet" href="./bower_components/dragula.js/dist/dragula.css" />
<style>
.compList{height:360px;border: 1px solid green;}
.compType{border:1px solid black;margin:10px;list-style: none;}
@mutongwu
mutongwu / redux_monkey_patch.md
Last active October 11, 2018 08:43
redux_monkey_patch

理解 redux 的middleware 中间件 机制: https://redux.js.org/advanced/middleware

假如对 store.dispatch 函数,做一些调整,比如 log、errorCatch 的事情,通常我们会想到 monkey-patch:

function addLog(store){
	var next = store.dispatch;

	store.dispatch = function(action){
		console.log('action before');
@mutongwu
mutongwu / nocache.md
Created January 3, 2019 14:52
disable cache with meta tag

    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="expires" content="0" />
    <meta name="renderer" content="webkit"/> 
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
@mutongwu
mutongwu / js
Last active January 25, 2019 07:35
ease animation
// https://pawelgrzybek.com/page-scroll-in-vanilla-javascript/
function scrollIt(destination, duration = 200, easing = 'linear', callback) {
const easings = {
linear(t) {
return t;
},
easeInQuad(t) {
return t * t;
npm publish 发布 npm 包
1. 默认情况下,不存在 .npmignore,npm 会依据 .gitignore 来选择过滤上传的文件;
2. 如果存在 .npmignore (即便是空白的),则 不再使用 .gitignore;
3. package.json 里面的 files 字段,拥有较高权重,控制打包的文件。
默认被排除在外的文件:
.*.swp
._*
.DS_Store
.git
@mutongwu
mutongwu / clone.md
Last active July 15, 2019 02:37
deep clone object

Depth-First Traversal

function clone(src){
	var dest = src;
	if(!src) {
		return dest;
	} else {
		if(typeof src === 'object') {
			if(Array.isArray(src)) {
				dest = []