Skip to content

Instantly share code, notes, and snippets.

@ajbonner
ajbonner / tablesize_report.sql
Created July 14, 2011 14:21
Get a list of large tables within a mysql database
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
WHERE table_schema = 'database-name'
ORDER BY data_length+index_length DESC LIMIT 10;
@ajbonner
ajbonner / mail_attachment.php
Created June 28, 2011 15:42
Add an attachment to an email with Zend_Form
<?php
$mail = new Zend_Mail();
$mail->setFrom('[email protected]', 'Me')
->addTo($to)
->setSubject($subject)
->setBodyText($message);
$file = '/path/to/a/file';
@ajbonner
ajbonner / image_dimensions.rb
Created June 24, 2011 16:58
Get the dimensions of an image using ruby's image_size gem
#!/usr/bin/env ruby
require 'image_size'
pwd = File.dirname(__FILE__)
Dir.glob(pwd+'/*') do |file|
if (File.extname(file) == '.jpg')
fh = File.open(file, 'rb')
size = ImageSize.new(fh.read)
@ajbonner
ajbonner / mysqldump_bypattern.sh
Created June 9, 2011 15:08
Mysqldump data from database tables matching a pattern
#!/bin/bash
if [ $# -lt 5 ]; then
echo "Exports data from mysql database in tables matching a like pattern e.g. 'table_%'"
echo "Usage: $0 dbname dbuser dbpass pattern outputfile"
exit 1
fi
DBNAME=$1
DBUSER=$2