Skip to content

Instantly share code, notes, and snippets.

View mike-pete's full-sized avatar

Mike Peterson mike-pete

  • San Francisco, CA
View GitHub Profile
@mike-pete
mike-pete / 0-README.md
Last active October 26, 2024 17:52
Initialize conditionally with anon function

So let's say I'm building a website to tell me what I should wear based on the current weather (raining, sunny, snowing).

I only use the app once per day, and the weather won't change while I'm looking at the app, so the clothing choice should be constant.

I also want the code to be easy to read so other members of my team can easily understand the code.

@mike-pete
mike-pete / heap.ts
Last active November 17, 2024 17:42
TS Heap
class Heap<T> {
#heap: (T | undefined)[] = [undefined]
#prioritize: (a: T, b: T) => number
constructor(prioritize: (a: T, b: T) => number, toHeapify: T[] = []) {
this.#prioritize = prioritize
this.#heap = [undefined, ...toHeapify]
this.#heapify()
}

Editable Text for Srcbook

This might be a reasonable MVP for making your page content editable.

In the Iframe

  1. find all the elements that contain text
  2. make them editable with contentEditable = 'true'
  3. listen for text changes and pass those changes to the parent window
@mike-pete
mike-pete / directions.ts
Last active April 9, 2025 02:04
Directions Map - useful for direction based traversal
const direction = {
'↑': [-1, 0],
'↗': [-1, 1],
'→': [0, 1],
'↘': [1, 1],
'↓': [1, 0],
'↙': [1, -1],
'←': [0, -1],
'↖': [-1, -1],
} satisfies Record<string, [number, number]>