Skip to content

Instantly share code, notes, and snippets.

View coulterpeterson's full-sized avatar
🤓
Always learning

Coulter Peterson coulterpeterson

🤓
Always learning
View GitHub Profile
@coulterpeterson
coulterpeterson / snippets.sh
Created November 3, 2023 14:57
Ubuntu Runaway Web Server Fire Fighting Toolbelt (Restarting Various Processes)
# Start with the obvious
sudo shutdown -r now
# Check CPU/memory usage
top
# Get running services
systemctl --type=service --state=running
# Start restarting them
@coulterpeterson
coulterpeterson / delete_memberships_by_id.py
Last active October 30, 2023 21:04
Batch Delete WooCommerce Memberships by ID (WooCommerce REST API in Python)
# Name: Delete Memberships by ID
# Description: A simple, command-line parameter driven script for deleting WooCommerce memberships by membership ID. Accepts a CSV input.
# Author: Coulter Peterson
# Author URL: https://coulterpeterson.com
# Dependencies to install via pip: requests, pandas
import os
import sys
import argparse
import requests
@coulterpeterson
coulterpeterson / hideTaskbar.bat
Created October 24, 2023 13:51
Force Windows Taskbar to Re-Hide Itself in Windows 10+
REM Hide Taskbar and Kill Explorer to Make It Restart (Credit to https://stackoverflow.com/a/47202007)
powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
@coulterpeterson
coulterpeterson / readme.md
Last active October 18, 2023 19:57
How To Import a Bedrock WordPress Project Into LocalWP

How To Import a Bedrock WordPress Project Into LocalWP

  1. Per the official doc from Bedrock, start by creating a new site in Local.
  2. Use the "open site folder" or "open site shell" option, delete the public folder in \Local Sites\YOURSITE\app\
  3. While in \Local Sites\YOURSITE\app, clone your project down into this folder.
  4. Open the .env file in app\YOURREPO\src and ensure:
    • DB_NAME=local
    • DB_USER=root
    • DB_PASSWORD=root
  • WP_HOME='https://YOURSITE.local'
@coulterpeterson
coulterpeterson / snippet.bat
Last active October 17, 2023 15:53
Revive SMB When It Conks Out
# Enable SMB1: Thanks Vasily Sosnovsky at https://learn.microsoft.com/en-us/answers/questions/815154/cant-connect-to-smb-share-windows-cannot-access
DISM /Online /Enable-Feature /All /FeatureName:SMB1Protocol
@coulterpeterson
coulterpeterson / snippet.sh
Last active October 11, 2023 19:56
List and Export MySQL/mariaDB Databases
# Login to find your db name (optional)
mysql -u username -p
SHOW DATABASES;
EXIT;
# Export
mysqldump -u username -p dbname | gzip > dump.sql.gz
# Copy it from server to local (optional)
@coulterpeterson
coulterpeterson / snippet.html
Created October 4, 2023 18:23
Automatically Updating Copyright Year via JS
<!-- Slick JS 1-liner credit to https://stackoverflow.com/a/4562604 -->
<span>© <script>document.write(new Date().getFullYear())</script> Your Company</span>
@coulterpeterson
coulterpeterson / snippet.php
Created September 19, 2023 20:57
GP Populate Anything Register Custom Data Object
<?php
add_action( 'plugins_loaded', 'register_object' );
function register_object() {
if ( class_exists( 'GP_Populate_Anything' ) && class_exists( 'GPPA_Object_Type' ) ) {
// For a starter class file, you can copy one from source like
// wp-content\plugins\gp-populate-anything\includes\class-object-type-post.php
require_once plugin_dir_path( __FILE__ ) . 'includes/class-object-type-YOURTYPE.php';
gp_populate_anything()->register_object_type( 'yourtype', 'GPPA_Object_Type_YOURTYPE' );
@coulterpeterson
coulterpeterson / snippet.sh
Created September 18, 2023 20:39
Git ignore chmod file permission changes
# Credit https://stackoverflow.com/a/1580644
git config core.fileMode false
@coulterpeterson
coulterpeterson / wordpress-multi-file-upload-snippet.php
Last active September 18, 2023 19:45
WordPress Multi File Upload Helper Function
/**
* Takes in a PHP multi file form field (that uses the name="identifer[]" bracket notation), uploads each attachment,
* provides them with attachment ids, then cleans up after itself.
* Returns: array of attachment ids.
* Example usage: $attachment_ids = multi_file_media_upload($_FILES['multi-upload-field']);
* Example form input field: <input name="myfiles[]" type="file" multiple="true" />
*/
function multi_file_media_upload($multiFile) {
// TODO: Test which of these can be removed for file upload functions used
require_once(ABSPATH . 'wp-admin/includes/media.php');