Skip to content

Instantly share code, notes, and snippets.

View mcdougald's full-sized avatar

Trevor McDougald mcdougald

View GitHub Profile
@mcdougald
mcdougald / The Rules.md
Created September 5, 2020 07:09 — forked from sebmarkbage/The Rules.md
The Rules of React

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

@mcdougald
mcdougald / Leetcode TS Util Classes.md
Last active September 19, 2023 01:24
move leetcode typescript to its own repo

Leetcode TS Util Classes

Preview:
/**
 * @param {number} capacity
 */

class LRUCache {
  capacity: number;
  count: number;
@mcdougald
mcdougald / Graph Class.md
Created September 19, 2023 01:23
This is a class for creating a graph data structure with methods for adding and removing nodes and edges, finding nodes, and getting information about edges. This is a class that defines two Graph classes, one for adding and removing edges from the graph. It also includes methods to create nodes with different properties such as add/remove edges

Graph Class

Preview:
class Graph {
  constructor(directed = true) {
    this.directed = directed;
    this.nodes = [];
    this.edges = new Map();
  }
@mcdougald
mcdougald / memo-js.md
Last active April 9, 2025 17:27 — forked from eric2j/memo-js.md
Memo Javascript