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;
@drewdhunter
drewdhunter / Magento - core code pre commit hook
Last active December 31, 2015 20:08
Pre commit hook useful for Magento projects
#!/usr/bin/env bash
set -eu
declare -a file_patterns=('app/code/core' 'app/Mage.php$' '^index.php$')
exit_status=0
while read x file; do
for file_pattern in ${file_patterns[@]}; do
if [[ $file =~ $file_pattern ]]; then
@endymuhardin
endymuhardin / create-poster.sh
Created June 27, 2011 10:42
Convert ogv to mp4 with H264 encoding, create poster, upload to server
ffmpeg -r 1 -t 1 -vframes 1 -i input-file.mp4 output-file.png
@drewgillson
drewgillson / pricerules.php
Created October 11, 2012 02:35
Magento CLI utility to refresh catalog price rules
<?php
require_once 'abstract.php';
class Mage_Shell_Pricerules extends Mage_Shell_Abstract
{
public function run()
{
ini_set('memory_limit', '1024M');
$this->db = Mage::getSingleton('core/resource')->getConnection('core_read');
@SchumacherFM
SchumacherFM / Magento-HHVM.md
Last active May 17, 2018 18:26
Running Magento Enterprise Edition with Facebook HipHop HHVM

Running Magento Enterprise Edition with Facebook HipHop HHVM

Prerequisites

Hardware

MacBook Air (MBA) Mid 2012

@SchumacherFM
SchumacherFM / README.md
Last active September 21, 2018 10:05
Avoiding database deadlocks in Magento 1.7

After having many deadlocks due to a high order volumne I've applied the these fixes to the core. Some can be found in a Magento forum. Before the fixes we could only process 1 order every 5-10 secs. Updating to Magento 1.8 is currently not an option but in 1-2 months.

1st Deadlock

Mage_Sales_Model_Abstract::_afterSave must be removed and replaced with afterCommitCallback. This is important to move the grid update (of sales_flat_order_grid) out of the transaction.

2nd Deadlock

Rewrite the method of the Mage_CatalogInventory_Model_Observer::reindexQuoteInventory() to remove the price reindexing from the transaction. That index process will also be fired in event sales_model_service_quote_submit_success.

@colinmollenhour
colinmollenhour / log_deadlocks.sh
Last active December 4, 2018 20:51
Record all new deadlocks in separate files
#!/bin/bash
#
# Copyright Colin Mollenhour 2014
dir=/root/deadlocks
[ -d $dir ] || mkdir -p $dir
cd $dir || { echo "Could not cd to $dir"; exit 1; }
mysql -be 'show engine innodb status;' \
| sed 's/\\n/\n/g' \
@Vinai
Vinai / 2016-48.md
Last active January 13, 2020 09:25
List of past code katas. The file names are the [year]-[week-of-year].md. I'll try to update the list each week.

The first kata is the classic BowlingGame Kata from Uncle Bob.

Write a class named Game that has two methods

  • roll(pins : int) is called each time the player rolls a ball. The argument is the number of pins knocked down.
  • score() : int is called only at the very end of the game. It returns the total score for that game.

Here is the original PowerPoint from Uncle Bob with the instructions including the solution steps. The PPT file also includes the rules for the scoring of a bowling game.

@ryansully
ryansully / optimize.sh
Created February 1, 2012 23:56 — forked from realdeprez/optimize.sh
image optimization script (pngcrush & jpegtran)
#!/bin/sh
# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# http://developer.yahoo.com/performance/rules.html#opt_images
# pngcrush
for png in `find $1 -iname "*.png"`; do
echo "crushing $png ..."
pngcrush -rem alla -reduce -brute "$png" temp.png
@mardix
mardix / php-cs-fixer-pre-commit.php
Created September 4, 2012 17:06
A pre-commit hook to make PHP code PSR-2 compliant, check for syntax error
#!/usr/bin/php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP error (lint), and make sure the code
* is PSR compliant.
*
* Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
*