Skip to content

Instantly share code, notes, and snippets.

View JamieMason's full-sized avatar

Jamie Mason JamieMason

View GitHub Profile
@JamieMason
JamieMason / next.config.js.md
Last active August 1, 2024 14:56
Next.js chrome devtools coverage settings

Next.js chrome devtools coverage settings

I found these settings really useful when using the Chrome Devtools Coverage Inspector to look for unused JavaScript in a Next.js App.

Build the app for production with these settings and the output will be easier to debug.

// next.config.js
module.exports = {
 webpack(config) {
@JamieMason
JamieMason / machine.js
Created October 19, 2021 11:19
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine(
{
initial: "evaluating",
states: {
evaluating: {
on: {
"done.invoke.loadAddressBook": [
{
cond: "hasAddresses",
target: "addressBookAndForm",
@JamieMason
JamieMason / fp-ts-get-props.md
Last active February 8, 2023 10:54
fp-ts – Lodash's `_.get` and Ramda's `R.props` that returns an `Option`

fp-ts – Lodash _.get, Ramda R.props that returns an Option

A function like Lodash's _.get, Ramda's R.props, and Immutable.js's getIn, written in fp-ts.

import { Json } from 'fp-ts/lib/Json';
import { none, Option, some } from 'fp-ts/lib/Option';

export function getIn<T = Json>(props: string[], origin: unknown): Option<T> {
  let value: unknown = origin;
@JamieMason
JamieMason / xstate-machine-types.md
Created September 11, 2021 18:31
Attempt to reduce boilerplate related to a Machine's types in XState

Attempt to reduce boilerplate related to a Machine's types in XState

import type {
  ActionObject,
  EventObject,
  Interpreter,
  Sender,
  State,
 StateMachine,

Refactor this

Spec

when on the server
  return ''
when on the client
  when gclid=12345 GET param is present in the URL
 store it in sessionStorage
@JamieMason
JamieMason / remove-comments-between-imports.js
Last active July 21, 2021 18:52
Remove single line javascript comments between ES module import statements
const fs = require('fs')
const globby = require('globby')
globby
.sync(
['**/*.js', '!node_modules', '!.next', '!**/*.spec.js', '!**/*.test.js', '!**/integration/**'],
{
absolute: true,
},
)
.map((file) => {
@JamieMason
JamieMason / spotify-starred-playlist.md
Last active August 18, 2022 10:02
Spotify Starred Playlist Backup

Spotify Starred Playlist Backup

Backup of my Starred Playlist at https://open.spotify.com/playlist/3K8uUT7ACHzcJD2Lq5rav5?si=d4f4f823811347a7

https://open.spotify.com/track/0abTt3IYQe5ygIGTfDlD1K
https://open.spotify.com/track/3mnqWACBGfk2AO2eonicIT
https://open.spotify.com/track/10zZYL5n0FX5R8tQFhFPU4
https://open.spotify.com/track/5KXaOkHaB1KA4hcEX9g2pv
https://open.spotify.com/track/5HrDLi6cYysquuwWQcK0G6
@JamieMason
JamieMason / getServerSideProps-leak.js
Created February 16, 2021 10:26
TODO getServerSideProps leaking server deps into client bundle
import type { GetServerSideProps, NextPage } from 'next';
import Head from 'next/head';
import React from 'react';
import { SearchPageComponent } from './search-page-component';
import type { Props } from './search-page-props';
export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
try {
if (typeof window === 'undefined') {
const { getSearchPageProps } = await import('./search-page-props');
@JamieMason
JamieMason / tailwind.config.js.md
Created November 30, 2020 11:55
A helper function to adjust every TailwindCSS font-size by a relative amount.

Adjust Default Tailwind CSS Font Sizes

A helper function to adjust every TailwindCSS font-size by a relative amount.

const defaultTheme = require('tailwindcss/defaultTheme');

const adjustFontSizes = (adjustFontSizeBy) => {
  const getAdjustedSize = (sizeName) => {
    const [fontSizeRem, { lineHeight: lineHeightRem }] = defaultTheme.fontSize[sizeName];
@JamieMason
JamieMason / zondicons.sh
Created October 22, 2020 17:54
Convert Zondicons to TypeScript React Components (~80%, still some small manual cleanup to do)
#!/usr/bin/env bash
echo "export const AddOutline: React.FC<{ className?: string }> = ({ className }) => $(cat "./add-outline.svg")" > "./add-outline.tsx"
echo "export const AddSolid: React.FC<{ className?: string }> = ({ className }) => $(cat "./add-solid.svg")" > "./add-solid.tsx"
echo "export const Adjust: React.FC<{ className?: string }> = ({ className }) => $(cat "./adjust.svg")" > "./adjust.tsx"
echo "export const Airplane: React.FC<{ className?: string }> = ({ className }) => $(cat "./airplane.svg")" > "./airplane.tsx"
echo "export const Album: React.FC<{ className?: string }> = ({ className }) => $(cat "./album.svg")" > "./album.tsx"
echo "export const AlignCenter: React.FC<{ className?: string }> = ({ className }) => $(cat "./align-center.svg")" > "./align-center.tsx"
echo "export const AlignJustified: React.FC<{ className?: string }> = ({ className }) => $(cat "./align-justified.svg")" > "./align-justified.tsx"
echo "export const AlignLeft: React.FC<{ className?: string }> = ({ className }) => $(ca