This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const resolved = Promise.resolve(); | |
| class Deferred { | |
| constructor() { | |
| const p = new Promise((resolve, reject) => { | |
| this.resolve = resolve; | |
| this.reject = reject; | |
| }); | |
| this.then = p.then.bind(p); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // usage | |
| // debounceHOC('input', { onChange: 300, onMouseOver: 1e3}) | |
| import _ from 'lodash'; | |
| import React, {PureComponent} from 'react'; | |
| import {findDOMNode} from 'react-dom'; | |
| function debounceHOC(Comp, events = {}) { | |
| class debounceEventsComponent extends PureComponent { | |
| constructor(props) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // No need to sub class Array if what you need is just an extended | |
| // array. Example below illustrates the way to extend Array. | |
| function SubArray() { | |
| return Object.defineProperties(Array.prototype.slice.call(arguments), SubArrayDescriptor) | |
| } | |
| SubArray.prototype = Array.prototype | |
| var SubArrayDescriptor = | |
| { constructor: { value: SubArray } | |
| , last: { value: function last() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| testImgUrl = '//img.alicdn.com/tps/i4/TB1PVZoOpXXXXcKXXXXSutbFXXX.jpg' | |
| rgbToHex = (r, g, b) -> | |
| hex = (i) -> | |
| h = i.toString 16 | |
| h = '0' + h if h.length < 2 | |
| h | |
| ['#', hex(r), hex(g), hex(b)].join('') | |
| getOnePixelHex = (context, x, y, w = 1, h = 1) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| React = @React or require 'react' | |
| win = window | |
| doc = win.document | |
| class ExampleComponent extends React.Component | |
| mixins: [React.DOM] | |
| getInitialState: -> | |
| name: 'DC3' | |
| render: -> | |
| @div null, "hello world form react! #{@state.name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| React = @React or require? 'react' | |
| win = window | |
| doc = win.document | |
| # 业务逻辑变为 Mixin 方便复用 | |
| Mixin1 = | |
| getInitialState: -> | |
| title: @props.title | |
| name: '' | |
| count: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| React = @React or require 'react' | |
| win = window | |
| doc = win.document | |
| range = (length) -> Array.apply(null, {length}).map(Number.call, Number) | |
| randomInt = (min, max) -> Math.floor(Math.random() * (max - min + 1)) + min | |
| memoized = (fn) -> | |
| do (lookupTable = {}, key = undefined, value = undefined) -> | |
| -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = "60o0749460o07134482"; | |
| //var b= parseInt(a, 10); | |
| G = function(a, b) { | |
| var c = function(a) { | |
| for (var b, c = [], d = 3, e = function(a) { | |
| return a >= "0" && "9" >= a ? parseInt(a, 10) : a.charCodeAt(0) - "a".charCodeAt(0) + 10 | |
| }, f = function(a, b) { | |
| var c, d, f, g, h; | |
| //c =e 函数 | |
| return c = e(a[b]), d = e(a[b + 1]), d = 15 & d, f = (12 & c) >> 2, g = (2 & c) > 0, h = (1 & c) > 0, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| doc = document | |
| $$ = doc.querySelectorAll.bind(doc) | |
| NodeList::__proto__ = Array:: | |
| genParam = -> '?_=' + Date.now() | |
| getXHR = (url) -> | |
| xhr = new XMLHttpRequest | |
| xhr.open 'GET', url | |
| xhr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .PHONY: compile | |
| time=/usr/bin/time | |
| compile: dart typescript coffeescript haxe jsx | |
| dart: | |
| $(time) dart2js -ooutput/dart.js source/simple.dart | |
| typescript: |