Skip to content

Instantly share code, notes, and snippets.

View petergi's full-sized avatar
💭
Just Busy Living On The Side Of A Square

Peter Giannopoulos petergi

💭
Just Busy Living On The Side Of A Square
View GitHub Profile
@petergi
petergi / Safely Inspect Docs Or Contents On A Specified Git Branch.sh
Created December 14, 2025 06:42
This is a neat little piece of shell judo. It’s doing capability detection against a Git repository and then falling back gracefully. Conceptually, this is the Unix philosophy in action: attempt the simplest thing, and if reality disagrees, degrade politely. In other words: optimistic, defensive, and mildly smug—in the best possible way.
# Try to show the contents of docs/ from the master branch.
# - git show works for files, but may fail for directories.
# - Suppress errors and limit output to 20 lines.
# - If that fails, fall back to listing files under docs/ instead.
# - Always show only the first 20 results to keep output predictable.
git show master:docs/ 2>/dev/null | head -20 \
|| git ls-tree -r master --name-only | grep '^docs/' | head -20
@petergi
petergi / Remove References in Git Branches.sh
Created December 14, 2025 05:53
Find and remove text from your branches. Just update the files you're targeting. e.g. md, txt, py, go, cs, etc... And of course the text your want to find and clean.
#!/bin/bash
# clean-branch-references.sh
# Branches to clean
BRANCHES=("master" "original" "go-version")
for branch in "${BRANCHES[@]}"; do
echo "Cleaning branch: $branch"
git checkout $branch
@petergi
petergi / Searching Through Git Branches.sh
Created December 14, 2025 05:40
Search through Git branches for particular text. In this case I am looking at reference to Anthropic or Claude.
# Search in files across all branches
git grep -i "claude\|anthropic\|generated with.*claude\|co-authored-by.*claude" $(git rev-list --all) -- ':(exclude)go.sum' ':(exclude)go.mod' | head -50
# Search in commit messages
git log --all --grep="Claude\|Generated with\|Co-Authored" --oneline
# Search for specific patterns in current branch
grep -r "Claude Code\|Co-Authored-By: Claude\|🤖 Generated" . --exclude-dir=.git --exclude-dir=build
@petergi
petergi / 90° Counter-Clockwise Image Rotation Script.py
Created December 13, 2025 23:36
This Python script walks a directory, finds images, and rotates any portrait-oriented image 90° counter-clockwise so it becomes landscape. # Landscape images are left alone. It also respects EXIF orientation, which saves you from the classic “why is this one upside down?” ritual.
from PIL import Image, ImageOps
import os
IMAGE_EXTENSIONS = (".jpg", ".jpeg", ".png", ".tiff", ".bmp")
def rotate_portrait_images(directory):
for filename in os.listdir(directory):
if not filename.lower().endswith(IMAGE_EXTENSIONS):
continue
@petergi
petergi / rename_pdfs.py
Created October 7, 2025 20:42
PDF file renaming utility based on metadata.
#!/usr/bin/env python3
"""PDF file renaming utility based on metadata."""
import os
import re
from PyPDF2 import PdfReader
def get_pdf_metadata(pdf_path):
"""
#!/usr/bin/env python3
"""
The Python script extracts metadata (title and author) from EPUB files and renames them based on the extracted information.
:param epub_path: The `epub_path` parameter in the `get_epub_metadata` function is the file path to the EPUB file from which you want to extract the title and author metadata. You should provide the full path to the EPUB file as a string when calling this function. For example, if
:return: Defines a Python script that extracts metadata (title and author) from EPUB files and renames the files based on this metadata. The `get_epub_metadata` function extracts the metadata from an EPUB file and returns a dictionary containing the title and author. The `rename_epubs` function renames EPUB files in a specified directory based on the extracted metadata.
"""
import os
import re
import xml.etree.ElementTree as ET
@petergi
petergi / RickRollQuickie
Created September 3, 2025 20:58
Never gonna give you up...
curl -sL https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash
@petergi
petergi / Generate a Data Dictionary for an MS SQL Database.sql
Last active July 8, 2025 16:44
After running these queries, you'll have all the information needed to create a comprehensive data dictionary document for your  database.
-- Data Dictionary Generation Queries
-- Run these queries sequentially to build your data dictionary
-- Data Dictionary Generation Queries
-- Run these queries sequentially to build your data dictionary
-- Each query provides different aspects of your database structure:
-- 1.Tables Overview - Lists all tables with descriptions
-- 2.Column Details - Complete column information including data types, nullability, and defaults
-- 3.Primary Keys - Identifies primary key constraints
-- 4.Foreign Keys - Shows table relationships

This is the simplest "hello world" example.

This example was generated with:

$ bashly init --minimal
$ bashly generate

In (N)Vim, you can perform search and replace operations using the :substitute command. Here are the basic steps and syntax for doing search and replace:

Basic Syntax

The basic command for search and replace in (N)Vim is:

:s/pattern/replacement/