Skip to content

Instantly share code, notes, and snippets.

View JamieMason's full-sized avatar

Jamie Mason JamieMason

View GitHub Profile
@JamieMason
JamieMason / yarn-audit-to-resolutions-with-jq.md
Last active May 10, 2020 13:34
Convert Yarn Audit output into Yarn Resolutions Object using jq

Convert Yarn Audit output into Yarn Resolutions Object using jq

The following command:

yarn audit --json | grep '"type":"auditAdvisory"' | jq -r '{(.data.advisory.module_name):.data.advisory.patched_versions}' | jq -s add

Will filter and convert the output of yarn audit into an index of overrides to avoid vulnerabilities. It will produce output like this:

@JamieMason
JamieMason / heroku-app-bulk-copy-config.md
Created April 30, 2020 16:50
JavaScript Snippet to Automate Copying Config Vars from one Heroku App to another using the UI

Automate Copying Config Vars from one Heroku App to another using the UI

Press Reveal Config Vars on the App you want to copy from and run this to put an array of objects in your clipboard containing all the keys and values.

copy(
  document
    .querySelectorAll('.config-vars-list-table tr')
    .map((el) => {
@JamieMason
JamieMason / sublime-keymap.md
Last active August 19, 2022 09:24
Reconfigure Sublime Text Keyboard Shortcuts to match VS Code

Reconfigure Sublime Text Keyboard Shortcuts to match VS Code

Add the following to ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap.

[
  { "keys": ["alt+down"], "command": "swap_line_down" },
  { "keys": ["alt+z"], "command": "toggle_setting", "args": { "setting": "word_wrap" } },
  { "keys": ["alt+up"], "command": "swap_line_up" },
 { "keys": ["shift+alt+down"], "command": "duplicate_line" },
@JamieMason
JamieMason / render-methods-codemod.js
Created March 9, 2020 18:08
[WIP] Attempt to replace this.renderFoo in a React Class with a new <Foo /> Component
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const createClassComponent = (className, superClassName, renderMethod) =>
j.classDeclaration(
j.identifier(className),
j.classBody([
j.methodDefinition("method", j.identifier("render"), renderMethod)
]),
@JamieMason
JamieMason / AppContextProvider.tsx
Created February 10, 2020 22:40 — forked from adamkl/AppContextProvider.tsx
xState service layer
import React from "react";
import { createUserSessionService } from "services/UserSessionService";
import { createNavService } from "services/NavService";
// Wiring up our "IOC container"
const userSessionService = createUserSessionService();
// NavService depends on UserSessionService
const navService = createNavService(userSessionService);
@JamieMason
JamieMason / tree-walk-deep-traverse-generator.md
Last active June 18, 2021 06:40
JavaScript Generator function to deeply traverse JSON-Encodable data

JavaScript Generator function to deeply traverse JSON-Encodable data

Helpers

const isArray = value => Array.isArray(value);
const isObject = value => Object.prototype.toString.call(value) === '[object Object]';

walkTree

@JamieMason
JamieMason / proxy-dom.md
Last active December 24, 2019 15:41
Use JavaScript Proxy to log DOM APIs

Use JavaScript Proxy to log DOM APIs

Find out which DOM APIs your code is using with Proxy and Webpack.

Files

src/components/App.js

@JamieMason
JamieMason / machine.js
Last active December 6, 2019 14:38
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@JamieMason
JamieMason / generators-and-async-generators.js
Created October 23, 2019 10:19
JavaScript Generators and Async JavaScript Generators
const sleep = secs => new Promise(done => setTimeout(done, secs * 1000));
function* myGenerator() {
const array = [1, 2];
while (array.length) {
yield array.shift();
}
}
@JamieMason
JamieMason / sleep.js
Created October 23, 2019 10:18
sleep
const sleep = secs => new Promise(done => setTimeout(done, secs * 1000));