Skip to content

Instantly share code, notes, and snippets.

View dengjonathan's full-sized avatar

Jon Deng dengjonathan

View GitHub Profile
@dengjonathan
dengjonathan / naivePromise.js
Created January 27, 2017 16:25
Naive Promise implementation
// creates a promise object which will either resolve or reject
const Promise = function (executor) {
const _thens = [];
let _catch;
const promise = {
then: cb => {
_thens.push(cb);
return promise;
},
@dengjonathan
dengjonathan / avltree.js
Created January 16, 2017 19:27
Javascript AVL Tree
// AVLTree ///////////////////////////////////////////////////////////////////
// This file is originally from the Concentré XML project (version 0.2.1)
// Licensed under GPL and LGPL
//
// Modified by Jeremy Stephens.
// Pass in the attribute you want to use for comparing
function AVLTree(n, attr) {
this.init(n, attr);
}
const Server = require('./server.js');
const webpack = require('webpack');
let config;
const port = (process.env.PORT || 8080);
const app = Server.app();
if (process.env.NODE_ENV === 'development') {
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
{
"env": {
"node": true,
"es6": true
},
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParameters": true,
@dengjonathan
dengjonathan / Vue.html
Created December 9, 2016 23:54
Vue example by reader @thoragio
<div id="counter">
<button @click="up()">+</button>
<p id="count">{{ value }}</p>
<button @click="down()">-</button>
</div>
<script>
var counter = new Vue({
el: '#counter',
data: {
value: 0
<!DOCTYPE html>
<html>
<head>
<title>Vanilla JS MVC</title>
</head>
<body>
<div class="counter">
<button id="up">+</button>
<p id="count">0</p>
<button id="down">-</button>
@dengjonathan
dengjonathan / react.jsx
Created December 9, 2016 03:10
Counter React Example
// Counter.jsx
import React from 'react';
import ReactDOM from 'react-dom';
// PRESENTATIONAL COMPONENT: a simple stateless React View
const Button = ({onClick, label}) => (
<button onClick={onClick}>{label}</button>
);
// REACT COMPONENT: a stateful React View (stored in this.state)
@dengjonathan
dengjonathan / vanilladom.html
Last active December 9, 2016 03:18
Vanilla DOM
<!DOCTYPE html>
<html>
<head>
<title>Vanilla JS</title>
</head>
<body>
<div class="counter">
<button id="up">+</button>
<p id="count">0</p>
<button id="down">-</button>
@dengjonathan
dengjonathan / react-redux.jsx
Created December 8, 2016 23:03
React Redux
import React from 'react';
import ReactDOM from 'react-dom';
import {createStore} from 'redux';
import {connect, Provider} from 'react-redux';
/********************************REDUX*****************************************/
//default state
const INITIAL_STATE = {
value: 0
};
@dengjonathan
dengjonathan / react.jsx
Last active December 8, 2016 22:56
React MVC
import React from 'react';
import ReactDOM from 'react-dom';
import {createStore} from 'redux';
import {connect, Provider} from 'react-redux';
/********************************REDUX*****************************************/
//default state
const INITIAL_STATE = {
value: 0
};