Skip to content

Instantly share code, notes, and snippets.

View bradwestfall's full-sized avatar

Brad Westfall bradwestfall

View GitHub Profile
import React, { useState, useRef } from 'react'
import ReactDOM from 'react-dom'
/**
* 1. Start by creating some state to store an array of items
* where you have the array holding objects as shown below
* 2. Eventually, your array will start empty, but for now it might
* make sense to have that array already populated with an item
* or two so that way we can show them in the `<ul>`. So do that
* and then iterate over the `items` array in the JSX and make
@bradwestfall
bradwestfall / HoC-vs-RenderProps-vs-Hooks.md
Last active April 14, 2024 15:54
An explanation of why Hooks are a nicer way to abstract re-useable state and functionality vs HoC's and Render Props

HoC (pattern) vs Render Props (pattern) vs Hooks (not pattern, a new API)

Someone was asking me about comparing the HoC and Render Props patterns (and their shortcomings) to hooks. I might leave this up as a public gist for others if it's helpful.


tldr;

Issues with HoC:

@bradwestfall
bradwestfall / docker.sh
Last active January 15, 2018 18:50
Docker Cheat Sheet
# Build a container from a local Dockerfile
# 1. -t is the tagname
# 2. The appname is any name we want to distinguish containers
# 3. . the path to Dockerfile
docker build -t <appname> .
# List Images
docker images
# Remove an Image
@bradwestfall
bradwestfall / S3-Static-Sites.md
Last active April 10, 2024 16:40
Use S3 and CloudFront to host Static Single Page Apps (SPAs) with HTTPs and www-redirects. Also covers deployments.

S3 Static Sites

⚠ This post is fairly old. I don't keep it up to date. Be sure to see comments where some people have posted updates

What this will cover

  • Host a static website at S3
  • Redirect www.website.com to website.com
  • Website can be an SPA (requiring all requests to return index.html)
  • Free AWS SSL certs
  • Deployment with CDN invalidation

It seems as though some people like me are experiencing a weird thing when upgrading mac these days, the RSA keys still work for connecting to things like GitHub but my keychain doesn't want to remember the password and is annoyingly asking me for it with every git push.

The solution I found that works is at http://stackoverflow.com/a/41576222

Basically, edit my ~/.ssh/config file to be:

Host *
    UseKeychain yes
sudo npm uninstall npm -g
brew uninstall node

Then

sudo rm -rf /usr/local/lib/dtrace/node.d /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/nodemon /usr/local/bin/node /usr/local/include/node ~/.npm* ~/.node* /usr/local/share/man/*/node* /usr/local/share/man/*/npm*

Bump Semver - https://docs.npmjs.com/cli/version

# One of these
npm version patch -m 'Git commit message'
npm version minor -m 'Git commit message'
npm version major -m 'Git commit message'

Push to GitHub

@bradwestfall
bradwestfall / gist:c3e44d5c1e4a74ad852e
Last active August 25, 2017 16:35
OS X (Yosemite) Apache Environment Setup

OS X (Yosemite) Apache Environment Setup

Instructions for setting up a basic Apache environment on OS X Yosemite Only. For Mavericks, view this guide

For this guide, square brackets are used to denote places where you need to plugin your own stuff. In none of these cases are you supposed to use actual square brackets.

Note that /private/etc and /etc go to the same place on Yosemite. This is good to know for later.

If you've already configured Apache correctly and you just want to know the part about setting up a new Virtual Host, then you can skip to that section. If not, then you'll need to configure Apache.

@bradwestfall
bradwestfall / gist:f5a010e96fb0c4d18556
Last active November 20, 2022 14:40
Pull Instagram Images via JavaScript

Ubuntu IP Tables (Firewall)

When setting up an Ubuntu server, you'll want to establish basic security including a firewall to only allow certain types of requests, and to allow only certain types of responses. This code will:

  • Flush your current firewall
  • Because it's our server and we're not hosting other people's stuff (like a shared server), we'll allow all output
  • Allow input requests for SSH, Port 80 and 443 (Web and TLS (SSL))
  • Log bad requests with the prefix "iptables denied:"
  • Then save these rules to a file called /etc/iptables.up.rules