Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / magento-nginx-appfiles.conf
Last active December 23, 2015 11:19
Nginx magento app file handling
location ^~ /store/app {
access_log off;
log_not_found off;
return 404;
}
@ajbonner
ajbonner / customer_attribute.php
Created July 16, 2013 11:27
Create a Magento customer attribute and add it to admin forms
<?php
/* @var $installer Mage_Model_Customer_Entity_Setup */
$installer = $this;
/* @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
$installer->startSetup();
@ajbonner
ajbonner / zend_db_count.php
Last active December 19, 2015 04:49
Get the number of rows matching a select query with Zend_Db
<?php
class ZdbCountExample
{
public function doSelect()
{
$pageSize = 1000;
$numPages = ceil($this->count($this->baseSelect()) / $pageSize);
for ($page = 0; $page <= $numPages; $page++) {
@ajbonner
ajbonner / array_reduce.php
Created April 26, 2013 10:20
Array Reduce Example
<?php
$selectionQtys = array_reduce($savedSelections, function($sum, $selectionId) { $sum[$selectionId]++; return $sum; }, array());
@ajbonner
ajbonner / bundle-programmable.php
Last active December 16, 2015 09:19
Add a bundle product to the cart programatically
<?php
$options = array(
'product' => 8234,
'bundle_option'=>array(
'297'=>1233
),
'qty'=>$qty
);
@ajbonner
ajbonner / php-fpm.conf
Last active December 15, 2015 11:39
Apache2 FastCGI and PHP-FPM Configuration
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
</IfModule>