Skip to content

Instantly share code, notes, and snippets.

@jacks0n
jacks0n / .gitignore
Last active March 22, 2024 22:45
Comprehensive .gitignore
#######################################
# Operating Systems #
#######################################
# OS X
.DS_Store
._*
.Spotlight-V100
.Trashes
@jacks0n
jacks0n / .htaccess
Created May 10, 2014 14:28
Default .htaccess
# Some sensible defaults
Options +FollowSymLinks -Indexes
AddDefaultCharset UTF-8
ServerSignature Off
# Hide sensitive information
RedirectMatch 404 /\.git
RedirectMatch 404 /*.sql
RedirectMatch 404 /Gruntfile.js
@jacks0n
jacks0n / wp-config.php
Created May 15, 2014 05:42
WordPress Any URL - A quick and dirty way of allowing WordPress to run on any URL, without having to replace URLs in the database. It will figure out the home URL, based on the current hostname and relative path from the server's root directory. It will also re-write existing links with the current site, using output buffering. eg. http://oldser…
// Add whatever URLs you want to replace with the current home URL
$replace_urls = array('http://exampleoldsite.com/mysite');
$uri = str_replace("{$_SERVER['DOCUMENT_ROOT']}/", '', dirname(__FILE__));
$home_url = sprintf('%s://%s/%s', $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http', $_SERVER['SERVER_NAME'], $uri);
define('WP_SITEURL', $home_url); define('WP_HOME', $home_url);
function replace_old_urls($html) { global $replace_urls; return str_replace($replace_urls, WP_SITEURL, $html); }
ob_start('replace_old_urls');
@jacks0n
jacks0n / install-google-fonts.sh
Created May 19, 2014 02:22
Install all Google Fonts for OS X
# To update replace line below with: hg pull && hg update
hg clone https://googlefontdirectory.googlecode.com/hg/ googlefonts
find . -name "*.ttf" -exec cp {} /Library/Fonts \;
fc-cache -f
@jacks0n
jacks0n / fix-permissions.sh
Last active August 29, 2015 14:01
Fixes / restores permissions for most CMSs
# General
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
# Magento
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 mage # For magento 1.5+
# Joomla
@jacks0n
jacks0n / .gitignore
Created May 28, 2014 11:37
Minimal .gitignore
# OS's
.DS_Store
Desktop.ini
Thumbs.db
# Server
.ftpquota
error_log
cgi-bin/
.htpasswd
@jacks0n
jacks0n / .htaccess
Created June 6, 2014 03:37
Lock down a specific site to a given IP address
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !=59.167.223.97
RewriteRule ^(.*)$ 404.php [R=404,L]
</IfModule>
@jacks0n
jacks0n / SQL Queries to Cleanup WordPress.sql
Last active September 17, 2019 19:55
Useful SQL Queries to Cleanup a WordPress Database
-- Delete all old post revisions
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';
-- Cleanup weird characters
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
@jacks0n
jacks0n / wp-auto-login.php
Last active November 19, 2023 16:35
Automatically login to WordPress, with a given user and optionally whitelist IPs. Add this to the bottom of wp-config.php, or your theme functions.php. To automatically login, visit the admin login page (/wp-login.php or /wp-admin/).
/**
* Automatically logs in a visitor when accessing the admin login area (/wp-login.php)
*
* @copyright Copyright (c) 2014, Jackson Cooper
* @license MIT
*
* Whitelist IPs: add IPs to whitelist in $ip_whitelist. If it is empty, it will allow all IPs.
* Username: Specify the username to login as with the "user" GET parameter (eg. ?user=admin).
* If the "user" get parameter is not set, $default_user_login will be used. If set
* to "*", it will login as the first administrator found. Otherwise it will use the
@jacks0n
jacks0n / .htaccess
Last active August 29, 2015 14:11
Force the www or non-www canonical domain (example.com => www.example.com or www.example.com => example.com). Includes re-directing files/assets.
# Force the canonical www-subdomain
# example.com => www.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Force the canonical root domain
# www.example.com => example.com
RewriteEngine On