Skip to content

Instantly share code, notes, and snippets.

@justinobney
justinobney / 01-util-service.js
Last active April 22, 2016 22:52
Memoize Promise
function UtilService($q, $timeout){
this.memoizePromise = memoizePromise;
function memoizePromise(fn, expire){
const calls = {};
const action = (...args) => {
var key = hash(args);
var found = calls[key];
@justinobney
justinobney / state_machine.js
Created April 14, 2016 20:58
playing with a simple state machine
function createState(props){
if(!props.name){
throw new Error('state name required');
}
const defaults = {
canEnter(toState, fromState, appState){ return true; },
onEnter(toState, fromState, appState){ console.log(`entering ${toState.name}`) },
canExit(fromState, toState, appState){ return true; },
onExit(fromState, toState, appState){ console.log(`exiting ${fromState.name}`) }
/*
pesticide v1.3.0 . @mrmrs . MIT
*/
body {
outline: 1px dotted #2980b9 !important; }
article {
outline: 1px dotted #3498db !important; }
nav {
const times = (times, fillFn) =>
'_'.repeat(times)
.split('')
.map((val, idx) => fillFn(idx))

Learn React (or other libs)

Let's get together and build a component in React each week. We can then check out each other's solutions to the challenge and hopefully get better at this development thing. While my goal is to get better at React, other libraries are also welcome. There is so much out there we can learn from.

This is not meant to be a tutorial. There are TONS of those for react already on the web. We are going to start with very simple components and work into more complex scenarios.

const identity = x=>x;
/**
* Reducing Function - Turns an array of values into a single value
* n => 1
* @param {array} array - The values to reduce into a single value.
* @param {callback} aggregatingFunction - called for each item in the array
* - given:
* - aggregatedValue
* - currentArrayItem
@justinobney
justinobney / .babelrc
Last active December 31, 2015 00:40
basic react component
{
"presets": [
"es2015",
"stage-2",
"react"
]
}
// npm i mkdirp node-fetch minimist
var path = require('path');
var fs = require('fs');
var fetch = require('node-fetch');
var mkdirp = require('mkdirp');
var argDefaults = {
dir:'test',
template: 'module'
}
@justinobney
justinobney / .babelrc
Last active January 7, 2016 14:43
Test setup
{
"presets": [
"es2015",
"stage-2"
]
}
function onSuccess(){
$('form').attr('action', 'foo');
}
function makeEquation(successCallback){
var words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
var left = Math.floor(Math.random() * 10 + 1);
var right = Math.floor(Math.random() * 10 + 1);
var question = words[left-1] + ' + ' + words[right-1] + ' = ? (example: one + two = 3)';
return {