Skip to content

Instantly share code, notes, and snippets.

View kane-c's full-sized avatar

Kane kane-c

View GitHub Profile
@kane-c
kane-c / column-max-check.php
Last active December 23, 2015 03:49
A script to find int columns in a MySQL database that are nearing the maximum value for the given size. This supports all types of int columns, and also supports unsigned columns.This is especially useful for auto incrementing primary keys and their related foreign keys.
<?php
$config = (object) array(
'db' => (object) array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
),
// Threshold for how "full" the int columns are, as a percentage. Since we
// deal with columns of different sizes, a fixed number isn't appropriate
'threshold' => 0.95,
@kane-c
kane-c / clone-wordpress-db.php
Created March 20, 2014 04:02
Makes a copy of a Wordpress database by copying existing tables to a set of tables with a different prefix. Useful for having a staging version hosted in the same place.
<?php
$host = 'localhost';
$username = 'username';
$password = 'password';
$database = 'db';
$prefix = 'wp_';
$newPrefix = 'staging_';
$link = mysql_connect($host, $username, $password);
mysql_select_db($database);
@kane-c
kane-c / upgrade_pg.sh
Last active August 29, 2015 14:00 — forked from ibussieres/upgrade_pg.sh
Upgrade PostgreSQL 9.1 to 9.3 on Ubuntu 14.04
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
sudo apt-get remove postgresql-9.1 postgresql-client-9.1 -y
sudo sed -i "s:5433:5432:g" /etc/postgresql/9.3/main/postgresql.conf
sudo service postgresql restart
sudo su - postgres -c '~/analyze_new_cluster.sh'
@kane-c
kane-c / dns.php
Created July 17, 2014 00:23
Gets the DNS records for a given domain(s)
#!/usr/bin/env php
<?php
if ($_SERVER['argc'] < 2) {
echo 'Usage: ', basename(__FILE__), ' domain-name.com [domains...]';
die;
}
foreach ($_SERVER['argv'] as $i => $domain) {
// 0 is the script name
if (0 === $i) {
@kane-c
kane-c / woocommerce-force-shipping-pickup.php
Created July 23, 2014 05:40
WordPress WooCommerce: Force local pickup as the only shipping option when products in the cart require it.
<?php
// Force pickup as a shipping option if one or more products in the catalog is marked as pickup only.
// To do this, add a shipping class with the slug 'pickup-only' then set products with that class as required.
// Add this script to your theme's functions.php or similar.
function hideShippingWhenPickupRequired($rates, $package)
{
foreach ($package['contents'] as $item) {
$product = $item['data'];
$shippingClass = $product->get_shipping_class();
@kane-c
kane-c / wordpress-change-domain.sql
Last active August 29, 2015 14:04
The SQL required for changing a WordPress install's domain
-- Replace new-domain and old-domain as with your values
SET @old_domain = '',
@new_domain = '';
UPDATE `wp_options`
SET `option_value` = REPLACE (
`option_value`,
@old_domain,
@new_domain
);
# Make the Django server from LiveServerTestCase multi-threaded
# so that you can make requests to yourself during tests without
# deadlocking.
# Note that this prevents being able to use in-memory sqlite for
# tests unless you use something like `/dev/shm`
# May cause other bugs too
from django.core.servers.basehttp import WSGIServer
from django.test import testcases
from django.utils.six.moves import socketserver
@kane-c
kane-c / backup
Last active September 5, 2020 04:25
Simple Postgres & MySQL regular maintenance + backup script
#!/usr/bin/env bash
# Usage: backup.sh type database username host gdrive-parent-folder-id gpg-recipient
# Requires gdrive: https://github.com/prasmussen/gdrive
set -e
timeslot=$(date '+%Y%m%d%H%M')
type=$1
database=$2
user=$3
host=$4
@kane-c
kane-c / update.sh
Last active September 5, 2015 23:48
Update Ubuntu and software
#!/usr/bin/env bash
apt-get update
apt-get dist-upgrade -y
apt-get autoremove -y
apt-get clean
apt-get autoclean
pip install -U pip virtualenvwrapper
npm update -g
@kane-c
kane-c / git-grep-all
Created May 26, 2015 03:45
Search all git repos in a directory
#!/bin/sh
bold=$(tput bold)
normal=$(tput sgr0)
DIR=`pwd`
for project in $(find * -type d -maxdepth 0)
do
cd $project
if [ -d ".git" ]