Skip to content

Instantly share code, notes, and snippets.

View idiotWu's full-sized avatar

Daofeng Wu idiotWu

  • Tokyo, Japan
  • 18:41 (UTC +09:00)
View GitHub Profile
@idiotWu
idiotWu / attach-events.js
Last active October 6, 2017 15:22
attach-events decorator for react
/**
* @decorator
* Attach events to DOM element
*
* @param {Element|Function} elemOrFunc: DOM Element, or a function returns element
* @param {String} events: a list events separated with ','
*
* Usage:
* @attachEvents(window, 'click')
* handleWindowClick(evt) {
@idiotWu
idiotWu / gist:efedfe5c6153ce5740662b841c0d0849
Created May 22, 2016 15:36 — forked from wintercn/gist:5342839
取两个HTML节点最近的公共父节点
function getCommonParent(el1,el2){
var parents1 = [];
var el = el1;
while(el) {
parents1.unshift(el);
el = el.parentNode;
}
var parents2 = [];
/**
* An implementation for Quicksort. Doesn't
* perform as well as the native Array.sort
* and also runs the risk of a stack overflow
*
* Tests with:
*
* var array = [];
* for(var i = 0; i < 20; i++) {
* array.push(Math.round(Math.random() * 100));
@idiotWu
idiotWu / concat-with-callbacks.js
Last active June 14, 2022 08:33
ES6 Promise Examples
/**
* @date 2015/3/21
* @author Dolphin
*
* Callback 风格的文件合并
*/
var fs = require('fs');
function getFilesInDir(dir, cb) {
@idiotWu
idiotWu / unre.js
Created April 4, 2015 08:43
redo/undo manager
var Manager = function (obj) {
this.target = obj;
this.history = [];
this.step = -1;
return this;
}
Manager.prototype.set = function (key, value) {
var me = this,
target = me.target;