Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie Mason JamieMason

View GitHub Profile
@JamieMason
JamieMason / find-nested-dependencies.md
Created Mar 2, 2022
Find all modules which a given JavaScript module depends on, and all they modules they depend on, and all they modules they depend on etc.
View find-nested-dependencies.md

Find nested dependencies or imports of a JavaScript Module

Find all deep/nested/recursive/descendant dependencies/imports/requires of a JavaScript Module.

Related to sverweij/dependency-cruiser#564, find all modules which a given JavaScript module depends on, and all the modules they depend on, and all the modules they depend on etc.

Installation

npm install -g ts-node
View list-github-pull-request-reviewers.md

List All GitHub Pull Request Reviewers for a Repo

Needs jq installed.

#!/bin/bash

for pull_number in {1..500}
do
  USER="YourGitHubUserName"
@JamieMason
JamieMason / README.md
Last active Dec 8, 2021
Lossless Debounce Function in JavaScript
View README.md

Lossless Debounce Function

Returns a function which will capture and collect all invocation arguments, to process in batches once ms consecutive resting time has passed.

Know a more common name for this function? Let me know in this discussion.

Demo

@JamieMason
JamieMason / github-bulk-mark-as-viewed.md
Created Nov 29, 2021
Tick "Viewed" on every file you've scrolled past on a GitHub Pull Request
View github-bulk-mark-as-viewed.md

GitHub PR bulk mark file as viewed

Tick "Viewed" on every file you've scrolled past on a GitHub Pull Request

// Tick "Viewed" on every file you've scrolled past on a
// GitHub Pull Request
$$('.js-reviewed-checkbox').forEach((el) => {
  if (!el.checked && window.scrollY > el.getBoundingClientRect().top) {
 el.click();
@JamieMason
JamieMason / next.config.js.md
Last active Nov 10, 2021
Next.js chrome devtools coverage settings
View next.config.js.md

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) {
View machine.js
const fetchMachine = Machine(
{
initial: "evaluating",
states: {
evaluating: {
on: {
"done.invoke.loadAddressBook": [
{
cond: "hasAddresses",
target: "addressBookAndForm",
@JamieMason
JamieMason / fp-ts-get-props.md
Last active Sep 28, 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) => {