Skip to content

Instantly share code, notes, and snippets.

@mrcoles
mrcoles / pause-gifs.css
Created February 15, 2018 18:22
A lightweight approach to pausing gifs on a webpage.
/** .pause-gif */
.wrap-pause-gif {
position: relative;
text-align: center;
}
.pause-gif {
visibility: hidden;
}
@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 / make-axios-request-config.ts
Created April 8, 2020 14:55
An example of making an AxiosRequestConfig object to do a multipart/form-data request
import axios, {
AxiosRequestConfig,
Method,
} from 'axios';
export const makeAxiosRequestConfig = (
method: Method,
path: string,
data?: { [key: string]: any },
@mrcoles
mrcoles / fill-mixed-text.js
Last active February 14, 2023 13:15
A simple function for writing mixed color and/or font text on an HTML5 Canvas object.
// # HTML5 Canvas: Fill Mixed Text
//
// ctx: CanvasRenderingContext2D
// args: array of objects of form
// { text: string, fillStyle?: string, font?: string }
// x: number
// y: number
//
const fillMixedText = (ctx, args, x, y) => {
let defaultFillStyle = ctx.fillStyle;
@mrcoles
mrcoles / make_imgs.py
Created January 17, 2018 22:16
Convert the MNIST CSV dataset from Kaggle to png images
#!/usr/bin/env python3
import csv
import os
import pathlib
import imageio
import numpy as np
@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
@mrcoles
mrcoles / replace_words.js
Last active February 25, 2022 05:41
Replace all instances of one word with another in a web page
// ### Replace words in document
//
// Update all instances of `fromWord` to `toWord` within the text
// in the current document.
//
function replaceWordsInDocument(fromWord, toWord) {
if (/\s/.test(fromWord)) {
throw new Error('You must enter a single word without whitespace');
}
@mrcoles
mrcoles / airtable_escape.py
Last active December 26, 2021 19:24
A helper function for escaping variables passed into formulas in the Airtable API
from typing import Any, Optional, Union
from decimal import Decimal
class AirtableBadTypeException(Exception):
def __init__(self, val: Any):
self.val = val
super().__init__(f"unexpected type variable type: {type(val)}")
@mrcoles
mrcoles / use-intersection-observer.ts
Last active December 20, 2021 06:05
A simple hook for running an IntersectionObserver inside a React FunctionComponent
import { useEffect, useRef } from 'react';
export type OnIntersect = (elt: HTMLElement) => void;
/**
* Hook for running an IntersectionObserver.
* @param onIntersect this is used in the deps of useEffect, you can
* employ useCallback to prevent it from running
* after every render
* @param args
@mrcoles
mrcoles / dynamodb-auto-paginate-scan.ts
Last active March 29, 2021 02:20
Snippet for doing auto-pagination of a DynamoDB scan with an async generator in NodeJS
import { DocumentClient } from "aws-sdk/lib/dynamodb/document_client";
export async function* autoPaginateScan<I extends DocumentClient.AttributeMap>(
docClient: DocumentClient,
params: DocumentClient.ScanInput
) {
while (true) {
const data = await docClient.scan(params).promise();
if (data.Items && data.Items.length) {