Skip to content

Instantly share code, notes, and snippets.

View basperheim's full-sized avatar

Benji Asperheim basperheim

View GitHub Profile
@basperheim
basperheim / fix-yarn-corepack-macos-homebrew.md
Created December 22, 2025 20:44
Fixing "packageManager: [email protected]" projects when Yarn 1.x is shadowing Corepack (macOS/Homebrew)

Fixing "packageManager: [email protected]" projects when Yarn 1.x is shadowing Corepack (macOS/Homebrew)

This is the "Yarn 4 project, but my shell keeps running Yarn 1.22" problem.

You'll see an error like:

This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22. ...the project is meant to be used with Corepack...

What happened

@basperheim
basperheim / macos-homebrew-python-setup.md
Last active December 15, 2025 18:04
macOS + Homebrew + Python venvs (Pinned to 3.12 for Pygame) — A Practical Setup + Gotchas

macOS + Homebrew + Python venvs (Pinned to 3.12 for Pygame) — A Practical Setup + Gotchas

This gist is the "do it once, stop suffering" setup for macOS (Apple Silicon) where:

  • Homebrew's default python3 is too new for your project (ex: Python 3.14 breaks/doesn't have stable wheels for stuff like Pygame yet)
  • macOS still has /usr/bin/python3 (often 3.9.x) and it silently wins when Homebrew isn't configured how you think
  • you want a project-local venv that is always Python 3.12, with pip installs going into the venv (no PEP 668 drama)
  • you also want IDLE/Tkinter to work on 3.12 (optional)

This documents the exact failures I hit and the final working config.

@basperheim
basperheim / create_gifs_macos_screen_record.py
Created November 28, 2025 18:51
Turn macOS Screen Recordings into GIFs and Screenshots
#!/usr/bin/env python3
"""
Batch-convert .mov/.MOV QuickTime videos in the current directory:
1. Find all .mov/.MOV files.
2. For each:
- Convert to MP4 (H.264, no audio, slightly reduced quality).
- Generate a high-quality GIF from the MP4.
- Extract JPEG screenshots from the GIF every 1 second.
- If everything succeeds, delete the original .mov/.MOV file.
@basperheim
basperheim / python-venv-tutorial.md
Last active December 7, 2025 15:24
Ultimate Python Venv Tutorial and Guide

Ultimate Python Venv Tutorial and Guide

This is a practical, opinionated guide to Python virtual environments on POSIX/macOS/Linux with a few Windows notes. It shows the cleanest workflows that don't bite you later: create/activate, install via pip and requirements.txt, run scripts with reliable logging/printing, deactivate/uninstall/remove, common gotchas, when to upgrade pip/setuptools/wheel, and a Zsh prompt that shows the active venv in red. It also explains what a venv does and doesn't do (spoiler: you can still build Go, run Docker, etc.).


Why venvs (in one paragraph)

Python versions and packages vary per project. A venv creates an isolated interpreter + site-packages so each project can pin its own dependencies without polluting system or Homebrew installs. On macOS/Homebrew you usually only have python3 globally; once you activate a venv, you get a project-local python.

@basperheim
basperheim / ollama-reference-guide.md
Last active November 11, 2025 12:43
Ollama: Practical Reference (macOS · Linux · Windows)

Ollama: Practical Reference (macOS · Linux · Windows)

Local LLMs with a Docker-like CLI. This doc shows how to install, run, manage RAM/disk usage, and clean up.

TL;DR (cheat-sheet)

# install (mac)
brew install --cask ollama-app   # or: brew install ollama
@basperheim
basperheim / README.md
Last active October 13, 2025 14:44
Use Python/Vosk to Create Transcripts from Audio Files

Vosk Transcriber (MP3/WAV → Text)

A small Python CLI that transcribes audio using Vosk. If you pass an .mp3, it automatically converts to a 16 kHz mono WAV via ffmpeg and then transcribes. If you pass a .wav, it transcribes directly.


@basperheim
basperheim / README.md
Last active November 4, 2025 13:45
Focused Git diffs for humans and LLMs: prints only meaningful changed files (skips assets/vendor dirs), groups by file with headers, and supports path filtering—perfect for pasting compact context into prompts.

git_diff_filtered — focused diffs for humans and LLMs

A small Bash function that prints only the meaningful parts of your Git diff, skipping asset/vendor directories and binary-ish files. Output is grouped by file with a clear header, making it ideal for quickly reviewing changes or pasting compact, high-signal code context into LLM prompts.

Why

  • Less noise, more signal. Excludes node_modules/, .yarn, .astro, and common binary/extensions by default.
  • LLM-friendly. Keeps diffs tight to save tokens and reduce hallucinations; per-file headers help models understand boundaries.
  • Convenient. One call prints all filtered diffs, or you can narrow to a path.
@basperheim
basperheim / tetris.py
Created August 12, 2025 14:14
Tetris clone written in Python using the Pygame high-level SDL wrapper.
#!/usr/bin/env python3
# Tetris clone in Python + Pygame
# No assets needed. Run: python tetris.py
# Controls:
# Left/Right: move
# Down: soft drop
# Up / X: rotate CW
# Z: rotate CCW
# Space: hard drop
# P: pause
@basperheim
basperheim / README.md
Last active August 5, 2025 21:05
Fast, Flexible Directory Tree & File Preview Tool for Sharing Context with LLMs

detailed_tree.sh

A robust, cross-platform shell function for quickly sharing a directory’s structure and previewing file contents.
Ideal for collaborating with others, sharing context with ChatGPT or other LLMs, or just auditing a codebase without manually sifting through files.


Features

  • Smart Exclusions
@basperheim
basperheim / replace_special_char_markdown.py
Last active November 4, 2025 13:44
Removes special LLM-injected characters from markdown files in order to "normalize" the markdown content.
#!/usr/bin/env python3
import argparse
import os
import sys
import re
# directories to skip entirely
EXCLUDE_DIRS = {'node_modules', 'target', 'bin', '__pycache__', 'build', 'dist'}
MARKDOWN_LINK = re.compile(r'(!?\[.*?\])\((.*?)\)') # matches [text](url) and ![alt](url)