Skip to content

Instantly share code, notes, and snippets.

View ColeTownsend's full-sized avatar

Cole Townsend ColeTownsend

View GitHub Profile
@ColeTownsend
ColeTownsend / index.ts
Last active August 14, 2019 23:43
Handling errors with promises
// 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) {
res.json(result);
@ColeTownsend
ColeTownsend / RichTextImage.js
Created February 12, 2019 23:08
Gatsby Image Lookup for Rich Text
import React from 'react'
import { StaticQuery, graphql } from 'gatsby'
import Img from 'gatsby-image'
export default class RichTextImage extends React.Component {
render() {
return (
<StaticQuery
query={graphql`
query {
@ColeTownsend
ColeTownsend / index.html
Last active November 27, 2018 20:30
The Micro Stripe demo front end.
<!DOCTYPE html>
<html>
<head>
<title>Micro Stripe Checkout</title>
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<script src="https://js.stripe.com/v3/"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<style>
* {
@ColeTownsend
ColeTownsend / post.js
Last active April 23, 2017 18:24
Post module for Micro Stripe API
require('dotenv').config(); // we need our dotenv stuff
// https://github.com/romuloalves/micro-post/blob/master/src/index.js
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
ColeTownsend / index.js
Created April 22, 2017 01:16
For Micro Stripe Demo
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) {
import Post from './post'; // coming soon, don't worry
export default function({ className, data }) {
return (
<div className={className}>
{data.map(post => (
<Post key={post.id} post={post} />
))
}
</div>
);
@ColeTownsend
ColeTownsend / Index.js
Last active April 6, 2017 02:09
Index.js
import React from 'react';
import 'isomorphic-fetch';
import Feed from './components/Feed';
const postEndpoint = `http://twnsndco.dropmark.com/396720.json`;
export default class Index extends React.Component {
static async getInitialProps () {
const response = await fetch(postEndpoint);
const json = await response.json();
@ColeTownsend
ColeTownsend / Post.js
Last active April 1, 2017 20:42
The Post component
import React, { PropTypes } from 'react';
import moment from 'moment';
export default class Post extends React.Component {
constructor (props) {
super(props);
}
render () {
const {
#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