Skip to content

Instantly share code, notes, and snippets.

@max-barry
max-barry / function-dynamic-resize-simple.ts
Last active April 29, 2021 16:47
Dynamic Firestore Image Resizing Function > Simple #1
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import * as sharp from "sharp";
// Just a list of all of the formats supported by Sharp
const SHARP_FORMATS = Object.values(sharp.format);
export const dynamicImages = functions.https.onRequest(async (request, response) => {
// From the URL we want to get our passed parameters
@max-barry
max-barry / function-dynamic-resize-complete.ts
Last active July 13, 2024 20:29
Dynamic Firestore Image Resizing Function > Complete #2
import * as path from "path";
import * as zlib from "zlib";
import { PassThrough } from "stream";
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import * as log from "firebase-functions/lib/logger";
import * as sharp from "sharp";
import { empty } from "ramda";
@max-barry
max-barry / module-registry.ts
Last active May 25, 2021 11:53
Lazy load a module using a React hook, with Typescript safety
import React, { useContext, useEffect, useRef, useState } from "react";
// Types
type Import<M> = () => Promise<M>;
/**
* Using a single hook without context.
* This is shorter but relies on the browser/webpack cache.
*
* @example