Skip to content

Instantly share code, notes, and snippets.

<?php
$tree = array(
"name" => "A", "child" => array(
"name" => "B", "child" => array(
"name" => "C", "child" => Null
),
),
);
var myElements = [ /* DOM Collection */ ];
for (var i = 0; i < 100; ++i) {
myElements[i].onclick = function() {
alert( 'You clicked on: ' + i );
};
}
// That wouldn't work. By the time the element is clicked, the variable i is 99. To make this work properly we cold use a closure to capture the value of i:
function getHandler(n) {
@paulmouzas
paulmouzas / throttle.py
Created January 20, 2016 21:47 — forked from ChrisTM/throttle.py
Python decorator for throttling function calls.
class throttle(object):
"""
Decorator that prevents a function from being called more than once every
time period.
To create a function that cannot be called more than once a minute:
@throttle(minutes=1)
def my_fun():
pass
@paulmouzas
paulmouzas / README.md
Created January 11, 2016 21:04 — forked from gsomoza/README.md
Magento CLI Media Cleaner

Magento CLI Media Cleaner

CLI utilities to clean the Magento media folders.

Features:

  • Clean unused images from the product catalog.
  • Clean the product catalog image cache.
  • Ready to use: automatically reads settings from app/etc/local.xml
  • FAST: I used it to safely clean about 45,000 images in just a couple of minutes.
@paulmouzas
paulmouzas / normalise.py
Created December 29, 2015 15:04 — forked from j4mie/normalise.py
Normalise (normalize) unicode data in Python to remove umlauts, accents etc.
# -*- coding: utf-8 -*-
import unicodedata
""" Normalise (normalize) unicode data in Python to remove umlauts, accents etc. """
data = u'naïve café'
normal = unicodedata.normalize('NFKD', data).encode('ASCII', 'ignore')
print normal
import MySQLdb
from MySQLdb.cursors import DictCursor
class DatabaseBridge():
def __init__(self, *args, **kwargs):
kwargs['cursorclass'] = DictCursor
self.cnx = MySQLdb.connect (**kwargs)
self.cnx.autocommit(True)
self.cursor = self.cnx.cursor()
<?php
include_once 'magento/app/Mage.php';
Mage::app();
$childproduct = Mage::getModel('catalog/product')->loadByAttribute('sku','red');
$parentproduct = Mage::getModel('catalog/product')->loadByAttribute('sku','mytestsku');
function _attachProductToConfigurable( $_childProduct, $_configurableProduct ) {
$loader = Mage::getResourceModel( 'catalog/product_type_configurable' )->load( $_configurableProduct );
$children = $_configurableProduct->getTypeInstance()->getUsedProductIds();
require_once 'app/Mage.php';
Mage::app();
function getCategoryIdByName($categoryName) {
$category = Mage::getResourceModel("catalog/category_collection")->addFieldToFilter("name" , $categoryName);
$cat_det=$category->getData();
$category_id=$cat_det[0][entity_id];
return $category_id;
}
$dir = new DirectoryIterator("./getbyname");
<?php
// script to remove categories from navigation menu
// $children = Mage::getModel('catalog/category')->getCategories(7);
require_once 'app/Mage.php';
Mage::app();
$category = Mage::getResourceModel("catalog/category_collection")->addFieldToFilter("name" , "Aphex Twin");
$cat_det=$category->getData();
$category_id=$cat_det[0][entity_id];
@paulmouzas
paulmouzas / update_categories.php
Last active September 28, 2015 18:20
update_categories.php
<?php
require_once 'app/Mage.php';
Mage::app();
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
if ($ids){
foreach ($ids as $id){