Skip to content

Instantly share code, notes, and snippets.

@JamieMason
JamieMason / fp-ts-get-props.md
Last active Sep 19, 2021
fp-ts – Lodash's `_.get` and Ramda's `R.props` that returns an `Option`
View fp-ts-get-props.md

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 Sep 11, 2021
Attempt to reduce boilerplate related to a Machine's types in XState
View xstate-machine-types.md

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

import type {
  ActionObject,
  EventObject,
  Interpreter,
  Sender,
  State,
  StateMachine,
View yuck.md

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 Jul 21, 2021
Remove single line javascript comments between ES module import statements
View remove-comments-between-imports.js
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
Created Apr 14, 2021
Spotify Starred Playlist Backup
View spotify-starred-playlist.md

Spotify Starred Playlist Backup

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

https://open.spotify.com/track/6H8YFN8eLYYnvIrm694LNn
https://open.spotify.com/track/6pkmfPkNwOtucanO7JF9Q6
https://open.spotify.com/track/64ISj1YDMNUvSyIC28cGgL
https://open.spotify.com/track/4ugsTxjvUc7iGuY1fMNWzO
https://open.spotify.com/track/1Td7TGT1XtK2ojUjz1mGUV
@JamieMason
JamieMason / getServerSideProps-leak.js
Created Feb 16, 2021
TODO getServerSideProps leaking server deps into client bundle
View getServerSideProps-leak.js
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 Nov 30, 2020
A helper function to adjust every TailwindCSS font-size by a relative amount.
View tailwind.config.js.md

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 Oct 22, 2020
Convert Zondicons to TypeScript React Components (~80%, still some small manual cleanup to do)
View zondicons.sh
#!/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
@JamieMason
JamieMason / delete-whatsapp-messages.js
Last active Jul 25, 2021
Bulk Delete every WhatsApp Chat Message
View delete-whatsapp-messages.js
// Delete every Chat in WhatsApp, by Jamie Mason (https://twitter.com/fold_left)
// https://gist.github.com/JamieMason/f8992ebf95423244b730b2c393c321ef
//
// 1. Go to https://web.whatsapp.com/ and sign in.
// 2. Archive any messages you don't want deleting, you can unarchive them after.
// 3. Open the Developer Console. (COMMAND+ALT+I on Mac)
// 4. Paste this into the Developer Console and run it.
// 5. If it gets stuck, scroll up and down in the list of chats.
// 6. Refresh the page and run again if you have any problems.
// 7. This Script does not Exit Groups or clear messages in them.
@JamieMason
JamieMason / copy-names-of-all-github-issue-labels.md
Created Aug 20, 2020
Copy names of all GitHub Issue Labels
View copy-names-of-all-github-issue-labels.md