Skip to content

Instantly share code, notes, and snippets.

View jsteenkamp's full-sized avatar

Johan Steenkamp jsteenkamp

View GitHub Profile
@jsteenkamp
jsteenkamp / block-scope.js
Last active October 28, 2015 18:35
JavaScript and DOM question
'use strict';
// Solution using ES6 block scope
var list = document.createElement('UL');
for (var i = 1; i <= 5; i++) {
var item = document.createElement('LI');
item.appendChild(document.createTextNode('Item ' + i));
@jsteenkamp
jsteenkamp / one-way-binding.js
Created November 3, 2015 20:28
Replace Angular 1.x two-way binding with one-way binding
/*
Using one-way data bindings may offer an easy way to make sure such reassignments don't happen by accident.
If the component indeed does reassign the value on purpose, an explicit output binding should be used instead
of piggybacking on the two-way input.
- Replace a two-way '=' binding on the directive configuration with an expression binding '&'.
- Change all accesses to the binding inside the component to function calls.
http://teropa.info/blog/2015/10/18/refactoring-angular-apps-to-components.html
@jsteenkamp
jsteenkamp / todo.js
Last active March 11, 2016 01:58
Commented EggHead Redux Example
// Reducers are prue functions that implement the update logic of the applications
// Reducers define how to calculate the next State from the current State and the dispatched Action
// Reducer function returns the current State if not Action is performed.
// Redux passes the new State to each component and React re-renders them.
// Reducers are typically called by Container components. Container components do not emit DOM (so they
// do not have any associated CSS)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
@jsteenkamp
jsteenkamp / readFromAmazonS3.cfm
Last active May 27, 2016 20:55
Replacement for ColdFusion <cffile.../> to upload and read (acl = public-read) to/from Amazon S3
<cffunction name="readFromAmazonS3">
<cfargument name="fileName" required="true"/>
<cfargument name="bucket" default="mybucket"/>
<cfhttp method="GET" url="http://s3.amazonaws.com/#arguments.bucket#/#arguments.fileName#" timeout="300" result="result"></cfhttp>
<cfreturn result.filecontent/>
</cffunction>
@jsteenkamp
jsteenkamp / index.js
Created June 14, 2016 01:17
React Stand Alone component with config
// only entry point for CSS processed via webpack
import '../styles/main.scss';
import React from 'react';
import { render } from 'react-dom';
import { browserHistory } from 'react-router';
import configureStore from './store';
import root, { Root } from './root';
const store = configureStore(root.rootInitialState);
@jsteenkamp
jsteenkamp / elevations.js
Created June 22, 2018 22:27
Google Material Design Elevations
// Google Material Design 1-24dp elevations (shadows)
// https://github.com/material-components/material-components-web/blob/master/packages/mdc-elevation/_variables.scss
const umbraOpacity = '0.2';
const penumbraOpacity = '0.14';
const ambientOpacity = '0.12';
// map index are [0-24]
const elevationUmbraMap = [
@jsteenkamp
jsteenkamp / foo.js
Last active August 27, 2018 19:35 — forked from ryanflorence/foo.js
Animation/transition using react spring
// Adds a lovely fade in of the modal
// and a gentle slide-down of the modal content
class Demo extends React.Component {
state = { showDialog: false };
render() {
return (
<div>
<button onClick={() => this.setState({ showDialog: true })}>
Show Dialog
</button>
@jsteenkamp
jsteenkamp / README.md
Created September 4, 2018 19:59
Simple queue using async/await

Queue using async/await

Implement a queue using async/await.

I created a single instance, easy enough to convert to a factory if you want multiple queues or add features like timeout with configuration object.

Although this solution is simple and does not require any additional libraries I do not think it is robust. For example retries after errors or timeouts is not supported. Rather than solve these issues it makes more sense to look at proven solutions such as message/task queues.

Usage

@jsteenkamp
jsteenkamp / ladder.md
Created November 11, 2018 18:05 — forked from jamtur01/ladder.md
Kickstarter Engineering Ladder