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 / 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/
@petergi
petergi / Kill the process running on a specific port.sh
Created June 26, 2025 15:18
Kill whichever process is running on the given port
# Kill the process running on a port
lsof -t -t:port 1 xargs kill
@petergi
petergi / Export your notes to Markdown from OneNote on Mac.sh
Last active June 26, 2025 15:15
This command will convert each .docx file in the directory to a Markdown file with ATX-style headers. If you prefer Setext-style headers, you can replace atx with setext.
# 1 - Export to Word Document: First, export your OneNote pages to a .docx (Word) format using the OneNote export feature from the File menu.
# 2 - Install Pandoc: Install Pandoc on your Mac (https://gist.github.com/petergi/dcfe4279bb9c586463d0c4936a0738df#file-install-pandoc-on-macos-sh).
# 3 - Convert to Markdown: Use the terminal to navigate to the directory where your .docx files are saved.
# Run the following command to convert the .docx files to Markdown:
for file in *.docx; do
pandoc -f docx -t markdown_strict -i "$file" -o "${file%.docx}.md" --wrap=none --markdown-headings=atx
done
@petergi
petergi / Install Pandoc on macOS.sh
Created June 26, 2025 15:11
You can use Conda, Ports, Homebrew or the Installer Package directly (https://pandoc.org/installing.html) But seriously do yourself a favor just use Homebrew! Using Homebrew: Homebrew is a popular package manager for macOS that simplifies the installation process. If you don't have Homebrew installed, you can install it by running the following …
# If you don't already have it.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Once Homebrew is installed, you can install Pandoc by running:
brew install pandoc
@petergi
petergi / lsof examples.sh
Created May 7, 2025 14:25
You know.. a couple of handy examples of how to use lsof...
# Find what's using a volume on macOS
lsof | grep /Volumes/
# Check what processes are listening on port
lsof -iTCP -sTCP:LISTEN -P -n
# Kills a process using PID
#
# awk grabs the PIDs.
# tail gets rid of the pesky first entry: "PID".