Skip to content

Instantly share code, notes, and snippets.

View dengjonathan's full-sized avatar

Jon Deng dengjonathan

View GitHub Profile
@dengjonathan
dengjonathan / simulateMarbles.py
Created January 27, 2019 03:13
Python program simulating drawing marbles from a bag
import random
def takeMarble(isRed, bag):
color = 'red' if isRed else 'blue'
if isRed:
return ((bag[0] - 1, bag[1]), color)
else:
return ((bag[0], bag[1] - 1), color)
def pickMarble(bag):
# Scala FP Summary Notes
## What is a function?
In math, a function is a mapping from the set of possible inputs, the /domain/, to the set of possible outputs, the /codomain/.
This function maps from the set of possible inputs (the type `A`) to the set of possible outputs (the type `B`)
`A => B`
### Rules
* Every item in the domain must have a *single* deterministic mapping to an item in the co-domain
* However, not every item in the codomain has to have a mapping in the domain.
@dengjonathan
dengjonathan / flatMapAndMap.scala
Created October 28, 2018 19:18
Playing around to try to fully grok Scala map/ flatMap behavior
import scala.concurrent.{Await, Future, ExecutionContext}
import scala.util.Try
import ExecutionContext.Implicits.global
object rnn {
val seed = "5"
def fetch = Future {
Thread.sleep(100)
seed
@dengjonathan
dengjonathan / .babelrc
Last active May 1, 2018 20:36
Webpack/ Babel/ Express Env for React
{
"plugins": ["react-hot-loader/babel"],
"ignore":[]
}
@dengjonathan
dengjonathan / djikstra.js
Created February 27, 2018 04:12
djiksta's algorithm
const problem = {
start: {A: 5, B: 2},
A: {start: 1, C: 4, D: 2},
B: {A: 8, D: 7},
C: {D: 6, finish: 3},
D: {finish: 1},
finish: {}
};
const getMin = (queue, distances) => {
@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 / app.js
Created October 12, 2016 03:00
App.js file to instantiate a server and allow hot module reloading
const Server = require('./server.js')
const port = (process.env.PORT || 8080)
const app = Server.app()
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const config = require('../webpack.deployment.config.js')
const compiler = webpack(config)
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / index.js
Last active February 20, 2017 10:26
minimal express.js server
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.use("/styles", express.static(__dirname));
app.use("/images", express.static(__dirname + '/images'));
app.use("/scripts", express.static(__dirname + '/scripts'));
// viewed at based directory http://localhost:8080/
@dengjonathan
dengjonathan / jobSearchDP.js
Created February 16, 2017 19:14
job search DP
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**