Skip to content

Instantly share code, notes, and snippets.

View JamieMason's full-sized avatar
💤
On a break from OSS for a couple of weeks

Jamie Mason JamieMason

💤
On a break from OSS for a couple of weeks
View GitHub Profile
@JamieMason
JamieMason / try-rescript.res
Created December 18, 2023 22:04
Try ReScript
// looking at an alternative to ReScript's Option
// which exists at runtime when compiled to JS
type maybe<'a> = {
_tag: [#Some],
value: 'a,
}
let createMaybe = (value: 'a): maybe<'a> => {
{
@JamieMason
JamieMason / syncpack-dependents.json
Created September 26, 2023 10:02
Projects depending on https://github.com/JamieMason/syncpack, sorted by most stars
[
{ "org": "@pnpm", "repo": "pnpm/pnpm", "stars": 25486, "forks": 790 },
{ "org": "@mantinedev", "repo": "mantinedev/mantine", "stars": 21487, "forks": 1513 },
{ "org": "@BuilderIO", "repo": "BuilderIO/qwik", "stars": 18903, "forks": 1076 },
{ "org": "@microsoft", "repo": "microsoft/fluentui", "stars": 16391, "forks": 2540 },
{ "org": "@microsoft", "repo": "microsoft/pyright", "stars": 10898, "forks": 1172 },
{ "org": "@callstack", "repo": "callstack/linaria", "stars": 10805, "forks": 430 },
{ "org": "@woocommerce", "repo": "woocommerce/woocommerce", "stars": 8728, "forks": 10800 },
{ "org": "@electron", "repo": "electron/forge", "stars": 5816, "forks": 472 },
{ "org": "@altair-graphql", "repo": "altair-graphql/altair", "stars": 4828, "forks": 272 },
type GetFn = () => {
next(iteration: IteratorResult<any, any>): IteratorResult<any, any>;
};
function iterateOverSyncOrAsyncGenerator<T extends Iterable<any>>(getIterator: GetFn, gen: T): Iterable<any>;
function iterateOverSyncOrAsyncGenerator<T extends AsyncIterable<any>>(getIterator: GetFn, gen: T): AsyncIterable<any>;
function iterateOverSyncOrAsyncGenerator<T extends Iterable<any> | AsyncIterable<any>>(
getIterator: GetFn,
gen: T
): Iterable<any> | AsyncIterable<any> {
import { R } from '@mobily/ts-belt';
/** Additional helpers for https://mobily.github.io/ts-belt/api/result */
export const $R = {
/**
* 1. Return an R.Ok<output[]> if every R.Result succeeds
* 2. Return an R.Error<Error> for the first failure encountered
*/
all<Input, Output = Input>(
getResult: (value: Input) => R.Result<Output, Error>,
@JamieMason
JamieMason / find-nested-dependencies.md
Created March 2, 2022 12:49
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.

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

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 December 8, 2021 20:34
Lossless Debounce Function in JavaScript

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 November 29, 2021 16:55
Tick "Viewed" on every file you've scrolled past on a GitHub Pull Request

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 November 18, 2023 14:40
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",