Skip to content

Instantly share code, notes, and snippets.

View olivertappin's full-sized avatar
😁

Oliver Tappin olivertappin

😁
View GitHub Profile
@olivertappin
olivertappin / column-entry-creation.sql
Created March 26, 2019 13:12
Return the column entry for a SHOW CREATE TABLE (based on primary key or column name)
SELECT RTRIM(CONCAT(
'`',
COLUMN_NAME,
'`',
' ',
COLUMN_TYPE,
' ',
IF (COLLATION_NAME IS NULL, '', CONCAT('COLLATE ', COLLATION_NAME, ' ')),
IF (IS_NULLABLE = 'YES', '', 'NOT NULL '),
IF (COLUMN_DEFAULT IS NULL, '', CONCAT('DEFAULT ', COLUMN_DEFAULT, ' ')),
@olivertappin
olivertappin / gcloud-helpers.sh
Created February 25, 2019 13:36
Google Cloud helper functions to access instances from the command line
# SSH into an instance using the instance name (supports partial matching)
# Usage: gcessh <instance-name>
gcessh() { $(gcloud compute instances list --filter="name~'$1'" --sort-by name | tail -n +2 | head -1 | awk '{print "ssh "$1}' ) 2>/dev/null; };
# Describe an instance using the instance name (exact match only)
# Usage: gcedesc <instance-name>
gcedesc() { $(gcloud compute instances list | grep $1 | awk '{print "gcloud compute instances describe "$1" --zone "$2}'); };
# List all matching instances using a partially matched instance name (perfect for listing nodes from an instance group)
# Usage: gcelsn <instance-name>
@olivertappin
olivertappin / consul-kv-export.php
Created February 13, 2019 14:21
Export all data from the Consul KV store into consul kv put commands
<?php
$output = shell_exec('consul kv export');
if (null === $output) {
echo 'Could not run `consul kv export`. Is consul installed?' . PHP_EOL;
exit(1);
}
$data = json_decode($output, true);
@olivertappin
olivertappin / deploy.sh
Created January 31, 2019 10:44
Atomic symlinked deployments
BASE="/var/www/project"
RELEASES="$BASE/releases"
RELEASE="$RELEASES/`date +%s`"
SHARED="$BASE/shared"
CACHE="$BASE/deploy-cache"
cp -a $CACHE $RELEASE
cd $RELEASE
####### [Pre-launch commands] #######
@olivertappin
olivertappin / PostcodeLookupController.php
Created December 9, 2018 21:20
Postcode Lookup using the Google Geocoding API
<?php
namespace App\Http\Controllers\Api;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Http\Response;
use App\Mappers\Response\Address as AddressMapper;
@olivertappin
olivertappin / vote.php
Created October 17, 2018 22:12
Automatically vote on a SurveyMonkey survey, and make it go your way.
<?php
// Usage: Upload to a random server of your choice and send the URL to http://browsershots.org (or similar)
// Prerequisites:
// composer require fabpot/goutte
include 'vendor/autoload.php';
use Goutte\Client;
@olivertappin
olivertappin / update-server-datetime.sh
Created September 24, 2018 10:44
Update server date time using Google
date -s "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')"
@olivertappin
olivertappin / track-disk-usage.sh
Last active August 8, 2018 08:04
Track disk related issues for MySQL ERROR 1034 (HY000) during an ALTER TABLE
# During an ALTER TABLE run, if you experience the following error:
#
# mysql> ALTER TABLE `my_table` ALGORITHM=INPLACE, ENGINE=InnoDB;
# ERROR 1034 (HY000): Incorrect key file for table 'my_table'; try to repair it
#
# It may be disk related. To track this, run the following commands (in a screen session)
# and leave them running whilst running the ALTER again. After the error displays, check
# the files for obvious signs of disk related issues. Please note, the results from the
# df-full.log may not be accurate (on their own), so use this with the lsof.log
# Also, please ensure the following commands are run seperatley in parallel (with seperate
@olivertappin
olivertappin / remove-unused-headers.sh
Last active March 30, 2019 22:37
Remove unused headers on Ubuntu
#!/bin/sh
# Run the following command to run this script locally:
# sh -c "$(curl -sSL https://gist.github.com/olivertappin/1628438fbb9460743a9021cddd7221ce/raw)"
headers=$(dpkg --list | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+[0-9]+-generic' | awk {'print $2'} | grep -v `uname -r`)
echo "Current header: "
uname -r
@olivertappin
olivertappin / travis-vhost.conf
Last active July 30, 2018 22:02
Travis-CI virtual host configuration
<VirtualHost *:80>
ServerName %TRAVIS_HOSTNAME%
DocumentRoot %TRAVIS_BUILD_DIR%
LogFormat "%{UNIQUE_ID}e %h %l %u %t \"%r\" %>s %b" unique
CustomLog %TRAVIS_LOG_DIR%/access_log unique
ErrorLog %TRAVIS_LOG_DIR%/error_log
SetEnv APP_ENV local
<Directory "%TRAVIS_BUILD_DIR%">
AllowOverride None
Require all granted