Skip to content

Instantly share code, notes, and snippets.

View aaronccasanova's full-sized avatar

Aaron Casanova aaronccasanova

View GitHub Profile
@aaronccasanova
aaronccasanova / glob-alt.mjs
Last active February 20, 2022 23:03
You might not need `globby`
const files = await findFiles('/Users/aaronccasanova/projects', 'css')
console.log('files:', files)
/**
* Wraps the `find` command to recursively search for files of a given type.
* @param {string} path - Target directory to search
* @param {string} ext - File extension to search
* @returns {string[]} - Paths to all matching files
*
@aaronccasanova
aaronccasanova / cloud-run-deploy.yml
Last active November 14, 2021 03:18
Continuous Deployment GitHub Action template for the Nextjs GCP GitHub Action repository
# Adapted from: https://github.com/google-github-actions/deploy-cloudrun/blob/main/.github/workflows/example-workflow.yaml
name: Build and Deploy to Cloud Run
on:
push:
branches:
- main
env:
@aaronccasanova
aaronccasanova / .dockerignore
Created November 13, 2021 21:53
.dockerignore template for the Nextjs GCP GitHub Action repository
Dockerfile
.dockerignore
node_modules
npm-debug.log
@aaronccasanova
aaronccasanova / Dockerfile
Last active November 14, 2021 19:00
Dockerfile template for the Nextjs GCP GitHub Action repository
## Adapted from the following articles:
#- https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
#- https://medium.com/weekly-webtips/this-is-how-i-deploy-next-js-into-google-cloud-run-with-github-actions-1d7d2de9d203
# Base image.
FROM node:14-alpine
# Create and change to the app directory.
WORKDIR /usr/app
@aaronccasanova
aaronccasanova / useCopyToClipboard.md
Last active December 24, 2022 07:39
useCopyToClipboard.ts

Implementation:

import React from 'react'

type Status = 'idle' | 'resolved' | 'rejected'

/**
 * Copy text to the native clipboard using the `navigator.clipboard` API
 * Adapted from https://www.benmvp.com/blog/copy-to-clipboard-react-custom-hook/
@aaronccasanova
aaronccasanova / makeStore.ts.md
Last active August 30, 2021 02:54
How to bootstrap a performant React context store (TypeScript)

React Store Creator (Performance considerations included)

// makeStore.tsx
export function makeStore<R extends React.Reducer<any, any>, I>(
  reducer: R,
  initialState: I & React.ReducerState<R>,
  // initializer?: (arg: I & React.ReducerState<R>) => React.ReducerState<R>,
) {
  const DispatchContext = React.createContext<null | React.Dispatch<
    React.ReducerAction<R>
@aaronccasanova
aaronccasanova / makeStore.md
Last active August 28, 2021 20:36
How to bootstrap a performant React context store

React Store Creator (Performance considerations included)

// makeStore.js
export default function makeStore(reducer, initialState) {
  const DispatchContext = React.createContext()
  const StoreContext = React.createContext()
  
  function StoreProvider(props) {
    const [store, dispatch] = React.useReducer(reducer, initialState)