Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head><title>Script Block Test</title></head>
<body>
<?php if (isset($_GET['mode']) && $_GET['mode'] == 'inline'): ?>
<script type="text/javascript">
var domReadyQueue = [];
var x=function(){return {on: function(){}};};
@rgranadino
rgranadino / gist:8744147
Created January 31, 2014 22:00
sample asset path data structure
Array
(
[gallery] => Array
(
[1810] => Array
(
[path] => g/0000430/11.jpg
[orig_path] => /1/1/11.jpg
)
@rgranadino
rgranadino / memleak.php
Last active August 29, 2015 13:55
Magento Memory Leak
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
require 'app/Mage.php';
Mage::app('admin', 'store');
/* @var $customers Mage_Customer_Model_Resource_Customer_Collection */
$customers = Mage::getResourceModel('customer/customer_collection');
$customers->addAttributeToSelect('*');
$customers->setPageSize((isset($argv[1]) && is_numeric($argv[1]))?$argv[1]:2000);
@rgranadino
rgranadino / gist:8695018
Created January 29, 2014 19:24
updating db resource connection info in magento - special cases only?
<?php
$dbConfig = Mage::getConfig()->getNode('global/resources/report_database/connection');
if (!$dbConfig) {
return;
}
/* @var $db Magento_Db_Adapter_Pdo_Mysql */
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
$db->closeConnection();
//update values
$dbConfig = $dbConfig->asArray();
@rgranadino
rgranadino / gist:7530093
Created November 18, 2013 15:50
simple log4j properties
log4j.rootLogger = ALL, Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n
<?php
class Email {
//...
public function setAttachments(array $files) {
$this->attachment_list = array();
foreach($files as $filename => $file) {
if (is_str($filename)) {
$this->addAttachment($file, $filename);
} else {
@rgranadino
rgranadino / gist:6645104
Created September 20, 2013 23:07
Magento Sync Product Attributes
public function syncConfigProductAttributes(Mage_Catalog_Model_Product $product)
{
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
/* @var $productType Mage_Catalog_Model_Product_Type_Configurable */
$productType = $product->getTypeInstance(true);
$syncAttributes = array('short_description', 'description');
foreach ($productType->getUsedProductCollection($product) as $childProduct) {
//$childProduct->load($childProduct->getId());
/* @var $childProduct Mage_Catalog_Model_Product */
foreach ($syncAttributes as $attributeCode) {
@rgranadino
rgranadino / gist:5977733
Created July 11, 2013 18:05
install dummy rice and beans product in magento
#!/usr/bin/env php
<?php
require 'app/Mage.php';
if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit(1);
}
$baseDir = getcwd();
//not sure if this is necessary, ported over from cron.php script
$_SERVER['SCRIPT_NAME'] = $baseDir.'/index.php';
@rgranadino
rgranadino / gwsdecoder.php
Created August 23, 2012 04:43
D-Link gws file decoder
#/usb/bin/php
<?php
//author rgranadino aug 22 2012
//tested on a D-Link DIR-615 B2 v2.25 firmware.
//this is a php translation of:
// http://www.shulerent.com/2009/08/21/cracking-the-d-link-settings-file/
$file = $argv[1];
if (!is_readable($file)) {
echo "Cannot read file: $file\n";
@rgranadino
rgranadino / gist:3100752
Created July 12, 2012 20:29
php object comparison recursion example
class Foo {
public $x = null;
}
$a = new Foo();
$b = new Foo();
$c = new Foo();
$d = new Foo();
$a->x = $c;