Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Lan Qingyong lanqy

🎯
Focusing
Block or report user

Report or block lanqy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lanqy
lanqy / args.ml
Created Oct 15, 2017 — forked from ghulette/args.ml
Labeled and optional arguments in OCaml, by example
View args.ml
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 Jul 4, 2017 — forked from martinsik/chat-frontend.js
Node.js chat frontend and server
View chat-frontend.js
$(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 — forked from straker/two-way-binding.js
Simple and small two-way data binding between DOM and data
View two-way-binding.js
/**
* @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 Jan 23, 2017 — forked from paul-delange/GIFDownloader.h
Convert remote GIF into something MPMoviePlayerController can use
View GIFDownloader.h
//
// GIFDownloader.h
// TheJoysOfCode
//
// Created by Bob on 29/10/12.
// Copyright (c) 2012 Tall Developments. All rights reserved.
//
#import <Foundation/Foundation.h>
View browserify_for_webpack_users.markdown

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

View 0virtual-dom.md

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.

View ReactCanvasDrawing.js
/** @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 Aug 27, 2016 — forked from gaearon/ReduxMicroBoilerplate.js
Super minimal React + Redux app
View ReduxMicroBoilerplate.js
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 Aug 27, 2016 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
View slim-redux.js
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])) {
@lanqy
lanqy / index.js
Created Aug 27, 2016 — forked from gaearon/index.js
Breaking out of Redux paradigm to isolate apps
View index.js
import React, { Component } from 'react'
import Subapp from './subapp/Root'
class BigApp extends Component {
render() {
return (
<div>
<Subapp />
<Subapp />
<Subapp />
You can’t perform that action at this time.