Skip to content

Instantly share code, notes, and snippets.

@mrcoles
mrcoles / parcel-local-proxy.js
Last active December 4, 2019 12:40
A simple proxy script for controlling URL rewriting when running Parcel with multiple entry points (including https support)
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 March 9, 2021 11:43
Sample file caching custom headers to add to an AWS Amplify build-settings.yml file
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 July 26, 2019 18:51
A simple React component for handling pluralization of a word.
import React from 'react';
export const Plural = ({
num,
text,
pluralText,
pluralSuffix,
singularSuffix
}: {
num: number;
@mrcoles
mrcoles / clean-amplify-s3-builds.js
Created June 25, 2019 22:58
A script for deleting old amplify builds in s3 and keeping the 5 most recent ones.
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 21:37
Simple template for a python script that uses argparse and reads in and prints out a CSV or TSV
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 April 5, 2019 01:34
Script for cropping iPhone X screen recordings with ffmpeg
#!/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 March 13, 2023 11:42
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

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 March 13, 2019 03:38
LoaderDots.jsx: a React loader component (to show when waiting on a network call)
import React from 'react';
export default ({
fill = '#666666',
width = 52,
height = 12,
scale = 1,
style = {}
}) => (
<svg
@mrcoles
mrcoles / extract-props.d.ts
Created March 6, 2019 16:13
A simple function to split up a props object into specified `customProps` that match `keys` and the remaining `spreadProps`
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 September 15, 2022 12:15
Script for compressing a video to .mp4 and .webm with ffmpeg
#!/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