Skip to content

Instantly share code, notes, and snippets.

View petertoi's full-sized avatar

Peter Toi petertoi

View GitHub Profile
# Use live site assets.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{HTTP_HOST} ^local\.com$
RewriteRule ^(.*\.(png|jpe?g|gif)) http://production.com/$1 [L,R=302,NC]
</IfModule>
@petertoi
petertoi / wp-delete-orphaned-postmeta.sql
Last active December 7, 2017 17:33
SQL Query for deleting orphaned postmeta from WordPress database
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL
@petertoi
petertoi / nginx-wp-rewrite-uploads.conf
Last active January 18, 2018 21:14
Nginx rewrite to request WordPress uploads from external domain
location ~ ^/wp-content/uploads/(.*) {
if (!-f $request_filename) {
rewrite ^/wp-content/uploads/(.*)$ http://EXTERNAL_URL/wp-content/uploads/$1 redirect;
}
}
@petertoi
petertoi / vvv-redirect-wpmu-files.conf
Last active August 29, 2015 14:21
nginx snippet for redirecting local VVV WPMU dev site /files to another domain
# Be sure to comment out the /files rules in /vagrant/config/nginx-config/nginx-wp-common.conf
# then add this to the bottom of the your /vagrant/config/nginx-config/sites/domain.conf
# replace 'domain' with the domain associated with your project
if ($http_host ~ (.*)\.domain\.dev) {
set $subdomain $1;
}
location ~ ^/files/(.*) {
rewrite ^/files/(.*)$ http://$subdomain.domain.com/files/$1 redirect;
}
@petertoi
petertoi / digall.sh
Created April 15, 2015 21:06
List all DNS records in a domain using dig
#!/bin/sh
#
# Author: Peter Toi
# Source: https://gist.github.com/petertoi/8f7e42b867cbb85ec47b
#
# Usage 1: $ digall.sh # No argument will prompt for domain
# Usage 2: $ digall.sh domain # Skip the prompts by including the domain as an argument
if [ "$#" -eq 1 ]
then
@petertoi
petertoi / dh_installnode.sh
Last active April 18, 2020 00:53
Install Node.js on Dreamhost shared hosting
#!/bin/sh
NODEVERSION=v0.12.2
SRCPATH=$HOME/src/node
LOCALPATH=$HOME/usr/local
BINPATH=$LOCALPATH/bin
mkdir -p $SRCPATH
mkdir -p $LOCALPATH
@petertoi
petertoi / injectionscan.sh
Last active August 29, 2015 14:17
Script for searching all .php files for evidence of PHP injections
#!/bin/sh
#
# Author: Peter Toi
# Source: https://gist.github.com/petertoi/23d072d1d8589d9f5386
#
# Usage 1: $ injectionscan.sh
rm -fr injections.txt
touch injections.txt
@petertoi
petertoi / check_plugin_version.sh
Created March 13, 2015 15:43
Performs a recursive scan from the current directory for the specified file and outputs matched files and plugin version
#!/bin/sh
#
# Author: Peter Toi
# Source: https://gist.github.com/petertoi/79d77b041f1f8f93c456
#
# Usage 1: $ check_plugin_version.sh # No argument will prompt for plugin file name
# Usage 2: $ check_plugin_version.sh pluginfile # Skip the prompts by including the file name as an argument
if [ "$#" -eq 1 ]
then
@petertoi
petertoi / wgetseq.sh
Created February 23, 2015 14:46
Download sequentially named files from command line
#!/bin/bash
#
# Author: Peter Toi
# Source: https://gist.github.com/petertoi/b61ac28f2cd27a2c645d
#
# Usage 1: $ wgetseq.sh # No argument will result in prompts
# Usage 2: $ wgetseq.sh starturl endurl startnum endnum # Skip the prompts by including the arguments
if [ "$#" -eq 4 ]
then