Skip to content

Instantly share code, notes, and snippets.

View mikegwhit's full-sized avatar
🎯
Focusing

Mike Whit mikegwhit

🎯
Focusing
View GitHub Profile
#!/bin/bash
# git-diff-json.sh - Get Git diff information in JSON format
#
# Usage:
# ./git-diff-json.sh [directory] [options]
#
# Options:
# --compare-branch, -c Branch to compare against (default: main)
# --no-local-changes, -n Don't include local changes in comparison
/**
* Chat-session cost estimator, accounting for character-based token growth
* and optional OpenAI-style cached token discounting.
*
* @param {Object} opts
* @param {number} opts.turns – number of user↔assistant turns
* @param {number} opts.totalChars – total characters across the full script
* @param {number} [opts.charsPerTok] – avg chars per token (English ≈ 4)
* @param {number} [opts.inputCost] – $ / 1,000 input tokens
* @param {number} [opts.outputCost] – $ / 1,000 output tokens
/**
* Problem: Word Ladder
*
* Given a `beginWord`, an `endWord`, and a list of `wordList`:
* Transform `beginWord` into `endWord` by changing **only one letter at a time**,
* and each intermediate word must exist in the `wordList`.
*
* Return the **minimum number of transformations** required.
* If no such sequence exists, return 0.
*
/**
* Problem: Detect Cycle in a Directed Graph
*
* You are given a directed graph represented as an adjacency list.
* Each key is a node, and its value is an array of neighbors.
*
* Goal:
* Return true if the graph contains a **cycle**, false otherwise.
*
* Example:
/**
* Problem: Coin Change (Leetcode #322)
*
* You are given an array of coin denominations `coins` and an integer `amount`.
* Return the **fewest number of coins** needed to make up that amount.
*
* If it's not possible, return -1.
*
* You may use **each coin unlimited times** (unbounded knapsack).
*
/**
* Problem: 0/1 Knapsack
*
* You are given two arrays:
* - weights[i] = weight of the i-th item
* - values[i] = value of the i-th item
*
* And an integer `capacity` representing the max weight the knapsack can hold.
*
* Goal:
/**
* Problem: Subsets (Power Set)
*
* Given an array of distinct integers `nums`, return all possible subsets (the power set).
* Each subset must be in non-descending order (order of input), and the full result must not contain duplicates.
*
* You must return all subsets, including:
* - The empty subset []
* - Single element subsets [x]
* - All combinations up to the full array [x, y, z, ...]
/**
* Problem: Sudoku Solver
*
* You are given a 9x9 Sudoku board represented as a 2D array of characters.
* Empty cells are denoted by '.'.
*
* Goal:
* Fill the board in-place so that it becomes a valid completed Sudoku.
*
* Rules:
@mikegwhit
mikegwhit / scroll.class.js
Last active October 10, 2022 16:26
A class for wrapping window.scrollTo with a callback and a scroll queue.
/**
* ScrollOptions
*/
class ScrollOptions {
constructor(obj) {
/**
* @type {Function} Function called when a scroll in occurs.
*/
this.scrollIn = function() {};
@mikegwhit
mikegwhit / levenstein.js
Last active May 15, 2019 21:48
Levenshtein Distance
/**
* @license MIT
* Copyright 2019 @andrei-m
*
* See original which this code is based on:
* https://gist.github.com/andrei-m/982927/0efdf215b00e5d34c90fdc354639f87ddc3bd0a5
*
* Basic modifications include using ES6 `const` and `let`. Additionally
* condenses if statement. Changes are somewhat trivial overall :)