Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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('me@gmail.com', 'Me')
->addTo($to)
->setSubject($subject)
->setBodyText($message);
$file = '/path/to/a/file';
@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 / core_file_storage_fix.sql
Created August 16, 2011 17:12
Fix for magento 1.5.x base table or view not found 'core_file_storage'
DROP TABLE IF EXISTS core_file_storage;
CREATE TABLE IF NOT EXISTS core_file_storage (
`file_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`content` LONGBLOB NOT NULL,
`upload_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`filename` varchar(255) NOT NULL DEFAULT '',
`directory_id` int(10) unsigned DEFAULT NULL,
`directory` varchar(255) DEFAULT NULL,
PRIMARY KEY (`file_id`),
UNIQUE KEY `IDX_FILENAME` (`filename`, `directory`),
@ajbonner
ajbonner / adminhtml.xml
Created August 11, 2012 11:32
Disable Magento Adminhtml Menu Option
<?xml version="1.0"?>
<!-- Disable Catalog Price Rules Menu Entry -->
<config>
<menu>
<promo translate="title" module="catalogrule">
<children>
<catalog translate="title" module="catalogrule">
<depends>
<module>Disable_This_Module</module>
@ajbonner
ajbonner / chef-from-src.sh
Created August 17, 2012 10:22
Build Chef From Source
#!/usr/bin/env bash
wget --no-check-certificate -O chef.tgz https://github.com/opscode/chef/tarball/10-stable
mkdir chef-stable
tar zxf chef.tgz --strip-components=1 -C chef-stable
cd chef-stable/chef
gem build chef.gemspec
/opt/ruby/bin/gem install chef --no-ri --no-rdoc
cd ../../
rm -rf chef-stable
@ajbonner
ajbonner / Result.php
Created August 30, 2012 08:12
Unescaped input in breadcrumbs - Magento 1.6.x Mage_CatalogSearch_Block_Result
/**
* Prepare layout
*
* @return Mage_CatalogSearch_Block_Result
*/
protected function _prepareLayout()
{
// add Home breadcrumb
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbs) {
@ajbonner
ajbonner / local.xml
Created September 3, 2012 10:38
Snippet showing how to disable Magneto's Database Logging Events
<config>
...
<global>
...
<frontend>
<events>
<controller_action_predispatch>
<observers><log><type>disabled</type></log></observers>
</controller_action_predispatch>
<controller_action_postdispatch>
@ajbonner
ajbonner / application_controller.rb
Created October 15, 2012 10:38
How not to rescue_from exceptions
class ApplicationController < ActionController::Base
# Catch all exceptions at a stretch
rescue_from Exception, :with => :handle_exceptions
private
# Handle exceptions
def handle_exceptions(e)
case e