Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
@thewinterwind
thewinterwind / checktablesize.sql
Created February 3, 2014 18:42
How to check a table size in MySQL
SELECT table_name AS "Table",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
@thewinterwind
thewinterwind / database_details.sql
Created February 3, 2014 20:19
View details on MySQL tables
SELECT count(*) tables,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') data,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;
+--------+----------+---------+--------+------------+---------+
| tables | rows | data | idx | total_size | idxfrac |
+--------+----------+---------+--------+------------+---------+
@thewinterwind
thewinterwind / read_from_x_to_end.php
Created February 9, 2014 04:11
Read from a specific line to end of file using PHP
<?php
$log_file = 'lines.log';
$read_start_position = 50;
$file = new SplFileObject($log_file);
$file->seek($read_start_position);
while(!$file->eof()) {
@thewinterwind
thewinterwind / datatables.php
Created March 25, 2014 14:29
Datatables class for Laravel 4
<?php
namespace Leads\Libraries;
class Datatables {
public static function ajax($table, Array $columns)
{
/*
* Script: DataTables server-side script for PHP and MySQL
@thewinterwind
thewinterwind / view_globals.php
Last active August 29, 2015 13:57
View PHP server-related global variables from command line or browser
<?php
/**
* Author: Anthony Vipond
* Tested on: PHP 5.5
*/
$global_indexes = ['SERVER', 'ENV', 'SESSION', 'REQUEST', 'COOKIE', 'GET', 'POST', 'FILES'];
if (php_sapi_name() !== 'cli') {
@thewinterwind
thewinterwind / helpers.php
Created March 28, 2014 22:18
Laravel 4 Helpers
<?php
/**
* Helpers for Laravel 4
* Author: Anthony Vipond
*/
// Preformat the dump and die function
if (!function_exists('d')) {
function d($mixed) {
@thewinterwind
thewinterwind / php-snippets.xml
Last active August 29, 2015 13:58
Sublime Text 2 Laravel 4 Snippet Collection
<overview>
pf = new function
comm = new function comment
fopen = open a form
fclose = close a form
</overview>
<snippet>
<content>
<![CDATA[
@thewinterwind
thewinterwind / log_laravel_db_queries_to_console.php
Created May 4, 2014 05:59
Log Laravel 4 Database Queries to the Console
@if (App::environment() == 'local')
@foreach (DB::getQueryLog() as $query)
<script>console.log(' {{ $query['query'] . ' (' . $query['time'] . ' secs)' }} ')</script>
@endforeach
@endif
@thewinterwind
thewinterwind / remove-duplicate-rows-from-mysql-table.sql
Last active August 29, 2015 14:01
How to remove duplicate rows from a MySQL table
-- For example, a members table that has duplicate emails
-- Needs unique id field to work
create temporary table tmpTable (id int);
insert tmpTable
(id)
select id
from members m
where exists
@thewinterwind
thewinterwind / add-primary-key-to-existing-table.sql
Created May 8, 2014 09:10
Add primary key after table already exists (MySQL)
ALTER TABLE XXX add column id INT NOT NULL AUTO_INCREMENT FIRST, ADD primary KEY Id(id)