Skip to content

Instantly share code, notes, and snippets.

View idiotWu's full-sized avatar

Daofeng Wu idiotWu

  • Tokyo, Japan
  • 16:37 (UTC +09:00)
View GitHub Profile
@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;
@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) {
/**
* 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 / 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 = [];
@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 / themr.js
Last active March 29, 2017 03:22
Another theme-able solution for react reusable components.
/*
* Usage:
*
* As a decorator:
*
* import defaultTheme from './style.scss';
*
* @themr(defaultTheme)
* class Comp extends React.Component { ... }
*
/**
* Optimize hybrid controlled component by add some method into proto
*
* Usage:
* @hybridCtrl
* class App extends React.Component {
* ...
* }
*
* @hybridCtrl('specified_prop_to_assign')
@idiotWu
idiotWu / component.js
Last active February 17, 2017 07:04
React refs saver
@storeRefs
class Demo extends React.Component {
doSomething() {
this.buttonRef.kill();
}
render() {
return (
<Button refs={this.storeRefAs('buttonRef')}>blabla</Button>
);
@idiotWu
idiotWu / tab-trigger.js
Created October 19, 2016 10:57 — forked from wesbos/tab-trigger.js
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@idiotWu
idiotWu / shadow.js
Last active November 13, 2016 18:54
DOM shadow blur algorithm: http://codepen.io/idiotWu/pen/YpwBdQ
// demo config
const color = 'rgba(255, 0, 255, 1)';
const radius = 50;
const offsetX = 50;
const offsetY = 50;
const width = 200;
const height = 100;
const dx = 100;
const dy = 100;