Skip to content

Instantly share code, notes, and snippets.

View jonatanrdsantos's full-sized avatar
🏠
Working from home

Jonatan Santos jonatanrdsantos

🏠
Working from home
View GitHub Profile
@jonatanrdsantos
jonatanrdsantos / prototype-update-select-option.md
Last active April 28, 2016 18:24
Update select option based in ajax request

PHP

    public function stateSearchAction()
    {
        $country = $this->getRequest()->getParam('code');
        $collection = Mage::getModel('directory/region')->getCollection()
            ->addFieldToFilter('country_id', $country)->getData();
        $this->getResponse()->clearHeaders()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody(Zend_Json::encode($collection));
    }
@jonatanrdsantos
jonatanrdsantos / Processlist MYSQL.md
Created May 14, 2016 18:45
Show processlist mysql

Show MySQL process list without sleeping connections

Usually you don't need to, but when you want to see which queries your MySQL server currently needs to handle (and if there are locks, etc), you could say SHOW PROCESSLIST in a MySQL shell.

Unfortunately, SHOW PROCESSLIST does not allow filtering. When you are on MySQL ≥ 5.1.7, do this instead:

SELECT * FROM information_schema.processlist WHERE command != 'Sleep' ORDER BY id;

That also allows you to only show some values or order differently, like so:

<?php
switch($_SERVER['HTTP_HOST']) {
case 'shoes.com':
case 'www.shoes.com':
$mageRunCode = 'shoes';
$mageRunType = 'website';
break;
@jonatanrdsantos
jonatanrdsantos / magento-custom-order-report.php
Created July 29, 2016 01:26
Magento custom order report to CSV
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
Mage::app();
//echo "Testando<br>";
$fromDate = date('Y-m-d H:i:s', strtotime('2016-05-28 00:00:01'));
$toDate = date('Y-m-d H:i:s', strtotime('2016-07-28 23:59:59'));
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToSelect('increment_id')
@jonatanrdsantos
jonatanrdsantos / remove-unused-media-catalog-image.php
Created August 30, 2016 16:17
Magento remove unused media catalog images
<?php
// Avoid any time limit
set_time_limit(0);
// Avoid any memory limit
ini_set('memory_limit', -1);
// Include bootstrap code and Mage class
require_once 'app/Mage.php';
@jonatanrdsantos
jonatanrdsantos / GEO.php
Created September 27, 2016 16:48
Geo php
<?php
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: :*/
/*:: This routine calculates the distance between two points (given the :*/
/*:: latitude/longitude of those points). :*/
/*:: :*/
/*:: Definitions: :*/
/*:: South latitudes are negative, east longitudes are positive :*/
/*:: :*/
@jonatanrdsantos
jonatanrdsantos / csv-to-varienObject.md
Last active October 17, 2016 14:26
Class To convert CSV data to Varien_Object

##Code

<?php
class Package_Module_Model_System_Config_Backend_ProcessCsv extends Varien_Object
{
    private $_csvFilePath;
    private $_headerIsValid;
    private $_validCsvHeader;
    private $_csvFileAsVarienFileCsv;
    private $_csvFileAsVarienObject;
@jonatanrdsantos
jonatanrdsantos / local.xml
Created October 21, 2017 16:13
sample local xml
<?xml version="1.0"?>
<!--
...
-->
<config>
<global>
<install>
<date><![CDATA[Sun, 28 Oct 2012 13:09:07 +0000]]></date>
</install>
<crypt>
@jonatanrdsantos
jonatanrdsantos / diasUteis.php
Created October 30, 2017 19:32
Calculo de dias úteis em php
<?php
function getWorkingDays($startDate, $endDate) {
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
return 0;
}
else {
$holidays = array('01/01', '03/04', '21/04', '01/05', '07/09', '12/10', '02/11', '15/11', '25/12');
$weekends = 0;
rsync -rave "ssh -i PEMKEYFILE.pem" /path/to/local/files/* ec2-user@EC2_INSTANCE_HOSTNAME:/path/to/remote/files