Skip to content

Instantly share code, notes, and snippets.

@ajbonner
ajbonner / str_putcsv.php
Last active December 26, 2015 11:18
A version of putcsv that returns a string rather than writes to a file
<?php
/**
* @param array $data
* @return string
*/
public function str_putcsv($data)
{
$fh = fopen('php://memory', 'rwb');
@ajbonner
ajbonner / customer_address_query.php
Last active January 1, 2016 04:59
Adding an attribute to a magento customer collection
$commonwealthSubscribers = Mage::getModel('customer/customer')
->getCollection()
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing')
->addAttributeToFilter('billing_country_id', array('in' => 'AU', 'CA', 'GB'))
@ajbonner
ajbonner / intervention_watermark.php
Created February 6, 2014 12:02
Intervention Watermarking with Cache
<?php
$filestore = new \Illuminate\Cache\FileStore(
new \Illuminate\Filesystem\Filesystem(),
'/some/path/to/somewhere/specific/intervention-cache');
$repository = new \Illuminate\Cache\Repository($filestore);
$cache = new \Intervention\Image\ImageCache($repository);
$watermark = $cache->make($watermarkFile)->get(0, true);
@ajbonner
ajbonner / enable_core_dumps.sh
Created April 11, 2014 21:04
Enable Core Dumps
#!/usr/bin/env bash
echo '/tmp/core-%e.%p' > /proc/sys/kernel/core_pattern
echo 0 > /proc/sys/kernel/core_uses_pid
ulimit -c unlimited
@ajbonner
ajbonner / filter_rename
Last active August 29, 2015 14:00
Mass Rename Files in a Dir Using Sed Expression
#!/usr/bin/env bash
find . -name '*.gz' -print | while read SRC_FILE; do
DEST_FILE=$(echo $SRC_FILE | sed 's/_2014.*.sql.gz/.sql.gz/')
mv $SRC_FILE $DEST_FILE
done
@ajbonner
ajbonner / gist:e5eb20d253c2695912fa
Created July 8, 2015 17:38
Mac OSX Vagrant /etc/export for NFS
"/Users/aaron/Sites" 192.168.200.100 -alldirs -mapall=501:20
@ajbonner
ajbonner / event_dispatch_check.php
Last active February 5, 2016 19:52
Quick and dirty way to test if an observer responds to a given event in Magento 1 using MageTest
<?php
class SomeTestTest extends MageTest_PHPUnit_Framework_TestCase
{
/**
* @param string $observerName e.g. mymodulens_mymodule_does_something_on_order_place
* @param string $eventName e.g. a dispatched event e.g. sales_order_place_after
* @param string $area e.g. global/frontend/admin/adminhtml
*/
public function assertObserverReceivesEvent($observerName, $eventName, $area)
@ajbonner
ajbonner / ImageController.php
Last active July 8, 2016 18:46
Fix tiresome headers already sent bug in Magento 1.x
<?php
/**
* Generate image thumbnail on the fly
*/
public function thumbnailAction()
{
$file = $this->getRequest()->getParam('file');
$file = Mage::helper('cms/wysiwyg_images')->idDecode($file);
$thumb = $this->getStorage()->resizeOnTheFly($file);
if ($thumb !== false) {
# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed --default-names
brew install findutils --with-default-names
@ajbonner
ajbonner / strace-fpm.sh
Created April 11, 2017 14:13
Strace all running php-fpm processes to file with timestamps and pid
sudo strace -f -tt -o /tmp/php.trace -s1024 -p `pgrep -f php-fpm | tr '\n' ','`