Skip to content

Instantly share code, notes, and snippets.

View basperheim's full-sized avatar

Benji Asperheim basperheim

View GitHub Profile
@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 July 22, 2025 23:50
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)
@basperheim
basperheim / search_angular_components.py
Last active July 17, 2025 13:05
Python script that prints Angular custom component methods declared in a component TS file, and also prints how they are used.
import os
import re
import argparse
from collections import defaultdict
# ---------------------------------------------------------
# Step 0: Utility Functions
# ---------------------------------------------------------
def find_parent_method(lines, call_line_num):
"""
@basperheim
basperheim / top-seo-keywords.csv
Created June 30, 2025 15:35
Some Popular SEO Keywords of 2024-25
We can't make this file beautiful and searchable because it's too large.
keyword,searches,visits
Chatgpt,24900000,8092500
chaat gbt,24900000,8092500
chaat gpt,24900000,8092500
chact gpt,24900000,8092500
chadgbt,24900000,8092500
chag gpt,24900000,8092500
chap gpt,24900000,8092500
chast gpt,24900000,8092500
chatb gpt,24900000,8092500
@basperheim
basperheim / create_video.sh
Created June 11, 2025 12:56
Use FFmpeg to create a video from an image and audio file
#!/bin/bash
# generate_video() {
# local config_file="$1"
# if [[ ! -f "$config_file" ]]; then
# echo "JSON config file not found: $config_file"
# return 1
# fi
@basperheim
basperheim / purge_docker_macos.sh
Created June 10, 2025 13:43
Removes Docker Desktop from macOS
#!/bin/bash
# Uninstall Script
if [ "${USER}" != "root" ]; then
echo "$0 must be run as root!"
exit 2
fi
while true; do
@basperheim
basperheim / ffmpeg_helpers.sh
Last active June 19, 2025 23:27
FFmpeg bash helper functions (should work well on macOS or Linux)
# Convert HH:MM:SS or HH:MM:SS.mmm to seconds with better handling
time_to_seconds() {
local time_str=$1
local IFS=':.'
read -r hours minutes seconds milliseconds <<< "$time_str"
# If milliseconds are not provided, set them to zero
local milliseconds=${milliseconds:-0}
# Ensure milliseconds are padded to three digits
while [ ${#milliseconds} -lt 3 ]; do
@basperheim
basperheim / find_dupes.py
Created May 27, 2025 22:24
Compares file hash for files in a directory and deletes certain duplicates
import os
import hashlib
import argparse
import logging
from difflib import SequenceMatcher
# Usage: python3 find_dupes.py ~/Downloads/audiobooks
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@basperheim
basperheim / find_large_files.py
Created May 27, 2025 22:22
Python script that finds large files in a directory
import os
import argparse
import logging
# Usage: python3 find_large_files.py ~/Movies
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Directories to ignore while scanning