Skip to content

Instantly share code, notes, and snippets.

View cgoldberg's full-sized avatar
👋
¯\_(ツ)_/¯

Corey Goldberg cgoldberg

👋
¯\_(ツ)_/¯
View GitHub Profile
@cgoldberg
cgoldberg / unarchive.sh
Created March 31, 2025 17:56
Bash function to extract any type of archive
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
@cgoldberg
cgoldberg / download_selenium_manager_local.sh
Created March 21, 2025 02:26
Bash script to download the Selenium Manager binary for AMD64 Linux
#!/usr/bin/env bash
#
# This script downloads the latest stable version of the `selenium-manager` binary
# for Linux (AMD64) from `https://github.com/SeleniumHQ/selenium_manager_artifacts/releases`
#
# When you run this script, it will download the binary to the current working directory.
if [ ! "$(uname -s)" == "Linux" ]; then
echo "this script only works on Linux"
exit 1
@cgoldberg
cgoldberg / download_selenium_manager.sh
Created March 21, 2025 02:24
Bash script to download the Selenium Manager binary for AMD64 Linux to be used with Python
#!/usr/bin/env bash
#
# This script downloads the latest stable version of the `selenium-manager` binary
# for Linux (AMD64) from `https://github.com/SeleniumHQ/selenium_manager_artifacts/releases`
#
# Before running this script, you should have the selenium repo cloned locally:
# $ git clone --filter=blob:none [email protected]:SeleniumHQ/selenium.git
#
# Make sure to set the `SELENIUM_HOME` variable below to match the repo's base directory.
#
@cgoldberg
cgoldberg / selenium_logging.py
Last active March 16, 2025 18:48
Python - Enable DEBUG logging for Selenium WebDriver
import logging
# add one of these logging configurations to your selenium script to enable logging.
# 6 logger levels are supported: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.
# (default is WARNING)
# enable DEBUG logging to console for all modules globally (selenium, urllib3, etc)
logging.basicConfig(level=logging.DEBUG)
# enable DEBUG logging to console for selenium module
@cgoldberg
cgoldberg / client.py
Last active February 20, 2025 07:55
Python Socket Client/Server - client sends a shell command, server runs received shell commands
import socket
HOST = '127.0.0.1'
PORT = 65432
COMMAND = 'whoami'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print('connecting to: {HOST}:{PORT}')
s.connect((HOST, PORT))
print(f'sending command: {command}')
@cgoldberg
cgoldberg / playlists.sh
Last active May 27, 2019 12:39
scan music library and create M3U playlists
## scan music library and create M3U playlists
# example shell commands:
# 500 random MP3's
find /path/to/music -type f -iname "*.mp3" | shuf | head -n 500 > 500_playlist.m3u
# All MP3's and FLAC's, sorted
find /path/to/music -type f \( -iname '*.mp3' -o -iname '*.flac' \) | sort > full_playlist.m3u
@cgoldberg
cgoldberg / next.sh
Last active December 20, 2018 17:17
bash - skip to next track on Squeezebox player via SlimServer/LogitechMediaServer
#!/usr/bin/env bash
# skip to next track on Squeezebox player via SlimServer/LogitechMediaServer
SQUEEZEBOX_SERVER='localhost:9000' # server host:port
SQUEEZEBOX_PLAYER='00:05:11:23:82:6e' # player MAC address
next () {
curl -sS -o /dev/null -X POST \
@cgoldberg
cgoldberg / file-rename-strip-digits.sh
Created October 8, 2018 21:54
shell one-liner - rename files in current directory with digits stripped from filenames
# rename files in current directory with digits stripped from filenames
# first do a dry-run (only print the commands that will be applied)
for f in *; do echo mv "$f" $(printf '%s' "$f" | tr -d '0123456789'); done
# run it for real (modifications done in-place)
for f in *; do mv "$f" $(printf '%s' "$f" | tr -d '0123456789'); done
@cgoldberg
cgoldberg / webdriver-unpacked-extension.py
Last active November 3, 2020 15:23
Python - Selenium WebDriver - Installing an unpacked Chrome Extension
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
unpacked_extension_path = '/path/to/unpacked/extension/'
options = Options()
options.add_argument('--load-extension={}'.format(unpacked_extension_path))
driver = webdriver.Chrome(options=options)
@cgoldberg
cgoldberg / webdriver-packed-extension.py
Last active July 8, 2021 17:48
Python - Selenium WebDriver - Installing a packed Chrome Extension
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
packed_extension_path = '/path/to/packed/extension.crx'
options = Options()
options.add_extension(packed_extension_path)
driver = webdriver.Chrome(options=options)