Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
mattdeboard / param_combos.ts
Created May 4, 2021 18:24
Sample type defs for typescript showing how to constrain function parameter combinations.
type Payload = Partial<{ [Key in AcceptableCombinations[1]]: number }>;
type EventObject = {
type: AcceptableCombinations[0];
payload: Payload;
}
type AcceptableCombinations =
| [...[type: "a", key: "x"]]
| [...[type: "b", key: "y"]];
@mattdeboard
mattdeboard / dynamic-settings.sh
Created January 30, 2021 00:31
Modify workspace settings dynamically by passing a custom settings fragment when starting VS Code at the command line
#!/usr/bin/env bash
# VS Code does not have workspace settings per user. Or user settings
# per workspace. Either way, I made this script because when I open up
# my Rails repo, I want it to have a different visual theme than my
# TypeScript repo.
# This script creates a workspace file dynamically with modifications
# specified in `custom` variable. When the VS Code process exits, it
# cleans up the temporary file.
@mattdeboard
mattdeboard / central ac cycle.md
Last active October 11, 2020 00:54
Central AC system description

System Component Inputs & Outputs

Refrigerant Cycle

Evaporator

Composed of evaporator coils & refrigerant line.

Refrigerant passing through coils absorbs thermal energy from unconditioned air, resulting in cooler & drier air. This air is discharged into the living space.

  • Input: Low-pressure, low-temp liquid/vapor-mix coolant.
    • From: TXV
  • Output: Low-pressure, low-temperator coolant vapor.
@mattdeboard
mattdeboard / kmp.py
Created March 17, 2012 00:04
Knuth-Morris-Pratt algorithm
def kmp_match(seq, subseq):
"""
Implementation of the Knuth-Morris-Pratt (KMP) algorithm in Python.
This algorithm finds valid shifts to locate subsequence `subseq` in
sequence `seq`.
"""
n = len(seq)
m = len(subseq)
@mattdeboard
mattdeboard / num_to_string.py
Last active March 2, 2020 18:10
Turns abitrary number into its string representation (e.g. 100 -> "one hundred") up to 999,999,999,999,999,999,999,999,999,999,999,999,999
#!/usr/bin/env python
from math import ceil, floor, log10
ones = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
@mattdeboard
mattdeboard / cycleFrom.js
Created February 22, 2019 18:20
Cycle through data infinitely. Optionally specify a starting index.
function* cycleFrom(elements, startIndex = 0) {
let index = startIndex;
while (true) {
if (index >= elements.length) {
index = index % elements.length;
}
yield elements[index];
index += 1;
@mattdeboard
mattdeboard / pull_request_waiter.js
Created February 8, 2019 22:05
Push PR merge buttons for you
function justClickIt() {
// The web-based minification tools I tried require 'var' instead of 'const'
var mergeButton = document.querySelector(".merge-message .select-menu .btn-group-squash button");
var confirmButton = document.querySelector("button.js-merge-commit-button");
// Selector for the "Update Branch" button
var updateButton = document.querySelector("form.branch-action-btn button");
console.log("Looking for the right buttons...");
if (!!updateButton && !updateButton.disabled) {
@mattdeboard
mattdeboard / camelcase-keys-in-region.el
Created December 18, 2018 21:15
Convert snake_case JSON keys in region to camelCase
(defun camelcase-keys-in-region (start end)
"Change snake_case JSON keys in the region to camelCase.
START and END are start/end of region."
(interactive "r")
(save-restriction (narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward "^ *[a-z0-9_]+:" nil t)
(while (re-search-backward "_\\(.\\)" (point-at-bol) t)
(replace-match (upcase (match-string 1)))))))
client.with_framework(
StandardFramework::new()
.configure(|c| c
.owners(owners)
.prefix("~"))
.command("add", |c| c
.cmd(commands::add::add)
// .after(|ctx, msg, error| {
// let data = ctx.data.lock();
// match data.get::<models::draft_pool::DraftPool>() {
<CurrencyInput
editable={editable}
onChange={e =>
handleChange && handleChange(this.props.row.priceCheckParam, e)
}
style={styles.textInput}
value={value}
invalidValueMsg="Must be >= $1,000"
isValueValid={v => v >= 1000}
/>