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 / 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 / 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
);
@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" ]
@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 / 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 / notify.py
Created June 21, 2016 05:05
Create OS level notifications via Python through a web server
#!/usr/bin/env python
"""
Simple server to create OS notifications.
Example usage with Django:
To get a notification when the Django development server is running or has just
reloaded in resoonse to a code change, append this to `wsgi.py`:
```
import requests
try:
@kane-c
kane-c / macos-update.sh
Created June 29, 2016 23:05
Update and clean stuff for macOS
#!/bin/sh
# Usage: . ./macos-update.sh (so that upgrade_oh_my_zsh works)
echo 'Updating brew'
brew update
brew upgrade --all
brew cleanup
echo 'Updating shell'
upgrade_oh_my_zsh
echo 'Updating Docker and its images'
dinghy upgrade
@kane-c
kane-c / Preferences.sublime-settings
Created July 16, 2016 01:14
Sublime Text settings
{
"color_scheme": "Packages/User/SublimeLinter/base16-ocean.dark (SL).tmTheme",
"detect_indentation": true,
"dictionary": "Packages/Language - English/en_GB.dic",
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
".git",
".hg",
".idea",