Skip to content

Instantly share code, notes, and snippets.

View cgoldberg's full-sized avatar
🐢
compiling!

Corey Goldberg cgoldberg

🐢
compiling!
View GitHub Profile
@cgoldberg
cgoldberg / README.md
Last active December 5, 2025 20:36
Python SHA512 Benchmark

super simple hash benchmark


  • run a loop a half million times:
    • split a delimited string into 5 fields
    • strip invalid characters from each field with a regex
    • calculate a SHA3-512 hash and get the digest for each field (2.5 million hashes)

Environment:

@cgoldberg
cgoldberg / sftp.py
Created November 14, 2025 00:14
Python - transferring files with SFTP using paramiko
#!/usr/bin/env python3
#
# transferring files with SFTP
# https://www.paramiko.org
import paramiko
class SFTP:
def __init__(self, host, user, password, port=22):
@cgoldberg
cgoldberg / selenium_chrome_extension.py
Last active November 12, 2025 20:16
Python - load a Chrome extension using Selenium BiDi
# load a Chrome extension using Selenium BiDi
import os
from selenium import webdriver
# using unzipped extension in ./extensions/my-extension/
path = os.path.join(os.getcwd(), "extensions", "my-extension")
options = webdriver.ChromeOptions()
options.enable_bidi = True
@cgoldberg
cgoldberg / current_year_prs.sh
Created October 28, 2025 13:27
Show GitHub Pull Requests in owner/repo created in the current year
#!/usr/bin/env bash
#
# Show GitHub Pull Requests in owner/repo created in the current year
#
# usage: current_year_prs.sh <owner> <repo>
#
# requires: jq
set -o pipefail
@cgoldberg
cgoldberg / selenium-bidi-network-logging.py
Created October 13, 2025 14:26
Python - Selenium BiDi - Network Request Logging
# Selenium BiDi - Network Request Logging
# - launch Chrome
# - add a request handler that logs all HTTP headers from reqests made during page load
# - navigate to a web page
# - remove request handler
# - quit Chrome
import pprint
from selenium import webdriver
@cgoldberg
cgoldberg / selenium-logging.py
Last active November 12, 2025 20:18
Python/Selenium - launch Chrome and load a web page with all possible logging enabled
# launch Chrome and navigate to a web page with all console logging enabled
# - chrome/chromedriver logs go to STDOUT
# - captured driver/performance logs go to STDOUT
# - selenium debug logs go to STDERR
import logging
from subprocess import STDOUT
from selenium import webdriver
@cgoldberg
cgoldberg / install-chrome-dependencies.sh
Created September 22, 2025 20:48
Chrome for Testing - install Debian Linux system dependencies
#!/usr/bin/env bash
#
# Chrome for Testing - install Debian Linux system dependencies
# - visit the CfT Dashboard: https://googlechromelabs.github.io/chrome-for-testing
# - download 'chrome-linux64.zip' for the version you need
# - unzip it and run this script
deps_file="chrome-linux64/deb.deps"
if [ "${EUID}" -ne 0 ]; then
@cgoldberg
cgoldberg / generate_monorepo_sboms.py
Last active September 12, 2025 23:02
Python - Generate language specific SBOMs from a multi-language monorepo on GitHub
#!/usr/bin/env python3
#
# Copyright (c) 2025 Corey Goldberg (https://github.com/cgoldberg)
# License: MIT
#
# Generate language specific SBOMs from a multi-language monorepo on GitHub
# - fetches repo-wide SBOM from GitHub
# - generates individual SBOMs for each language specified
#
# requires:
@cgoldberg
cgoldberg / hash-sha3-512.py
Created September 4, 2025 13:04
Python - Generate a SHA3-512 hash with optional salt
# Generate a SHA3-512 hash with optional salt
import re
# requires pycryptodome
# - https://pycryptodome.readthedocs.io/en/latest/src/hash/sha3_512.html
from Crypto.Hash import SHA3_512
def generate_hash(s, salt=None):
@cgoldberg
cgoldberg / monkeypatch_partialmethod.py
Created August 20, 2025 18:34
Python - monkeypatch a method on a class and call the original method from the new one
#!/usr/bin/env python
#
# monkeypatch a method on a class and call the original method from the new one
from functools import partialmethod
class MyClass:
# this is the original method