Skip to content

Instantly share code, notes, and snippets.

View jbranchaud's full-sized avatar

Josh Branchaud jbranchaud

View GitHub Profile
@jbranchaud
jbranchaud / file_info.sh
Created April 1, 2025 16:14
A script that you can run against any file/path to get a bunch of details about it
#!/bin/bash
# file_info.sh - A script to provide comprehensive information about a file
# Usage: ./file_info.sh <filename>
set -e
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
@jbranchaud
jbranchaud / validate_constraints.rb
Created March 22, 2025 16:55
Idea for a fail-fast Rails initializer to check that database check constraints are in-sync with app code constants
# config/initializers/validate_constraints.rb
Rails.application.config.after_initialize do
if Rails.env.development? || Rails.env.test?
# Get the check constraint from the database schema
connection = ActiveRecord::Base.connection
constraint_sql = nil
# Try to extract the constraint SQL
begin
# For PostgreSQL, you can query the information_schema
@jbranchaud
jbranchaud / gdoc-download.sh
Created March 11, 2025 03:35
A script to download a public Google Doc from its link, prompts for format with fzf
#!/bin/bash
# Check if fzf is installed
if ! command -v fzf &> /dev/null; then
echo "Error: fzf is not installed. Please install it first."
echo "You can install it with:"
echo " - On macOS: brew install fzf"
echo " - On Ubuntu/Debian: sudo apt install fzf"
echo " - On other systems: see https://github.com/junegunn/fzf#installation"
exit 1
@jbranchaud
jbranchaud / answer-based-ai-conversations.md
Created March 3, 2025 17:03
Flip the script with AI Conversations

Some starter prompts for having conversations with AI where the AI asks the questions and you get to answer.

Try pasting one of these into your favorite conversational LLM tool (I like to use Claude Sonnet) and see where their questions take you. Modify them as needed to tailor it to your situation.

Morning Pages

I'd like to do a guided form of "Morning Pages" with you, for 15 minutes, where you ask me one question at a time and I answer. The questions can build on each other, but it is also fine to go off in another direction if it could be fruitful. The idea is for me to get all the things in my head, out on paper at the beginning of the day. A light goal is getting some clarify on what to work on today, but the process of "brain dumping" is more important than any particular end result.

Remember, one question at a time. Go ahead and ask me the first question.

@jbranchaud
jbranchaud / export-all-chrome-tabs.js
Created January 10, 2025 17:54
A ScriptKit script to grab URL and title for all Chrome tabs of current window
/** @type {import("@johnlindquist/kit")} */
// Name: Export all Chrome Tabs
// Description: Export all Chrome Tabs to Clipboard
let jxa = await npm("@jxa/run");
let result = await jxa.run(() => {
// This was taking too long for windows with TONS of Chrome tabs. AppleScript
// was timing out.
@jbranchaud
jbranchaud / explain_analyze_query_plan.json
Created December 6, 2024 02:37
Explain analyze for complex query plan in TEXT, JSON, YAML, and XML formats
[
{
"Plan": {
"Node Type": "Sort",
"Parallel Aware": false,
"Async Capable": false,
"Startup Cost": 25.77,
"Total Cost": 25.78,
"Plan Rows": 1,
"Plan Width": 164,
@jbranchaud
jbranchaud / qtil.go
Created December 5, 2024 00:14
quick TIL file creator
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"time"
@jbranchaud
jbranchaud / send_more_money.rb
Created November 21, 2024 03:47
Send More Money solved with Ruby (brute-force)
# Send More Money
#
# Verbal Arithmetic https://en.wikipedia.org/wiki/Verbal_arithmetic
letters = %i[s e n d m o r y]
check = ->(vals) do
# leading zeros are not allowed
return false if vals[:s] == 0 || vals[:m] == 0
@jbranchaud
jbranchaud / get-email-for-newsletter-signup.js
Created November 20, 2024 17:59
Get email (w/ current site interpolated) for newsletter signup
/** @type {import("@johnlindquist/kit")} */
// Name: Get Email for Newsletter
// Description: Create email address with current domain interpolated
const createEmailWithDomain = (baseEmail, { url }) => {
const [emailUser, emailDomain] = baseEmail.split("@");
const urlObj = new URL(url);
let domain = urlObj.host.split(".");
@jbranchaud
jbranchaud / stored-array.sql
Created March 11, 2024 15:32
User-Defined Ordering in PostgreSQL using Stored Array
-- from the People, Postgres, Data Discord https://discord.com/channels/710918545906597938/710918545906597941/1214677867431206932
CREATE TABLE todo_list (
id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
list_name TEXT NOT NULL,
item_order INT[] NULL
);
CREATE TABLE todo_list_item (
id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,