Skip to content

Instantly share code, notes, and snippets.

@moog16
moog16 / Root.js
Created March 9, 2017 04:22
RootContainer for new hot loader syntax
import React from 'react';
import { Router, Route, IndexRedirect, browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { AppContainer } from './components/App';
import { RandomContainer } from './components/Random';
export default React.createClass({
history: null,
_routes: null,
function knapsack(vals, wts, maxWeight) {
var maxValFound = 0;
function maxVal(vals, wts, currentVal, currentWeight) {
for(var i=0; i<vals.length; i++) {
var addVal = vals[i];
var addWeight = wts[i];
if(currentWeight + addWeight > maxWeight) {
continue;
@moog16
moog16 / classDeclaration.js
Last active October 11, 2017 19:14
[UPGRADE] ES6 Classes
// before
export default React.createClass({ …. });
// after
export default class extends React.Component { … }
const processResponseBody = async (response) => {
let result = '';
if (!response || !response.body) {
return;
}
const reader = response.body.getReader();
return new Promise((resolve) => {
reader.read().then(function processText({ done, value }) {
// Result objects contain two properties:
const renderConditionCards = () => {
const renderedConditions = isMobileBreakpoint
? conditions[0]
: conditions.slice(0, 4);
return renderedConditions.map((condition, i) => {
const percentageProbability = getPercentageText(condition.probability);
const isTopCondition = i === 0;
const isSecondCondition = i === 1;
const lastIteration = i === renderedConditions.length - 1;
const shouldRenderAccordion =