Skip to content

Instantly share code, notes, and snippets.

@donpark
donpark / react-lifecycle.md
Last active May 3, 2016 23:45
React.js Component Lifecycle

Invokation sequence of React.js Component Lifecycle Methods under four distinct conditions:

initial render

  • componentWillMount
  • render
  • componentDidMount

props change

Keybase proof

I hereby claim:

  • I am donpark on github.
  • I am superdon (https://keybase.io/superdon) on keybase.
  • I have a public key whose fingerprint is 065A 30C2 A391 5D3F F49C 00D1 DF40 87B3 6702 6798

To claim this, I am signing this object:

@donpark
donpark / hdom.coffee
Last active December 8, 2015 02:16
like virtual-dom except works with real elements
util = require('./util')
applyStyle = (elem, style) ->
if typeof style is 'string'
elem.setAttribute('style', style)
else
elem.style[key] = val for own key, val of style
return
@donpark
donpark / lazy.go
Created July 25, 2015 00:49
Abstract lazy connection with optional auto disconnect on idle timeout
package lazy
import (
"sync"
"time"
)
type Connection struct {
sync.Mutex
conn interface{}
@donpark
donpark / gist:7549a1a2a5f7eef7fbea
Created January 11, 2015 06:53
CALayer with resizable image
- (CALayer*)layerFromResiableImage:(UIImage*)image {
CGSize size = [image size];
UIEdgeInsets insets = [image capInsets];
CALayer *layer = [CALayer layer];
[layer setContents:(id)[image CGImage]];
layer.contentsCenter = CGRectMake(insets.left / size.width, insets.top / size.height,
1.0/size.width, 1.0 / size.height);
return layer;
}
@donpark
donpark / EventEmitter.coffee
Created January 22, 2014 17:49
Generic implementation of EventEmitter for browser in CoffeeScript
class EventEmitter
on: (name, listener) ->
listeners = (@_eventListeners ?= {})[name] ?= []
listeners.push listener
off: (name, listener) ->
if listeners = @_eventListeners?[name]
index = listeners.indexOf listener
listeners[index] = null if index >= 0
[localhost] local: npm outdated -g
grunt-cli /Users/don/.nvm/v0.10.21/lib/node_modules/grunt-cli current=0.1.9 wanted=0.1.10 latest=0.1.10
nodeunit /Users/don/.nvm/v0.10.21/lib/node_modules/nodeunit current=0.8.1 wanted=0.8.2 latest=0.8.2
stylus /Users/don/.nvm/v0.10.21/lib/node_modules/stylus current=0.39.4 wanted=0.40.0 latest=0.40.0
generator-webapp /Users/don/.nvm/v0.10.21/lib/node_modules/generator-webapp current=0.4.3 wanted=0.4.4 latest=0.4.4
uglify-js /Users/don/.nvm/v0.10.21/lib/node_modules/uglify-js current=2.4.2 wanted=2.4.3 latest=2.4.3
yeoman-generator /Users/don/.nvm/v0.10.21/lib/node_modules/generator-mocha/node_modules/yeoman-generator current=0.10.5 wanted=0.10.5 latest=0.14.0-rc.1
commander /Users/don/.nvm/v0.10.21/lib/node_modules/dox/node_modules/commander current=0.6.1 wanted=0.6.1 latest=2.0.0
stylus /Users/don/.nvm/v0.10.21/lib/node_modules/serve/node_modules/stylus current=0.39.4 wanted=0.40.0 latest=0.40.0
commander /Users/don/.nvm/v0.10.21/lib/node_modules/serve/node_modules/command
@donpark
donpark / toutf8.js
Created July 13, 2013 16:00
Convert JavaScript string to UTF-8 bytes in modern browsers using the File API
// Convert JavaScript string to UTF-8 bytes in modern browsers using the File API
// callback function will be called with UTF8 bytes in Uint8Array
//
// jsPerf test reveals this method is slower than looping over each character.
// http://jsperf.com/convert-javascript-string-to-utf-8-bytes-using-file-api
function toUTF8(string, cb) {
var reader = new FileReader();
reader.onload = function(evt) {
cb(new Uint8Array(reader.result));
@donpark
donpark / temple.coffee
Created June 30, 2013 04:21
Sketchy coffee-script that generates precompiled Hogan templates from a HTML file containing script tags of type `text/x-mustache-template'.
FS = require("fs")
Path = require("path")
Cheerio = require("cheerio")
Hogan = require("hogan.js")
htmlFile = process.argv[2]
html = FS.readFileSync process.argv[2], encoding: "utf8"
# console.log html
@donpark
donpark / npm-1.3.0-outdated.txt
Created June 22, 2013 04:40
output of `npm outdated -g` on npm version 1.3.0
$ npm -v
1.3.0
don@ironforge:~
$ npm outdated -g
superagent@0.9.7 /usr/local/lib/node_modules/c-pm/node_modules/superagent current=0.9.10
optimist@0.3.5 /usr/local/lib/node_modules/uglify-js/node_modules/optimist current=0.3.7
commander@0.5.2 /usr/local/lib/node_modules/docco/node_modules/commander current=1.2.0
less@1.3.0 /usr/local/lib/node_modules/recess/node_modules/less current=1.3.3
yeoman-generator@0.11.1 /usr/local/lib/node_modules/yo/node_modules/yeoman-generator current=0.11.4