Skip to content

Instantly share code, notes, and snippets.

View danielrose7's full-sized avatar

Daniel Rose danielrose7

View GitHub Profile
@danielrose7
danielrose7 / git-trim-merged-branches-and-worktrees.zsh
Last active March 26, 2026 17:00
trim — zsh function to delete local git branches (+ worktrees) that have been merged. Catches both true merges and squash merges via GitHub PR status. Auto-detects default branch from origin/HEAD.
# Delete local branches merged to the default branch + their worktrees
# Catches both true merges (git) and squash merges (GitHub PR status)
# Reads default branch from origin/HEAD — works with main, staging, etc.
# Usage: trim [--force] (--force skips confirmation)
trim() {
local repo_root
repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "Not in a git repo"; return 1; }
local base_branch
base_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)"
@danielrose7
danielrose7 / worktree-nav.sh
Last active March 24, 2026 21:15
Worktree-aware branch switcher: cd to existing worktree instead of failing
# Worktree-aware branch switcher
#
# The problem: git won't let you checkout a branch that's already open in a
# worktree. The error message tells you exactly where to go — so why not just
# go there automatically?
#
# $ git checkout some-branch
# fatal: 'some-branch' is already checked out at '/Users/dan/work/admin.worktrees/some-branch'
#
# Instead of copying that path, this alias catches the error and cd's there.
@danielrose7
danielrose7 / .zshrc
Last active October 24, 2025 16:27
alias to run jest test files in current git status
# add to runs tests for both modified and untracked files ending in .test.ts extension
alias jestdiff="git status --porcelain | grep -E '\.test\.ts$' | awk '{print \$2}' | xargs pnpm jest"
@danielrose7
danielrose7 / generatePdfBase64.ts
Created October 10, 2025 00:25
pdfMake getBase64 with promise with error handling
/**
* pdfMake's getBase64 provides for an async callback that does not allow for error handling (at least in v0.2.x)
* this recreates their OutputDocument.getBase64() behavior with accessible error handling
*/
export const generatePdfBase64 = (
pdf: TCreatedPdf,
{
endStream = true,
readChunkSize = 1024 * 1024 * 1024, // 1 GiB (matches pdfmake's OutputDocument.bufferSize)
timeoutMs = 15 * 1000,
@danielrose7
danielrose7 / rls-prisma-extension.test.ts
Last active April 10, 2026 09:25
RLS Extension for Prisma with wrapping jest test
import { Prisma, PrismaClient } from '@prisma/client';
import get from 'lodash.get';
describe('prisma extensions', () => {
it('RLS extension sets app policy helpers', async () => {
// #region setup
const userId = 'user_123';
const organizationId = 'org_456';
const membershipRole = 'admin';
const setRlsSql = Prisma.sql`SELECT set_rls_app_context(${userId}, ${organizationId}, ${membershipRole});`;
@danielrose7
danielrose7 / dependent_tag_ui.md
Last active January 27, 2023 11:04
progressively disable dependent options

Tag Type

  • category of tag
  • has_many :tags
  • optionally belongs to a parent tag type (nested option)

Tag

  • specific field
  • belongs_to :tag_type
  • optionally belongs to a parent tag (nested option)
@danielrose7
danielrose7 / parsePropsFromDataset.js
Last active January 27, 2023 10:17
a simple way to hand off server side rendered data attributes to props in components
// - example rails erb view
// <div id="edit-react-form"
// data-submit-endpoint="<%= billing_profile_path(@billing_profile.token) %>"
// data-initial-values="<%= @form.initial_values.to_json %>"
// data-cancel-url="<%= billing_profile_path(@billing_profile.token) %>"
// >
// </div>
function parsePropsFromDataset(dataset) {
let stringifyedOptions = { ...dataset }; // convert DOMStringMap into Object
@danielrose7
danielrose7 / DisplayLocalStorage.js
Last active December 20, 2022 20:25
react component to read and display localStorage in a _more_ human readable manner
import * as React from "react";
import { SmallButton } from "../../shared"; // a cool <button />
const DisplayLocalStorage = () => {
const [changes, setChanges] = React.useState(0); // triggers re-renders
let localStorageState = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
let value;
@danielrose7
danielrose7 / ClientSideFiltering.js
Last active June 9, 2021 14:10
abstracted, client side filtering with location.search navigation via hooks
import * as React from "react";
import { GET } from "../utils/service"; // a fetch wrapper
import { useFilters } from "../hooks";
import FilterForm from "../components/FilterForm";
// filterTemplate instructs useFilters
// which filters should be allowed
// and how they are to traverse the data object tree
@danielrose7
danielrose7 / application_system_test_case.rb
Last active October 9, 2020 16:38
helpers for debugging webpacker + rails system test for minitest including printing to the console and disabling uglify
# based on https://intellipaat.com/community/16534/is-there-a-way-to-print-javascript-console-errors-to-the-terminal-with-rspec-capybara-selenium
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
JavaScriptError = Class.new(StandardError)
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
def teardown
logs = page.driver.browser.manage.logs.get(:browser)
errors = logs.select { |e| e.level == 'SEVERE' && e.message.present? }