Skip to content

Instantly share code, notes, and snippets.

View kendallroth's full-sized avatar
🍁

Kendall Roth kendallroth

🍁
View GitHub Profile
@kendallroth
kendallroth / README.md
Created July 22, 2025 19:51
Postgres Table Sizes

Postgres Table Sizes

Calculating Postgres table sizes is a bit complicated, due to the variety of data sizes available.

  • Table data
    • main - main data fork of relation
    • fsm - Free Space Map for relation
    • vm - Visibility Map for relation
    • init - initialization fork (if any) for relation
  • TOAST data
@kendallroth
kendallroth / repository.util.ts
Last active July 10, 2025 21:25
Update TypeORM entity fields from a NestJS DTO object
/**
* Set defined/scalar entity fields from a DTO (only using fields existing on entity)
*
* NOTE: Mutates original value!
*
* NOTE: Skips all non-scalar fields and `undefined` DTO values, which would other wise cause unexpected
* data loss for non-specified or partially provided relation values. However, non-scalar fields
* can be permitted with `allowNonScalarKeys` if specifically handled/provided.
*
* @param options.allowNonScalarKeys - Allows non-scalar keys to be assigned (ie. arrays, objects, etc)
@kendallroth
kendallroth / pocketbase_v23_data_migration_guide.md
Created May 13, 2025 21:23
Guide for migrating data in Pocketbase v23 upgrade

Upgrading to v23

Upgrading to Pocketbase v23 was a large undertaking due to the amount of fundamental changes to extending as a framework. The library contains several excellent resources, including the GitHub Release and Pocketbase Upgrade Guide, that help with the upgrade. However, they do not explain how to handle upgrading deployed/production instances, which is a bit more tricky depending on the server host. This guide deals with upgrading a Pocketbase application deployed on Pockethost, an excellent and affordable hosting service for Pocketbase apps.

Official Upgrade Guide

The Pocketbase Upgrade Guide provides an excellent guide to the major breaking changes. However, there were a few assorted changes not explicitly documented (and there may be others still).

Email templates no longer have ACTION_URL

Email templa

@kendallroth
kendallroth / README.md
Last active July 22, 2024 16:22
CS2 Modding: JS deobfuscation

CS2 Modding: JS deobfuscation

For anyone else working on understanding some of the JS helpers for the Colossal Order UI package, I spent some time deobfuscating a couple functions/classes. Please note there certainly be mistakes and there is some omitted code; however, overall the gist is present.

@kendallroth
kendallroth / README.md
Last active June 15, 2023 20:32
Strongly type React Hook Form field names

Typing RHF Fields

While react-hook-form supports strong typing everywhere, including support for types inferred from a Yup schema (Yup.InferType<Schema>), passing field names to controls is still untyped. However, this can be resolved with RHF's FieldPath type and a helper function.

Options

// Option 1: Declared per form, less boilerplate per control
export const getOrganizationFormField = (name: FieldPath<OrganizationForm>) => name;
getOrganizationFormField("billingAddress.address1");
@kendallroth
kendallroth / cache.ts
Created August 25, 2022 05:10
Simple TS caching mechanism (use Map instead though...)
type CacheKey = string | number;
interface Cache<T> {
/** Number of cache entries */
readonly count: number;
/** Get an item from the cache */
get: (key: CacheKey) => T | null;
/** Check whether cache contains a given item */
has: (key: CacheKey) => boolean;
/** Cached items */
@kendallroth
kendallroth / reduce-jupyter-git-conflicts.md
Last active July 20, 2022 15:56
Reduce Jupyter Notebook Git conflicts

Jupyter Git Conflicts

Jupyter Notebooks have a tendency to cause Git conflicts when working collaboratively on a notebook. This is primarily due to cell metadata that really doesn't matter, and can be removed with a pre-save configuration hook. This hook will be run across all Jupyter Notebooks; however, it utilizes a custom opt-in metadata configuration option (reduce_git_conflicts). If the opt-ine is not specified, or set to false, the Notebook will save as normal.

  1. Add pre-save hook to Jupyter Notebook config
  2. Enable reducing Git conflicts in Notebook metadata

NOTE: This approach does modify the notebook save file itself, which could lead to issues if there are fields that must remain in the file but lead to conflicts (and would otherwise be removed).

NOTE: This approach was developed with Jupyter Notebook in mind. While Jupyter Lab is quite similar, there are several differences (generating config, editing metadata).

@kendallroth
kendallroth / ignore_diffs.md
Created January 24, 2022 17:43
Exclude files from Gid diff

Some projects may have files that should be skipped in Git diff but still show in Git status (and be tracked). This can be made possible with a custom diff driver that uses a no-op command.

Adapted from StackOverflow - @KurzedMetal.

Custom diff driver

Create a global no-op diff command driver with the following command. Note that driver can be limited to local respository by removing the --global flag.

git config diff.nodiff.command /bin/true
@kendallroth
kendallroth / updateNestedValue.ts
Created January 20, 2022 23:14
Update value in nested objects (with/without mutation)
/**
* Dynamically sets a deeply nested value in an object (returns new object)
*
* NOTE: By default it will create any missing nested keys!
*
* @param obj - Object which contains the value to set
* @param path - Path to nested key being set
* @param value - Target value to set
* @param recursive - Whether to create non-existing paths
* @returns Updated nested object
@kendallroth
kendallroth / .vimrrc
Created January 1, 2022 20:15
Standard Vim configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""
" 01. General
""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
filetype off
""""""""""""""""""""""""""""""""""""""""""""""""""
" 02. Vundle plugins
""""""""""""""""""""""""""""""""""""""""""""""""""
set rtp+=~/.vim/bundle/Vundle.vim