Skip to content

Instantly share code, notes, and snippets.

@octoxan
octoxan / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@octoxan
octoxan / responsive-frames.js
Last active April 11, 2017 15:02
Responsive iframes
jQuery(function ($) {
$(document).ready(function () {
if (typeof IFRAME_MARGIN == 'undefined') {
IFRAME_MARGIN = 5;
}
$('iframe').each(function (index, item) {
if ($(item).attr('src').match(/iframebasedomaingoeshere/)) {
//eg for a youtube video just replace the above with youtube
var w = $(item).attr('width');
var h = $(item).attr('height');
@octoxan
octoxan / MagentoSnippets.md
Created March 29, 2016 12:31 — forked from discountscott/MagentoSnippets.md
Magento Snippets

Magento Snippets

Clear cache/reindex

<?php
// clear cache
Mage::app()->removeCache('catalog_rules_dirty');
// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
@octoxan
octoxan / layout.xml
Last active June 24, 2016 17:37
Add Class to <body> in Magento
<reference name="root">
<action method="addBodyClass"><classname>whatever</classname></action>
</reference>
@octoxan
octoxan / heightLogger.js
Created July 8, 2016 17:50
Target Height Logger
$(document).on('click', function(e) {
console.log('my height is ' + $(e.target).height());
console.log('my outerHeight is ' + $(e.target).outerHeight());
});
@octoxan
octoxan / readCookie.js
Created July 9, 2016 13:57
Read Cookie Function
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
@octoxan
octoxan / .stylelintrc
Last active March 17, 2017 14:16
StyleLint config file
{
"rules": {
"declaration-colon-space-after": "always",
"indentation": ["tab"],
"max-empty-lines": 2,
"color-hex-case": "lower",
"color-hex-length": "short",
"number-leading-zero": "never",
"comment-empty-line-before": null,
"at-rule-empty-line-before": null,
@octoxan
octoxan / table-to-csv.js
Created September 2, 2016 13:53
Export HTML Table as CSV
function exportTableToCSV($table, filename) {
var $rows = $table.find('tr:has(td),tr:has(th)'),
// Temporary delimiter characters unlikely to be typed by keyboard
// This is to avoid accidentally splitting the actual contents
tmpColDelim = String.fromCharCode(11), // vertical tab character
tmpRowDelim = String.fromCharCode(0), // null character
// actual delimiter characters for CSV format
@octoxan
octoxan / getPriceRange.php
Last active September 28, 2016 13:01
Magento 1.x getPriceRange Function
function getPriceRange($productId) {
$max = '';
$min = '';
$pricesByAttributeValues = array();
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
$basePrice = $product->getFinalPrice();
@octoxan
octoxan / Collection.php
Created October 12, 2016 13:55
Patch for Magento Attribute sort order (app/code/local/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/)
<?php
/**
*
* Magento (has some problems)
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL: