Skip to content

Instantly share code, notes, and snippets.


Cole Townsend ColeTownsend

View GitHub Profile
ColeTownsend / index.ts
Last active Aug 14, 2019
Handling errors with promises
View index.ts
// how do I get an error handler function involved here?
Routes.forEach(route => {
(app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {
const result = (new (route.controller as any))[route.action](req, res, next);
if (result instanceof Promise) {
result.then(result => result !== null && result !== undefined ? res.send(result) : undefined);
} else if (result !== null && result !== undefined) {
ColeTownsend / RichTextImage.js
Created Feb 12, 2019
Gatsby Image Lookup for Rich Text
View RichTextImage.js
import React from 'react'
import { StaticQuery, graphql } from 'gatsby'
import Img from 'gatsby-image'
export default class RichTextImage extends React.Component {
render() {
return (
query {
ColeTownsend / index.html
Last active Nov 27, 2018
The Micro Stripe demo front end.
View index.html
<!DOCTYPE html>
<title>Micro Stripe Checkout</title>
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<script src=""></script>
<script src=""></script>
* {
ColeTownsend / post.js
Last active Apr 23, 2017
Post module for Micro Stripe API
View post.js
require('dotenv').config(); // we need our dotenv stuff
module.exports = exports = function (fn) {
return (req, res) => {
res.setHeader('Access-Control-Request-Method', 'POST, GET')
res.setHeader("Access-Control-Allow-Credentials", "true");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
// set this with your own URL
res.setHeader('Access-Control-Allow-Origin', process.env.STRIPE_ALLOW_DOMAIN);
ColeTownsend / index.js
Created Apr 22, 2017
For Micro Stripe Demo
View index.js
require('dotenv').config(); // we need our dotenv stuff
const {send, json} = require('micro');
const post = require('./post'); // we'll make this soon don't worry.
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); // this is our stripe key! use your testing key for now.
module.exports = post(async (req, res) => {
const data = await json(req);
stripe.charges.create(data, (err, resp) => {
if (err) {
View Feed.js
import Post from './post'; // coming soon, don't worry
export default function({ className, data }) {
return (
<div className={className}>
{ => (
<Post key={} post={post} />
View Index.js
import React from 'react';
import 'isomorphic-fetch';
import Feed from './components/Feed';
const postEndpoint = ``;
export default class Index extends React.Component {
static async getInitialProps () {
const response = await fetch(postEndpoint);
const json = await response.json();
ColeTownsend / Post.js
Last active Apr 1, 2017
The Post component
View Post.js
import React, { PropTypes } from 'react';
import moment from 'moment';
export default class Post extends React.Component {
constructor (props) {
render () {
const {
View gist:510848f7e89120f1fbba26bf5b4428d5
#include <iostream>
using namespace std;
struct StudentType
string name;
int score;
char grade;

macOS 10.12 Sierra Setup

Custom recipe to get macOS 10.12 Sierra running from scratch, setup applications and developer environment. This is very similar (and currently mostly the same) as my 10.11 El Capitan setup recipe and 10.10 Yosemite setup recipe. I am currently tweaking this for 10.12 Sierra and expect to refine this gist over the next few weeks.

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. I generally reinstall each computer from scratch every 6 months, and I do not perform upgrades between releases.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your o