Skip to content

Instantly share code, notes, and snippets.

@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>
@ajbonner
ajbonner / macports_pear.sh
Created February 16, 2013 22:19
Configure macports pear for use with PHP54
sudo pear config-set php_bin /opt/local/bin/php
sudo pear config-set php_dir /opt/local/lib/php/pear
sudo pear config-set ext_dir /opt/local/lib/php54/extensions/no-debug-non-zts-20100525
sudo pear config-set bin_dir /opt/local/bin
sudo pear config-set cfg_dir /opt/local/lib/php/pear/cfg
sudo pear config-set doc_dir /opt/local/lib/php/pear/docs
sudo pear config-set www_dir /opt/local/lib/php/pear/www
sudo pear config-set test_dir /opt/local/lib/php/pear/tests
sudo pear config-set data_dir /opt/local/lib/php/pear/data
@ajbonner
ajbonner / rr_sluper_multi.rb
Last active December 12, 2015 08:39
Multithreaded Ruby Rogue Podcast Slurper
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
MAX_THREADS = 5
thread_pool = []
index = Nokogiri::HTML(open('http://rubyrogues.com/episode-guide/'));
@ajbonner
ajbonner / rr_sluper.rb
Created February 9, 2013 16:23
Script to pulldown all the Ruby Rogue Podcast MP3s as only the latest 50 are in their feed
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
index = Nokogiri::HTML(open('http://rubyrogues.com/episode-guide/'));
index.css('a[rel=bookmark]').each do |link|
podcast = Nokogiri::HTML(open(link['href']));
title = podcast.css('.entry-title').text
@ajbonner
ajbonner / xdebug.sh
Created January 9, 2013 20:09
A pair of bash functions to speed up enabling and disabling xdebug on debian like systems
function enable_xdebug() {
sudo sed -i'' 's/^;*//g' /etc/php5/conf.d/xdebug.ini
}
function disable_xdebug() {
sudo sed -i'' 's/^/;/g' /etc/php5/conf.d/xdebug.ini
}