Skip to content

Instantly share code, notes, and snippets.

Jon Deng dengjonathan

Block or report user

Report or block dengjonathan

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
@dengjonathan
dengjonathan / simulateMarbles.py
Created Jan 27, 2019
Python program simulating drawing marbles from a bag
View simulateMarbles.py
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):
View FP Scala Notes
# 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 Oct 28, 2018
Playing around to try to fully grok Scala map/ flatMap behavior
View flatMapAndMap.scala
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 / djikstra.js
Created Feb 27, 2018
djiksta's algorithm
View djikstra.js
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) => {
View jobSearchDP.js
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}
];
/**
View jobSearchLinear.js
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}
];
/**
View jobSearchBackTrack.js
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}
];
/**
View jobSearchLinear.js
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}
];
/**
View jobSearch.js
/*
You have a defined set of activities you can be doing during your job search
process. Each activity has a cost (time that it takes you to complete the activity)
and each activity provides some value (XP, or experience points,
that will increase your chances of finding a job).
Write a function that maximizes XP for a given input of time. Try to make your
solution as efficient as possible.
*/
@dengjonathan
dengjonathan / stopwatch.js
Created Feb 15, 2017
redux middleware example
View stopwatch.js
const redux = require('redux');
const reducer = (state={}, action) => {
switch(action.type) {
case 'START':
return Object.assign({}, state, {start: Date.now(), interval: action.interval});
case 'TICK':
return Object.assign({}, state, {elapsed: action.currentTime - state.start});
case 'STOP':
return Object.assign({}, state, {interval: null});
You can’t perform that action at this time.