Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Taking new clients now

Anthony Vipond thewinterwind

💭
Taking new clients now
View GitHub Profile
@thewinterwind
thewinterwind / checktablesize.sql
Created Feb 3, 2014
How to check a table size in MySQL
View checktablesize.sql
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 Feb 3, 2014
View details on MySQL tables
View database_details.sql
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 Feb 9, 2014
Read from a specific line to end of file using PHP
View read_from_x_to_end.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 Mar 25, 2014
Datatables class for Laravel 4
View datatables.php
<?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 Aug 29, 2015
View PHP server-related global variables from command line or browser
View view_globals.php
<?php
/**
* Author: Anthony Vipond
* Tested on: PHP 5.5
*/
$global_indexes = ['SERVER', 'ENV', 'SESSION', 'REQUEST', 'COOKIE', 'GET', 'POST', 'FILES'];
if (php_sapi_name() !== 'cli') {
View helpers.php
<?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 Aug 29, 2015
Sublime Text 2 Laravel 4 Snippet Collection
View php-snippets.xml
<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
Log Laravel 4 Database Queries to the Console
View log_laravel_db_queries_to_console.php
@if (App::environment() == 'local')
@foreach (DB::getQueryLog() as $query)
<script>console.log(' {{ $query['query'] . ' (' . $query['time'] . ' secs)' }} ')</script>
@endforeach
@endif
@thewinterwind
thewinterwind / add-primary-key-to-existing-table.sql
Created May 8, 2014
Add primary key after table already exists (MySQL)
View add-primary-key-to-existing-table.sql
ALTER TABLE XXX add column id INT NOT NULL AUTO_INCREMENT FIRST, ADD primary KEY Id(id)
@thewinterwind
thewinterwind / remove-duplicate-rows-from-mysql-table.sql
Last active Aug 29, 2015
How to remove duplicate rows from a MySQL table
View remove-duplicate-rows-from-mysql-table.sql
-- 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