Skip to content

Instantly share code, notes, and snippets.

@TemporaryJam
TemporaryJam / PHP config class
Last active August 29, 2015 13:56
PHP config class supporting dot notation
class Config
{
/**
*@var array
*/
private static $config = null;
/**
* Returns a config setting.
* @param string $name
@TemporaryJam
TemporaryJam / Magento - Get attributes by attribute group
Created September 3, 2014 13:14
Retrieves attribute codes by the attribute group name
$setId = $_product->getAttributeSetId(); // Attribute set Id
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($setId)
->setSortOrder()
->load();
$attributeCodes = array();
foreach ($groups as $group) {
if($group->getAttributeGroupName() == 'Somename'){ // set name
@TemporaryJam
TemporaryJam / Magento - Attributes
Created September 3, 2014 13:39
Various magento attribute notes
//Get attribute value, where 'technical_pdf' is attribute code
$_technical_pdf = $_product->getResource()->getAttribute('technical_pdf')->getFrontend()->getValue($_product);
//Get attribute frontend store label
$label = $_product->getResource()->getAttribute('attribute_code')->getStoreLabel();
//Get attribute value
$attribute_value = $_product->getAttributeText($attributeCode);
@TemporaryJam
TemporaryJam / Magento category fix
Created November 18, 2014 17:03
Magento categories not showing in admin
/** Check integrity */
SELECT c.entity_id, c.children_count as original_children_count, COUNT(c2.children_count) as `children_count`, c.level as original_level, (LENGTH(c.path)-LENGTH(REPLACE(c.path,'/',''))) as `level`
FROM mage_catalog_category_entity c
LEFT JOIN mage_catalog_category_entity c2 ON c2.path like CONCAT(c.path,'/%')
GROUP BY c.path
/** Fix child counts */
UPDATE mage_catalog_category_entity SET children_count = (SELECT COUNT(*) FROM (SELECT * FROM mage_catalog_category_entity) AS table2 WHERE path LIKE CONCAT(mage_catalog_category_entity.path,"/%"));
/** more info */
@TemporaryJam
TemporaryJam / PHP Download
Created June 2, 2015 04:04
PHP downloader with range support
<?php
/**
* Copyright 2012 Armand Niculescu - MediaDivision.com
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PR
function fireGaEvent(category, action, label, value)
{
if (null === category) {
category = 'Professional Learning';
}
if (ga) {
if (value !== undefined && value !== '') {
ga('send', 'event', category, action, label, value);
} else {
ga('send', 'event', category, action, label);
- Check for opcode caching (APC), built into PHP 5.5+, check it is enabled.
@TemporaryJam
TemporaryJam / RabbitMQ Clustering
Created September 20, 2013 07:51
RabbitMQ clustering guide
#To tell RabbitMQ to instruct Erlang to communicate on a certain range of ports, create a file at /etc/rabbitmq/rabbitmq.config with the following contents:
[
{kernel, [{inet_dist_listen_min, 9100},{inet_dist_listen_max, 9105}]}
].
#Now for the iptables configuration. Update /etc/sysconfig/iptables with the following rules:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5672 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 4369 -j ACCEPT
@TemporaryJam
TemporaryJam / Command line IP
Last active December 29, 2015 01:59
Find IP on the terminal (CLI)
wget http://ipecho.net/plain -O - -q ; echo
@TemporaryJam
TemporaryJam / getWorkingDays
Last active January 2, 2016 09:39
Calculate working days between dates
$nr_work_days = getWorkingDays('2014-05-01','2014-05-06', null);
echo $nr_work_days;
/**
* Calculate the number of working days between two dates.
* Note: The result is inclusive of the start and end date. Given two adjacent weekday dates the result is 2
* Return 0 if the start date is greater than the end date
* @param string $startDate Starting date
* @param string $endDate End date
* @param array $additional_holidays Additional holidays to remove from the calculation