Skip to content

Instantly share code, notes, and snippets.

View joshdover's full-sized avatar

Josh Dover joshdover

View GitHub Profile
@joshdover
joshdover / ExtendedRichUtils.js
Last active July 30, 2021 12:58
Example of how to add metadata to blocks for handling text alignment correctly
import { Modifier, EditorState, RichUtils } from 'draft-js';
import getCurrentlySelectedBlock from './getCurrentlySelectedBlock';
export const ALIGNMENTS = {
CENTER: 'center',
JUSTIFY: 'justify',
LEFT: 'left',
RIGHT: 'right'
};
@joshdover
joshdover / 01_python_flamegraphs.md
Last active November 27, 2022 20:38
Python flamegraphs

Install python-flamegraph into your project:

pip install git+https://github.com/evanhempel/python-flamegraph.git

Record a profile around a bit of code:

import flamegraph
thread = flamegraph.start_profile_thread(fd=open("./profile.log", "w"))
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed: