Skip to content

Instantly share code, notes, and snippets.

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 =
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:
@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 { … }
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 / 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,
@moog16
moog16 / gulp.watch.js
Last active March 8, 2017 08:09
Gulp watch tasks for styles
// I run this right after webpack-dev-server task is complete
gulp.task('watch', () => {
gulp.watch('./styles/**/*.scss', ['watchCss']);
});
// this triggers whenever a `.scss` file changes
// which triggers a new scss compliation
gulp.task('watchCss', ['buildStyles'], () => {
// browserSyncInstance is defined in my above gist
// https://gist.github.com/moog16/095f6e6e592ae83c0182e0977c8a8762
@moog16
moog16 / webpack.config.js
Created March 8, 2017 08:03
Webpack config for bundling javascript files
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
// args.getArgs is a custom function that I wrote for yarn
const args = require('./build/utils/args');
// ENV Variables
const client = args.getArg('client') || 'default';
const stubs = args.getArg('stubs');
const PORT = 8080;
@moog16
moog16 / gulp.styles.js
Created March 8, 2017 08:03
gulpfile tasks for compiling styles
const gulp = require('gulp');
const sass = require('gulp-sass');
const path = require('path');
const gutil = require("gulp-util");
// custom importer for scss files that resolve file names in
// main app.scss manifest
const importer = require('../scssImporter');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
@moog16
moog16 / gulp.dev.js
Created March 8, 2017 08:02
Gulp task for starting webpack-dev-server
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const browserSync = require('browser-sync');
// a nice npm module written to have BrowserSync work with Webpack
// and webpack-dev-server
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const renderTemplate = require('./build/gulp/template');
const clients = require('./build/gulp/clients')();
let browserSyncInstance;
const argv = require('yargs').argv;
const webpackConfig = {
colors: true,
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|jspm_packages)/,
loader: 'babel'
}, {