Skip to content

Instantly share code, notes, and snippets.

Peter Coles mrcoles

Block or report user

Report or block mrcoles

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mrcoles
mrcoles / parcel-local-proxy.js
Last active Dec 4, 2019
A simple proxy script for controlling URL rewriting when running Parcel with multiple entry points (including https support)
View parcel-local-proxy.js
const chalk = require('chalk');
const fs = require('fs');
const http = require('http');
const https = require('https');
const yargs = require('yargs');
// Configuration
const DEFAULT_PARCEL_PORT = 4321;
@mrcoles
mrcoles / aws-amplify-build-settings-cache-static-files.yml
Last active Oct 19, 2019
Sample file caching custom headers to add to an AWS Amplify build-settings.yml file
View aws-amplify-build-settings-cache-static-files.yml
frontend:
customHeaders:
# cache static assets! (can I just use a glob for this, e.g., '**/*.{js,css,gif,ico,jpg,png,svg,mp4,webm}' ?)
# js
- pattern: '**/*.js'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# css
- pattern: '**/*.css'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# images
@mrcoles
mrcoles / Plural.tsx
Created Jul 26, 2019
A simple React component for handling pluralization of a word.
View Plural.tsx
import React from 'react';
export const Plural = ({
num,
text,
pluralText,
pluralSuffix,
singularSuffix
}: {
num: number;
@mrcoles
mrcoles / clean-amplify-s3-builds.js
Created Jun 25, 2019
A script for deleting old amplify builds in s3 and keeping the 5 most recent ones.
View clean-amplify-s3-builds.js
const AWS = require('aws-sdk');
const PREFIX = 'amplify-builds/';
const DEFAULT_KEEP_N = 5;
const DEFAULT_DRY_RUN = false;
const s3 = new AWS.S3();
// ## Main
@mrcoles
mrcoles / csv-script.py
Last active May 15, 2019
Simple template for a python script that uses argparse and reads in and prints out a CSV or TSV
View csv-script.py
import csv
def run(infile, outfile, is_tsv=False, dry_run=False):
dialect = 'excel-tab' if is_tsv else 'excel'
reader = csv.DictReader(infile, dialect=dialect)
writer = None
is_first = True
for row in reader:
@mrcoles
mrcoles / crop-video.sh
Created Apr 5, 2019
Script for cropping iPhone X screen recordings with ffmpeg
View crop-video.sh
#!/usr/bin/env bash
DIMS_SHORT="886:1576:0:104"
DIMS_TALL="886:1816:0:104"
INFILE=
OUTFILE=
DIMS="$DIMS_TALL"
print_usage() {
@mrcoles
mrcoles / aws-cognito-hosted-ui-amplify-setup.md
Last active May 13, 2019
The steps I followed to setup AWS Cognito for a React AWS Amplify project using the hosted UI with sign in/sign up by email and also social sign in
View aws-cognito-hosted-ui-amplify-setup.md

Steps to setup the AWS Cognito hosted UI with email sign up/sign in for a React AWS Amplify Project

This was done using the amplify cli v0.2.2-multienv.1.

The goal was to:

  1. Create an auth setup for my React AWS Amplify project
  2. Use email as the sign up/sign in id and make sure it's unique
  3. Offer social sign in with Facebook and Google (and have those users also end up in the Cognito user pool—this appeared to only be possible using the hosted UI)
@mrcoles
mrcoles / LoaderDots.jsx
Last active Mar 13, 2019
LoaderDots.jsx: a React loader component (to show when waiting on a network call)
View LoaderDots.jsx
import React from 'react';
export default ({
fill = '#666666',
width = 52,
height = 12,
scale = 1,
style = {}
}) => (
<svg
@mrcoles
mrcoles / extract-props.d.ts
Created Mar 6, 2019
A simple function to split up a props object into specified `customProps` that match `keys` and the remaining `spreadProps`
View extract-props.d.ts
declare module "extract-props" {
export interface ExtractedProps {
spreadProps: object;
customProps: object;
}
export default function extractProps(props: object, keys: string[]): ExtractedProps;
}
@mrcoles
mrcoles / compress-video.sh
Last active Apr 5, 2019
Script for compressing a video to .mp4 and .webm with ffmpeg
View compress-video.sh
#!/usr/bin/env bash
# inspired by: https://gist.github.com/Vestride/278e13915894821e1d6f
INPUT=$1
OUTDIR="out/"
if [ -z "$INPUT" ]; then
echo "No file specified"
exit 1
You can’t perform that action at this time.