Skip to content

Instantly share code, notes, and snippets.

View pmacMaps's full-sized avatar

Patrick McKinney pmacMaps

  • Commonwealth of Pennsylvania
  • Harrisburg, PA
  • 21:08 (UTC -04:00)
View GitHub Profile
@pmacMaps
pmacMaps / convert_pdf_to_audio_file.py
Created June 18, 2025 14:42
Convert a PDF file into an MP3 file
# Note: logic in app created via Vibe Coding using ChatGPT. You can review conversation at https://chatgpt.com/share/6852cff0-13a0-800b-8b0d-96a655a387cb
# This script converts a pdf of text into a MP3 file. Can be useful to converting long reports into audio files.
from gtts import gTTS
from PyPDF2 import PdfReader
from pydub import AudioSegment
import os
import sys
# === PDF TEXT EXTRACTION ===
@pmacMaps
pmacMaps / youtube_music_download.py
Created June 11, 2025 15:23
Python functions to extract audio files from YouTube videos
"""
These functions allow you to create mp3 files from YouTube videos. The scripts were created using Vibe coding.
You can view the AI conversation at https://chatgpt.com/share/684995e4-aa14-800b-9ce5-f8c74cd34d9a.
Backup of conversation located at https://github.com/pmacMaps/pmacMaps.github.io/blob/ec99d84c3c3f88eb6bb1a8c93251f95ed38f2cde/assets/documents/Download_Audio_From_YouTube_ChatGPT_Chat_History.pdf
download_playlist_audio: extracts audio from all videos in a playlist
download_audio: extracts audio from a single video
download_audio_segment: extracts audio from a single video using a start and end time stamp
Notes: you will need ffmpeg installed on the machine running this script.
@pmacMaps
pmacMaps / remove_records_from_csv.py
Created February 11, 2025 15:09
Randomly remove records from a CSV file
# the majority of the script was created by ChatGPT responding to the prompt "is there a python function that can randomly remove records from a CSV file?"
import csv
import random
import sys
def remove_records(input_file, output_file, remove_fraction=0.1):
"""
Randomly removes a fraction of records from a CSV file.
@pmacMaps
pmacMaps / optimize_lyr.py
Created January 21, 2025 20:23
Apply Layer Optimization for Feature Service Hosted in ArcGIS Online
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
from print_errors import print_exception # helper module to printing error messages
from time import strftime as format_time
from time import sleep
def optimize(portal_url, username, password, item_id, lyr_idx, req_timeout=180):
"""
portal_url = URL for GIS portal; string
username: username of administrative user to portal; string
@pmacMaps
pmacMaps / export_ags_portal_site.py
Created April 17, 2024 14:49
Export ArcGIS Server Site & ArcGIS Portal Site Sample Scripts
# see https://developers.arcgis.com/rest/enterprise-administration/portal/export-site.htm
# import modules
from arcgis.gis import GIS
from os import environ
from os import path
from datetime import date
import logging
import sys
import requests
@pmacMaps
pmacMaps / run-ags-enterprise-patch-tool.bat
Created October 14, 2022 17:29
BAT file for checking ArcGIS Enterprise for patches, and installing them. Write messages to a text file for further review.
rem turn off console printing
@echo off
rem set variables for date components (used in log file name)
For /f "tokens=2-4 delims=/ " %%a in ("%DATE%") do (
SET YYYY=%%c
SET MM=%%a
SET DD=%%b
)
@pmacMaps
pmacMaps / download-earthbound-songs.py
Last active May 9, 2022 20:17
Extract mp3 file links and download songs from Earthbound video game
import sys
import requests
import os
from urllib.parse import urlparse
from bs4 import BeautifulSoup
# page containing links to mp3's of songs from Earthbound
music_page_url = 'http://starmen.net/mother2/music/'
# container for mp3 links
mp3_links = []
@pmacMaps
pmacMaps / wild_kratts_race_game_spinner.html
Last active January 13, 2021 15:09
Game Spinner for Wild Kratts Race Around the World Board Game
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spinner for Wild Kratts Race Around the World Game</title>
<meta name="description" content="A simple spinner app for the Wild Kratts Race Around the World board game.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
@pmacMaps
pmacMaps / shuffle-gis-day-exhibitors.js
Created November 13, 2020 13:30
Function to randomize order of Central PA GIS Day exhibitors
'use strict';
let shuffleArray = array => {
let m = array.length, t, i;
// While there remain elements to shuffle
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
@pmacMaps
pmacMaps / clip_layers_by_other_layers.py
Created June 24, 2020 15:26
Function and demo to Use ArcPy Search Cursors to loop through a layer and clip other layers by each feature in that layer
# Note: this script is designed to run with Python 3 and ArcGIS Pro ArcPy
# import modules
# arcpy => provides access to Esri ArcGIS Pro
# os => provides convient way to construct file paths
# sys => provides way to capture errors
# re => used for snake case helper function (taken from https://www.30secondsofcode.org/python/s/snake)
import arcpy, os, sys
from re import sub