Skip to content

Instantly share code, notes, and snippets.

View ColeTownsend's full-sized avatar

Cole Townsend ColeTownsend

View GitHub Profile
@ColeTownsend
ColeTownsend / README.md
Last active November 6, 2024 16:07
Export Cloudflare Bulk Redirect List to CSV

Copy and paste this on your list page after you log in.

@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;
};