Skip to content

Instantly share code, notes, and snippets.

View ksemel's full-sized avatar

Katherine Semel-Munson ksemel

View GitHub Profile
@ksemel
ksemel / diffmerge.sh
Created January 10, 2020 21:50
Bash: Check for diffs, and only open the merge tool if diffs are found.
#!/bin/bash
#
# Check for diffs, and only open the merge tool if diffs are found.
#
dir=$FIRSTDIRECTORY
dir2=$SECONDDIRECTORY
cd "$dir"
@ksemel
ksemel / code_sniffer.sh
Created January 23, 2017 21:41
Install PHP CodeSniffer and other dependencies
#!/bin/bash
# Install PHP Code Sniffer and related modules
TMP_PATH=/tmp/
BIN_PATH=/usr/local/bin/
cd $TMP_PATH
# PHPCS
# PHP Code Sniffer
@ksemel
ksemel / scp_foundation_add_names.user.js
Last active March 7, 2021 19:41
SCP Foundation: Add names to details pages: Adds the descriptive names from the SCP series index page to the individual detail pages, and provides previous and next buttons to navigate through SCPs.
// ==UserScript==
// @name SCP Foundation: Add names to details pages
// @namespace https://gist.github.com/ksemel/3e189fef865a02ee9956
// @description Adds the descriptive names from the SCP series index page to the individual detail pages, and provides previous and next buttons to navigate through SCPs.
// @author Katherine Semel
// @date 2011-09-02
// @revision 2021-03-07
// @version 3.0
// @include /(?:scp-wiki\.wikidot\.com)\/(?:adult:)?(scp-[0-9]+)/
// @grant GM_xmlhttpRequest
@ksemel
ksemel / get_current_screen.php
Created May 28, 2014 15:57
use get_current_screen() to narrow the scope of a function
function admin_footer(){
$screen = get_current_screen();
if ( isset( $screen->base ) && $screen->base == 'profile' ) {
echo "<script type='text/javascript'>
if( jQuery('#GA_enabled').is(':checked') === false ) {
ShowOrHideQRCode();
}
</script>";
}
}
@ksemel
ksemel / functions.php
Created May 19, 2014 23:29
Basic non-class functions.php set up
<?php
function Init_My_Theme() {
// Declare all your add_action and add_filter here so they all run when you call the init function
// Add the custom taxonomies
add_action( 'init', 'My_Theme_register_custom_taxonomy', 1 );
// On the posts page, add a column
add_filter( 'manage_posts_columns', 'My_Theme_add_taxonomy_column', 10, 1 );
@ksemel
ksemel / query-cache.sql
Created May 10, 2014 16:25
Check if the Query Cache is enabled, and in use
# Check Query Cache Status
# is query cache available
SHOW VARIABLES LIKE 'have_query_cache';
# What is the cache set for?
SHOW VARIABLES LIKE 'query%';
# How much is actually used?
SHOW STATUS LIKE 'Qc%';
@ksemel
ksemel / woocommerce_override_css.php
Created May 9, 2014 17:06
Swap out the default WooCommerce stylesheets for your own
<?php
add_action( 'init', 'woocommerce_overrides', 99 );
function woocommerce_overrides() {
add_filter( 'woocommerce_enqueue_styles', 'switch_to_theme_css', 10, 1 );
}
function switch_to_theme_css( $styles ) {
$styles[ 'woocommerce-layout' ][ 'src' ] = get_template_directory_uri()."/assets/css/woocommerce-layout.css";
@ksemel
ksemel / orphans-post_meta.sql
Last active October 5, 2015 18:25
Delete WordPress Orphans in post_meta and taxonomy tables
# Delete Orphaned Post Meta
# Selects all postmeta where the post_id does not exist
SELECT * FROM wp_postmeta WHERE post_id NOT IN (SELECT DISTINCT ID FROM wp_posts) AND meta_id BETWEEN 1 AND 500000;
# Use an offset to avoid super massive queries!
# Make sure to offset the META_ID ( not the post_ID ) or you'll delete good data
# Set 1
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT DISTINCT ID FROM wp_posts) AND meta_id BETWEEN 1 AND 500000;
@ksemel
ksemel / top-ten-wp-mysql.sql
Last active February 17, 2021 21:07
Get top-ten lists of post sizes from WordPress database
# Find Table Sizes
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
@ksemel
ksemel / local.htaccess
Last active August 29, 2015 13:57
Run your WordPress site locally without copying down all your images
# BEGIN WordPress
<IfModule mod_rewrite.c>
# Single site Rules (with image pass-back)
###################################################
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# if it is an image that doesn't exist, try prod