Skip to content

Instantly share code, notes, and snippets.

View mwender's full-sized avatar
👨‍💻

Michael Wender mwender

👨‍💻
View GitHub Profile
@mwender
mwender / restart-redis.sh
Last active January 17, 2025 15:35
[Restart REDIS] Checks if REDIS is running and restarts if it isn't. #bash #REDIS #servers
#!/bin/bash
# Script to monitor and manage a Redis server.
# This script checks if Redis is running, executes a FLUSHALL command if it's down,
# sends email notifications, and rotates log files based on a specified age.
# Required Software:
# - redis-cli: Command-line interface for Redis.
# - sendmail: For sending email notifications.
# - awk: For processing log files.
@mwender
mwender / README.md
Last active December 23, 2024 19:42
[WordPress NGINX CDN Redirect Rules] Redirects not found requests in WP uploads to a CDN URL you define #nginx #wordpress

NGINX Configuration for Redirecting WordPress Uploads to a Production CDN

This configuration is designed to redirect all requests to the WordPress uploads directory (/wp-content/uploads/) to a specified production Content Delivery Network (CDN). This setup helps offload static media assets to the CDN, reducing load on the main server and improving load times.

Configuration Details:

  • The $production variable defines the CDN URL where the assets are located.
  • Requests for resources within /wp-content/uploads/ are first checked locally.
@mwender
mwender / applyPhoneMask.js
Created October 25, 2024 21:08
[applyPhoneMask.js] Phone number masking for text fields. #javascript
/**
* Apply phone number masking to a specified input field.
*
* This function attaches an input event listener to the form field identified by the given ID.
* It ensures that the phone number entered is formatted in the (XXX) XXX-XXXX pattern as the user types.
*
* The function removes non-digit characters from the input and limits the input length to 10 digits.
* It adjusts the formatting dynamically based on the number of digits entered:
* - Up to 3 digits: (XXX
* - 4 to 6 digits: (XXX) XXX
@mwender
mwender / heic-to-jpg.sh
Created August 15, 2024 20:02
[Convert .heic to .jpg] MacOS one-liner for converting all .heic files in current directory to .jpg #bash #imageprocessing
for f in *.heic; do sips -s format jpeg -s formatOptions 40 "$f" --out "${f%.heic}.jpg"; done
@mwender
mwender / elementor-omit-from-display.php
Created June 12, 2024 14:27
[Elementor Omit from Output] Provides a new control to keep Elementor from rendering a container. #elementor #wordpress
<?php
/**
* Taken from [Feature Request: Option to temporarily hide sections](https://github.com/elementor/elementor/issues/18183)
*/
(function() {
# Add new control after the Custom CSS control on the Advanced tab.
add_action(
'elementor/element/after_section_end',
function($element, $section_id, $args) {
if ($section_id === 'section_custom_css') {
@mwender
mwender / getimages.py
Created May 21, 2024 17:26
[SquareSpace Image Downloader] This python script downloads all images found in a SquareSpace site XML export. #python
import requests
import shutil
import xml.etree.ElementTree as ET
from bs4 import BeautifulSoup
import logging
# Setup basic logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Parse the XML and handle namespaces
@mwender
mwender / trending-posts-shortcode.php
Last active April 18, 2024 13:40
[WordPress Elementor Trending Posts Shortcode] In conjunction with the Post Views Counter plugin, the following provides a "trending_posts" shortcode for use in displaying an Elementor Loop Template #elementor #wordpress
@mwender
mwender / optimize-video-ffmpeg.sh
Created January 19, 2024 22:33
[Optimize video files with ffmpeg] One liners for optimizing video files from your command line. #cli
# Reduce the filesize of your .mov and convert to .mp4
#
$ ffmpeg -i input.mov -vcodec h264 output.mp4
# Adjust the resolution of your .mov and convert to .mp4
#
# - The following sets the width to 1280px with the
# height adjusting appropriately.
# - scale={$width}:{$height} - Specify one value and set
# the other to -1 to scale proportionately
@mwender
mwender / email-obfuscater.js
Last active January 18, 2024 16:42
[JS Email Obfuscater] Simple JavaScript to obfuscate "mailto" links.
/**
* Obfuscates email addresses in 'mailto' links to protect them from spam bots.
*
* This function first selects all anchor elements (<a>) in the document that have a 'href' attribute
* starting with 'mailto:'. For each of these mailto links, it retrieves the email address,
* obfuscates it, and then modifies the link's 'href' attribute to use a JavaScript code snippet
* for redirection. This obfuscation involves converting each character of the email address
* into its corresponding character code, joined by dots. Additionally, a click event listener
* is added to each link to handle the redirection in a user-friendly manner. When a user
* clicks on the obfuscated link, the browser redirects them to the actual 'mailto' link,
@mwender
mwender / link-elementor-pro-gallery-images.js
Last active January 17, 2024 19:49
[Elementor Pro Linked Gallery Images] Simple JS to add links to your Elementor Pro gallery images #elementor