Skip to content

Instantly share code, notes, and snippets.

View lanqy's full-sized avatar
🎯
Focusing

Lan Qingyong lanqy

🎯
Focusing
  • Shenzhen,China
View GitHub Profile
module Store = {
type actions =
| Increase
| Decrease;
type state = {count: int};
type store = {
state,
dispatch: actions => unit
};
let component = ReasonReact.reducerComponent("Store");
@lanqy
lanqy / args.ml
Created October 15, 2017 03:15 — forked from ghulette/args.ml
Labeled and optional arguments in OCaml, by example
open Printf
(* Labeled arguments, the easy way *)
let _ =
(* Declare a function with labeled arguments like this: *)
let f ~x ~y = x + y in
(* Type: f : x:int -> y:int -> int *)
(* Call it like this: *)
printf "%d\n" (f ~x:5 ~y:6);
@lanqy
lanqy / chat-frontend.js
Created July 4, 2017 08:49 — forked from martinsik/chat-frontend.js
Node.js chat frontend and server
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;
@lanqy
lanqy / two-way-binding.js
Created May 16, 2017 12:48 — forked from straker/two-way-binding.js
Simple and small two-way data binding between DOM and data
/**
* @param {object} scope - Object that all bound data will be attached to.
*/
function twoWayBind(scope) {
// a list of all bindings used in the DOM
// @example
// { 'person.name': [<input type="text" data-bind="person.name"/>] }
var bindings = {};
// each bindings old value to be compared for changes
@lanqy
lanqy / GIFDownloader.h
Created January 23, 2017 02:47 — forked from paul-delange/GIFDownloader.h
Convert remote GIF into something MPMoviePlayerController can use
//
// GIFDownloader.h
// TheJoysOfCode
//
// Created by Bob on 29/10/12.
// Copyright (c) 2012 Tall Developments. All rights reserved.
//
#import <Foundation/Foundation.h>
@lanqy
lanqy / browserify_for_webpack_users.markdown
Created October 21, 2016 14:58
browserify for webpack users

browserify for webpack users

There's been a strange explosion in misinformation about browserify recently, particularly in comparisons to webpack.

Generally speaking, most of this confusion stems from how webpack is more willing to pull features into its core to ease discoverability while browserify is more likely to push features out to userland instead.

I think that longer-term, separability has more benefits from a maintenance and

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

@lanqy
lanqy / ReactCanvasDrawing.js
Created August 30, 2016 12:00 — forked from sebmarkbage/ReactCanvasDrawing.js
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
@lanqy
lanqy / ReduxMicroBoilerplate.js
Created August 27, 2016 04:12 — forked from gaearon/ReduxMicroBoilerplate.js
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@lanqy
lanqy / slim-redux.js
Created August 27, 2016 04:11 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {