Skip to content

Instantly share code, notes, and snippets.

View DC3's full-sized avatar

Dee Cheung DC3

View GitHub Profile
@DC3
DC3 / debounceHOC.js
Last active November 27, 2017 18:30
React controlled component debounce HOC
// 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) {
@DC3
DC3 / extend-array.js
Created September 18, 2017 03:36 — forked from Gozala/extend-array.js
Array subclass ES5
// 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() {
@DC3
DC3 / test-get-all-pixel-hex.coffee
Created August 31, 2017 10:14
test-get-all-pixel-hex.coffee
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) ->
@DC3
DC3 / index.coffee
Created August 15, 2017 07:01
React with CoffeeScrpt playground
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}"
@DC3
DC3 / index.coffee
Created August 15, 2017 07:01
React Two-way bindings
React = @React or require? 'react'
win = window
doc = win.document
# 业务逻辑变为 Mixin 方便复用
Mixin1 =
getInitialState: ->
title: @props.title
name: ''
count: 0
@DC3
DC3 / index.coffee
Created August 15, 2017 07:00
React children
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) ->
->
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, {
doc = document
$$ = doc.querySelectorAll.bind(doc)
NodeList::__proto__ = Array::
genParam = -> '?_=' + Date.now()
getXHR = (url) ->
xhr = new XMLHttpRequest
xhr.open 'GET', url
xhr
@DC3
DC3 / Makefile
Last active August 29, 2015 14:25 — forked from mattmccray/Makefile
Simple comparison of several compile-to-javascript languages, including: CoffeeScript, Dart, Haxe, and TypeScript.
.PHONY: compile
time=/usr/bin/time
compile: dart typescript coffeescript haxe jsx
dart:
$(time) dart2js -ooutput/dart.js source/simple.dart
typescript:
@DC3
DC3 / watchify.coffee
Created July 15, 2015 04:40
watchify-task
fs = require 'fs'
path = require 'path'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
stream = require 'vinyl-to-stream'
watchify = require 'watchify'
browserify = require 'browserify'
defaultOptions =