Skip to content

Instantly share code, notes, and snippets.

@davehague
davehague / markedjs-new-tab.md
Last active November 15, 2024 16:55
Have the marked (markedjs) library open links in new tab

In some cases I'd like the marked library open links in new tabs, but the default behavior is to open in the same tab. This means you have to override then renderer but the documentation doesn't make it completely obvious how to do that. Here's how you can do it.

// src/utils/markdown.ts
import { marked } from "marked";
import type { Token, Tokens } from "marked";

export const renderMarkdown = (content: string) => {
  try {
 const renderer = new marked.Renderer();
@davehague
davehague / ps-file-tree.md
Created September 24, 2024 17:13
Print a nicely formatted file tree in Powershell

Often I'll find it helpful to give a LLM context of my file structure for coding projects, so I co-wrote this script to only grab the relevant files and output them in a nicely formatted tree.

As you can see, it ignores common directories in a VS code (Nuxt and Vue) project and in a Pycharm (Python) project. It also only grabs files with approved extensions.

function Print-Tree {
    param (
        [string]$Path,
@davehague
davehague / Powershell-Command-History.md
Created September 19, 2024 18:24
Powershell version of Linux's `history` command

Wouldn't it be nice if Powershell could simulate history | grep "alembic"? Now it can.

Place this in your Powershell profile (PS> $PROFILE to find the path)

function Get-CommandHistory {
    param (
        [string]$Pattern = "*"
    )
@davehague
davehague / undo-commit-with-sensitive-data.md
Last active November 8, 2024 16:16
Undoing a commit that includes sensitive data

If you accidentally perform a commit with sensitive data, I found this recovery approach to be fairly straightforward.

  1. (Optional) If you want to keep the file but not the changes, save off the file that has the secret. The command below will completely remove the file.
  2. Install Python if not already installed
  3. From command line pip install git-filter-repo
  4. Clone a fresh copy of the repository
  5. Run the command to remove the file
@davehague
davehague / ChatGPT Chat Extractor.md
Last active September 19, 2024 14:05
ChatGPT Chat Extractor

Index ChatGPT chats to local browser storage (IndexedDB)

Tampermonkey script
// ==UserScript==
// @name         ChatGPT Chat Extractor
// @namespace    http://tampermonkey.net/
@davehague
davehague / Chase-Partner-Offers-Bookmarklet.md
Last active September 19, 2024 14:05
Click all Chase Partner Offers Bookmarklet

Chase credit cards offer partner rebates, but you have to go in an manually click them. Use this script when you're on the offer page to click all of them, and then if you happen to purchase the item in the partner reward, you'll be alerted of a rebate via email!

Here's a guide on bookmarklets if you're not familiar with how they work.

Here's the code.

javascript:(function(){ var offers = document.querySelectorAll('div[data-testid="offerTileGridContainer"] mds-icon[type="ico_add_circle"'); if (offers) { var msg = `Found ${offers.length} unclicked offers!`; console.log(msg);  offers.forEach(function(offer) { var event = new MouseEvent('click', { bubbles: true, cancelable: true, view: window }); offer.dispatchEvent(event) }); var offerMessage = `Completed clicking ${offers.length} offers!`; alert(offerMessage) } else { alert('No element found with the specified data-testid.') }})() 
@davehague
davehague / html-live-reload.md
Last active September 19, 2024 14:05
Local Development - Live Reload for HTML/JS/CSS

Using NPM live server to watch HTML files. To avoid CORS issues and to work more quickly when developing a static HTML site locally, use a local server like live-server for development.

  1. Install live-server
npm install -g live-server
  1. Serve the project. Navigate to the root directory of your project and start live-server:
@davehague
davehague / Update Librechat.md
Last active September 19, 2024 14:05
Update Librechat

To pull the latest changes for LibreChat using Docker, while also considering the caching of images, you can follow these steps:

  1. Stop the running LibreChat container(s):
docker compose down
  1. CD to your librechat repository:
@davehague
davehague / Export Supabase Table Schemas.md
Last active September 19, 2024 14:05
Export Supabase Table Schemas

Setup

  1. Download and install pgAdmin
  2. Get your Supabase connection settings from the database settings page.

Export

In pgAdmin:

  1. Right click the schema and choose 'CREATE script' to script the schema
  2. Right click the schema and choose 'BACKUP...' to script the tables
@davehague
davehague / Supabase Multi-Project Project.md
Last active September 19, 2024 14:06
Supabase Multi-Project Project

Supabase only allows two projects to be active at any given time on their free tier. However, if you're like me and you like to explore and create a lot of projects, you'll be frustated with having to spin them down and up.

To solve this, use Postgres schemas. A PostgreSQL schema is a namespace that groups together database objects such as tables, views, indexes, data types, functions, and operators. It allows you to organize your data and objects within a database in a way that makes sense for your application.

Supabase actually has a page on how to use schemas. The short of it is below:

  1. Create a new schema
CREATE SCHEMA myproject