Skip to content

Instantly share code, notes, and snippets.

import os
import shutil
from pathlib import Path
from zipfile import ZipFile
from datetime import datetime
from PIL import Image
import pillow_heif
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.panel import Panel
@benlacey57
benlacey57 / Media Copy
Last active November 24, 2025 01:09
Shell script to copy TV series and movies into Jellyfin at random.
#!/bin/bash
#############################################################################
# Media File Organisation Script
# Purpose: Randomly copy movies, TV shows, and Christmas content from
# multiple media drives to organised destination folders
#############################################################################
set -euo pipefail
IFS=$'\n\t'
@benlacey57
benlacey57 / main.py
Created May 24, 2025 07:40
Free Proxy Scraping and Testing Tool
# Version 2
pip install requests bs4 gspread oauth2client
import csv
import logging
import os
import requests
import time
import datetime
@benlacey57
benlacey57 / CompressImages.py
Last active May 19, 2025 20:14
Python script to resize and compress images
# Image Compression and Conversion Script
# Author: Ben Lacey
# Version: 1.1
# Website: benlacey.co.uk
# Changes made:
# 1. Added a new `--rename` argument to accept a template string
# 2. Created a `generate_filename_from_template` function to handle template substitutions
# 3. Updated the `process_image` function to include counter and use the template
# 4. Added logging to show renamed filenames
@benlacey57
benlacey57 / Scraper.py
Created April 27, 2025 11:36
Python Web Scraping example using playwright
"""
Advanced Web Scraper with Playwright
This script demonstrates a robust web scraping approach using Playwright that:
- Uses proper browser headers to reduce detection
- Implements logging to track execution
- Follows scraping best practices
- Handles common scraping errors
- Saves scraped data to CSV
"""
@benlacey57
benlacey57 / block_manager.sh
Last active April 27, 2025 00:10
This script manages IP blocking based on server logs analysis. It detects # suspicious activity patterns and automatically blocks offending IP addresses # for a configurable period. Blocks are managed in a separate file that is # included in the main .htaccess file to prevent overwrites during manual edits.
#!/bin/bash
# Multi-Server IP Block Manager
# Author: Ben Lacey (https://benlacey.co.uk)
# Version: 1.1
# Date: 2025-04-27
@benlacey57
benlacey57 / BlockSuspectIPs.sh
Created April 26, 2025 23:27
Analyse Server Logs and Automatically Block IPs
#!/bin/bash
# Configuration
LOG_FILE="/var/log/apache2/access.log"
ERROR_LOG="/var/log/apache2/error.log"
HTACCESS_FILE="/var/www/html/.htaccess"
BLOCK_LOG="/var/log/ip_blocks.log"
DEFAULT_BLOCK_DAYS=7
MAX_FAILED_ATTEMPTS=5
THRESHOLD_PERIOD="10 minutes"
@benlacey57
benlacey57 / video-blocker.js
Created April 22, 2025 11:13
JavaScript video download and screenshot prevention
document.addEventListener('DOMContentLoaded', function() {
const video = document.getElementById('protected-video');
// Prevent right-click menu (basic download blocking)
video.addEventListener('contextmenu', function(e) {
e.preventDefault();
alert("Video downloading is not allowed");
});
// Disable controls that might allow download
For Laravel Socket.io implementation with authentication, here's a complete example:
// SERVER SIDE (Laravel)
// In your BroadcastServiceProvider.php
public function boot()
{
Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');