Skip to content

Instantly share code, notes, and snippets.

@duncan60
duncan60 / redux demo js
Last active January 7, 2016 11:06
redux practice
//https://egghead.io/lessons/javascript-redux-the-single-immutable-state-tree
//redux
const createStore = (reducer, initialState) => {
let state = initialState;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
@duncan60
duncan60 / example 1
Last active December 22, 2015 06:54
es7 immutable
let NBA = {
season : {
year : '2017',
start: '2016-10',
end : '2017-6',
state: 'active'
},
players: [
{
name : 'duncan',
@duncan60
duncan60 / monad example
Last active June 12, 2017 10:20
functional programming
let add = (val, fun) => fun(val + 3);
let multiplication = (val) => val * 3;
console.log(add(2, multiplication));
//--------------------------------
let test = {
a: 10,
b: 20,
c: 30
};
@duncan60
duncan60 / example 1
Created January 2, 2016 10:28
pure function
let player = {
name : '',
state : '',
level : '',
height: 0,
age : 0,
point : 0
};
//impure
// createStore
const createStore = (reducer) => {
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
};
var Webpack = require('webpack'),
path = require('path'),
util = require('util'),
pkg = require('./package.json'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin');
var nodeModulesPath = path.resolve(__dirname, 'node_modules'),
buildPath = path.resolve(__dirname, 'dist'),
mainPath = path.resolve(__dirname, 'src', 'app', 'app.js'),
@duncan60
duncan60 / 0_reuse_code.js
Created April 27, 2016 02:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@duncan60
duncan60 / Dockerfile
Last active May 22, 2016 15:06
docker run
# python 2
# Flask-RESTful & pymssql
FROM python:2-onbuild
MAINTAINER duncan60 <tmduncan60@gmail.com>
RUN apt-get update \
&& apt-get install freetds-dev \
&& pip install Flask \
&& pip install Flask-SQLAlchemy \
@duncan60
duncan60 / README.md
Created June 28, 2016 07:38 — forked from jonathantneal/README.md
createElement.js // a 300 byte DOM Element creator

createElement.js

createElement.js lets document.createElement use CSS selectors.

This is a pretty useful library for building out DOM elements. The whole thing runs on one regex and a for loop, so it’s plenty fast. The script is 300 bytes when compressed and gzipped. For 524 bytes (advanced), it includes nesting support and can generate entire DOM hierarchies, including text nodes.

Usage

document.createElement(); // generates <div />
#判断是否是Array
function isArray(data) {
return Array.isArray ? Array.isArray(data) : Object.prototype.toString.call(data) === '[object Array]';
}
#判断是否是 empty object {}
var isEmpty = function ua(data) {
if (Object.keys)
return Object.keys(data).length === 0;
for (var wa in data)