Skip to content

Instantly share code, notes, and snippets.

View jtulk's full-sized avatar

Justin Tulk jtulk

  • El Paso, Texas
View GitHub Profile
@jtulk
jtulk / StaticContainer.js
Created June 3, 2017 05:38
The basics for delivering HTML content to a React component from a Node/Express Server
// a React Component that includes the header and footer
import React from "react";
import Header from "./../components/Header";
import Footer from "./../components/Footer";
import StaticContent from "./../components/StaticContent";
// use the route name from React Router to request the right data
const StaticContainer = ({ route }) => (
<div>
@jtulk
jtulk / webpack.config.server.js
Created May 30, 2017 17:48
Webpack Server Config
// stashing a webpack config for transforming ES6 Code for Node
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
module.exports = function(env) {
return {
entry: ["babel-polyfill", path.join(__dirname, "..", "server", "app.js")],
output: {
@jtulk
jtulk / package.json
Created March 29, 2017 15:37
Configuration for Babel-Loader Error When Specifying --env
{
"scripts": {
"build:prod": "webpack --env=prod --colors --profile --json > prod.stats.json",
"build:staging": "webpack --env=dev --colors --profile --json > staging.stats.json",
"start": "webpack-dev-server --env=dev --open --watch --progress",
}
}
@jtulk
jtulk / index.js
Created December 29, 2016 17:56
A more efficient reducer for adding/editing/removing objects in an array using a hash table
const initialState = {
byId: ['1', '2', '3'],
byHash: {
'1': {id: '1', content: {title: 'item 1'}},
'2': {id: '2', content: {title: 'item 2'}},
'3': {id: '3', content: {title: 'item 3'}}
}
}
const action1 = {
@jtulk
jtulk / index.js
Last active January 11, 2019 03:50
An inefficient reducer pattern for updating an array of objects
const initialState = [
{id: '1', content: {title: 'item 1'}},
{id: '2', content: {title: 'item 2'}},
{id: '3', content: {title: 'item 3'}}
]
const action = {
type: 'update',
id: '2',
payload: { content: {title: 'item 2 updated' }}
@jtulk
jtulk / GITFLOW.md
Created December 21, 2016 05:50
A markdown styled explanation of basic GitFlow tasks for inclusion in a project's README.md

Git Strategy

We currently use Gitflow. Any features to the repository should be started as branches coming off the Development branch and be prefixed with feature/ (or an appropriate semantic prefix for commits that don't technically constitute a true 'feature', e.g. 'refactor/[refactor-description]' etc...). Any patches for production should be applied directly to Master AND Development and be prefixed with hotfix/. All branches should be associated with a pull request for merging back into Development or Master branches. For non-trivial commits (or in general), having someone else approve your pull request is preferred.

Workflow for new feature branch

  • Start on Development branch (git checkout development)
  • Pull recent changes (git pull)
  • Create new branch (git checkout -b feature/[feature-name])
  • Add changes (git status to see changes, git add . to add all changes)
  • Commit changes
// `num` now exists within the closure created by
// add, and will be available in any returned function
function add(num) {
// this returned function will wait for execution with an
// argument to be provided later
return function partial(otherNum){
// return the sum of the two arguments
return num + otherNum
function double(num){
return num + num
}
function square(num){
return num * num
}
const x = square(double(3))
function double(num){
return num + num
}
function square(num){
return num * num
}
const x = double(3)
>> 6
@jtulk
jtulk / curry.js
Last active October 8, 2016 20:21
function partial(fn, ...args){
return fn(...arg)
}
function basic(...args) {
// acts on any number of passed arguments
}
partial(basic, 2, 3, 4)