Skip to content

Instantly share code, notes, and snippets.

@code-poel
code-poel / gist:962668
Created May 9, 2011 14:55
Alternative Syntax for Selecting a MySQL Date Range
SELECT * FROM table WHERE created_on <= DATE_SUB( NOW(), INTERVAL 1 WEEK );
@code-poel
code-poel / gist:5375932
Created April 12, 2013 23:12
Snippet to add a root node to layout in Magento. This would be placed in local.xml (or page.xml).
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="new_root_node" as="new_root_node" translate="label">
<label>New Root Node</label>
</block>
</reference>
<reference name="new_root_node">
<block type="catalog/text" name="some_block" template="page/html/some_template.phtml" />
@code-poel
code-poel / SplInt.php
Last active December 19, 2015 12:49
Annoying PHP quirk.
<?php
$integer = new \SplInt( 5 );
if( false === filter_var( $integer, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1, 'max_range' => 9 ) ) ) )
{
throw new \InvalidArgumentException( sprintf( 'An integer value of 1 through 9 is required, %s "%s" given.', gettype( $integer ), $integer ) );
}
// Result:
@code-poel
code-poel / OuterIteratorMethods.php
Created August 1, 2013 12:08
Reusable block for Spl work.
<?php
public function getInnerIterator()
{
return $this->_children;
}
public function current()
{
return $this->getInnerIterator()->current();
}
@code-poel
code-poel / OuterIteratorMethods.php
Created August 1, 2013 12:08
Reusable block for Spl work.
<?php
public function getInnerIterator()
{
return $this->_children;
}
public function current()
{
return $this->getInnerIterator()->current();
}
@code-poel
code-poel / Blocks.php
Last active December 20, 2015 12:29
Nested SPL objects with recursion.
<?php
class Layout extends \ArrayIterator
{
}
class Block extends \ArrayIterator
{
protected $_alias;
@code-poel
code-poel / FindTables.sql
Created August 7, 2013 20:25
Find tables with columns.
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ( 'column' ) AND TABLE_SCHEMA='database_name';
@code-poel
code-poel / local.xml
Last active August 29, 2015 13:57
Using a Magento system configuration value to toggle layout.xml updates
<reference name="product_list">
<!-- If the system configuration node "one_ul_product_list" is true, execute this action -->
<action method="setColumnCount" ifconfig="sample/config/one_ul_product_list">
<columns>10000</columns>
</action>
</reference>
@code-poel
code-poel / MageTest.php
Created March 11, 2014 14:41
Magento App Emulation
<?php
require_once('app/Mage.php');
Mage::app();
$stores = array_map(function($store) {
return $store->getId();
}, Mage::app()->getStores(true));
foreach ($stores as $store_id) {
// Setup app emulation

Keybase proof

I hereby claim:

  • I am wlvrn on github.
  • I am cv (https://keybase.io/cv) on keybase.
  • I have a public key whose fingerprint is 228E A7DC A7C4 58C1 7407 5D3A BDFA 0A21 5472 090A

To claim this, I am signing this object: