Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / install-xdebug.sh
Created April 19, 2020 02:16
Install xdebug from the command line.
# Use homebrew to switch PHP versions, run this command for each version as needed:
pecl install xdebug
@wpscholar
wpscholar / grep-status-codes.sh
Last active October 6, 2023 17:46
How to use grep to lookup status codes in access logs.
# Output the access log
cat access.log
# Run the results through grep to find any 500 status codes
cat access.log | grep "[: ]500[: ]"
# Find any non 200 status codes
cat access.log | grep -v "[: ]200[: ]"
# Find multiple status codes
@wpscholar
wpscholar / unstick-valet-php-version.sh
Created March 18, 2020 16:40
What to do when Laravel Valet won't let you change PHP versions even though you ran `valet use php@7.4`
brew services stop php@7.3
brew services start php@7.4
valet restart
@wpscholar
wpscholar / create-database.sql
Created March 13, 2020 12:20
Create a MySQL database
CREATE DATABASE <name>;
GRANT ALL PRIVILEGES ON <name>.* TO "<user>"@"localhost";
FLUSH PRIVILEGES;
@wpscholar
wpscholar / brew-setup-mysql.sh
Created March 13, 2020 12:18
Setup MySQL using Brew
brew install mysql
brew services start mysql
# Set password to be 'root' for the root user
$(brew --prefix mysql)/bin/mysqladmin -u root password root
@wpscholar
wpscholar / cypress--support--commands.js
Created January 22, 2020 21:12
Cypress setup for conditional WordPress login. (Double dashes in file names should be replaced with slashes)
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
@wpscholar
wpscholar / remember-me.php
Created January 21, 2020 15:44
By default, WordPress will log you out when you close your browser. If you check 'Remember Me' WordPress will keep you logged in for 2 weeks. Your web browser stores a cookie that WordPress checks to see if you are logged in. It is possible to set the expiration for that cookie for longer than 2 weeks when a user checks the 'Remember Me' option.…
<?php
add_filter( 'auth_cookie_expiration', function() {
return 31556926; // 1 year in seconds
} );
<?php
/*
* Plugin Name: Auto-Redirect Root-Level Posts
* Plugin URI: https://gist.github.com/wpscholar/d37736b1b9c2439acf2289364e210bc5
* Description: Automatically redirects root level posts (e.g. /my-blog-post) to the new location (e.g. /blog/my-blog-post). Use anytime you update your post permalink structure from root-level to use a subdirectory prefix.
* Version: 1.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* License: GPL2
@wpscholar
wpscholar / buffer-to-stream.js
Created October 10, 2019 20:27
Convert a buffer to a stream in Node.js
/**
* Convert a buffer to a stream
*
* @param binary Buffer
* @returns Readable
*/
function bufferToStream(binary) {
return new Readable({
read() {
this.push(binary);
@wpscholar
wpscholar / base64.js
Created October 10, 2019 20:26
Utility functions for base64 encoding/decoding for buffers in Node.js
/**
* Take a file and convert to a base64 encoded string.
*
* @param buffer A Buffer instance.
* @returns {string} A base64 encoded string.
*/
function base64Encode(buffer) {
return new Buffer.from(buffer).toString('base64');
}