Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

James Mulholland mulholio

🙃
View GitHub Profile
View machine.js
const talkMachine = Machine({
id: "talk",
initial: "waiting",
states: {
waiting: {
on: {
LOAD: "loading",
},
},
loading: {
View Convert PNGS to JPEGS.sh
mogrify -format jpg -flatten dataset/**/*.png # you will need imagemagick installed
find ./dataset -name '*.png' -delete
View machine.js
// Comment and uncomment as desired for initial
// user states
const initialAccountStatus =
{ account: 'noAccount', signIn: undefined, }
// { account: 'hasAccount', signIn: 'signedIn', }
// { account: 'hasAccount', signIn: 'signedOut', }
const fetchMachine = Machine({
id: 'stackCommerce',
type: 'parallel',
View How to test a function throws in Jest without polutting the console with errors.ts
export function expectToThrow(
fn: Function,
messageMatch?: string | RegExp,
) {
const consoleSpy = jest.spyOn(console, 'error').mockImplementation();
try {
fn();
} catch (e) {
if (messageMatch) {
expect(e.message).toEqual(expect.stringMatching(messageMatch));
View machine.js
const initialContext = {
id: '',
title: '',
note: '',
childNodes: [],
}
// Must double-type the machine as it is recursive
const nodeMachine= Machine({
id: 'node',
@mulholio
mulholio / useKeyDown.ts
Created Jan 16, 2020
React hook to make use of key presses
View useKeyDown.ts
import { useCallback, useEffect } from 'react';
type Key =
| 'a'
| 'b'
| 'c'
| 'd'
| 'e'
| 'f'
| 'g'
View Mock named imports with jest differently for each test.txt
jest.mock('./module-to-mock', () => ({
functionToMock: jest.fn()
}))
import { functionToMock } from './module-to-mock'
it('test1', () => {
functionToMock.mockImplementation(() => 'someValue')
})
it('test2', () => {
View Change permissions on a new bash script to make it runnable.sh
# allow running of the script
chmod u+x new-script.sh
# and if you want to add this script to your path...
cp ./new-script.sh /usr/local/bin/new-script
# now you can run from anywhere with
new-script
View How to do what npm audit --fix does with yarn.txt
$ yarn audit # when this fails
---
# Try this to deeply upgrade a package
$ yarn upgrade parentFailingPackage
---
@mulholio
mulholio / delete-postmaster.sh
Created Feb 27, 2019
Removes Postgres' `postmaster.pid` file for when you computer shuts down incorrectly (e.g. battery failure) and Postgres won't start
View delete-postmaster.sh
# run this in your terminal
rm ~/Library/Application \Support/Postgres/var-10/postmaster.pid
You can’t perform that action at this time.