Skip to content

Instantly share code, notes, and snippets.

View idiotWu's full-sized avatar

Daofeng Wu idiotWu

  • Tokyo, Japan
  • 03:32 (UTC +09:00)
View GitHub Profile
@idiotWu
idiotWu / unlock.js
Last active November 19, 2017 11:53
Unlock netease music
const http = require('http');
const net = require('net');
const url = require('url');
const IP = '211.161.244.70';
const hosts = {
'p[1-4].music.126.net': 'cloudedge.chinanetcenter.com',
'm10.music.126.net': 'ws.acgvideo.com',
};
@idiotWu
idiotWu / fake-observable.js
Created May 18, 2017 09:08
A fake observable
let currentCaller = null;
class FakeObservable {
constructor() {
this._value = null;
this._callers = new Set();
}
set(val) {
this._value = val;
@idiotWu
idiotWu / extensify.js
Last active February 8, 2017 08:04
Make built-in classes extendable
// copied from <https://github.com/service-mocker/service-mocker>
function extensify(Native) {
class Extendable {
constructor(...args) {
this._native = initNative(...args);
checkLack(this._native);
}
}
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@idiotWu
idiotWu / setZeroTimeout.js
Created November 15, 2016 08:31 — forked from mathiasbynens/setZeroTimeout.js
Cross-browser-compatible setZeroTimeout
/*! Cross-browser-compatible setZeroTimeout
*
* I took the original setZeroTimeout and made it cross-browser-compatible, using setTimeout(fn, 0) as a fallback in case postMessage is not supported.
* Mathias Bynens <http://mathiasbynens.be/>
* See <http://mathiasbynens.be/notes/settimeout-onload>
*
* Copyright statement below:
*
* See <http://dbaron.org/log/20100309-faster-timeouts>
* By L. David Baron <dbaron@dbaron.org>, 2010-03-07, 2010-03-09
@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;
@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 / 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>
);
/**
* Optimize hybrid controlled component by add some method into proto
*
* Usage:
* @hybridCtrl
* class App extends React.Component {
* ...
* }
*
* @hybridCtrl('specified_prop_to_assign')
@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 { ... }
*