Skip to content

Instantly share code, notes, and snippets.

@uabassguy
uabassguy / php_no_xdebug
Created February 20, 2018 20:02
Temporarily run php cli without xdebug
#!/bin/sh
php_no_xdebug () {
temporaryPath="$(mktemp -t php.XXXX).ini"
# Using awk to ensure that files ending without newlines do not lead to configuration error
php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "$temporaryPath"
php -n -c "$temporaryPath" "$@"
rm -f "$temporaryPath"
@uabassguy
uabassguy / grepfile.sh
Created June 7, 2017 22:26
Read lines from a file then search a different file using those values
#!/bin/bash
# Accepts in.txt as input
# Uses strings found in search.txt
# Outputs to out.txt
# Test if in.txt exists in pwd
if [ ! -f in.txt ]; then
echo "Input data file not found. Please create in.txt"
exit 1;
fi
@uabassguy
uabassguy / Table.php
Last active August 29, 2015 14:26 — forked from IvanChepurnyi/Table.php
Optimized options load
<?php
/**
* Optimized version of attribute source options model
*
* That allows to preload options once and reuse them instead of doing calls to db all the time
*
*/
class EcomDev_Optimization_Model_Resource_Attribute_Source_Table
extends Mage_Eav_Model_Entity_Attribute_Source_Table
(declare -a tt && tt=( app/design app/code app/etc skin/frontend ) &&\
for t in "${tt[@]}"; do tree -fi -L 3 --noreport $t | awk 'NR > 2 { print $0 " " $0 }'; done)\
> modman
<?php
$file = fopen('csv/import.csv','r');
$data = fgetcsv($file, null, ",");
$fields = $data;
$i = 0;
$j = 0;
while (($data = fgetcsv($file, 1000, ",")) !== FALSE) {
foreach($data as $value){
$f = $fields[$i];
$parsed[$j][$f] = $value;
@uabassguy
uabassguy / setImages.php
Created September 27, 2013 04:12
Magento image import script (doesn't work)
<?php
ini_set('memory_limit', '-1');
require 'app/Mage.php';
Mage::app();
echo "Loading catalog...\n";
$products = Mage::getModel('catalog/product')->setStoreId(13)->getCollection()->addAttributeToSelect('*');
echo count($products) . " products selected for image import.\n";
// Remove unset images, add image to gallery if exists
@uabassguy
uabassguy / err.php
Last active December 22, 2015 17:29
Custom error handler
<?
function custom_error_debug($errno, $errstr, $errfile, $errline, $errvars) {
$message = "";
$message .= "[ " . date('Y-m-d h-i-s') . " ] Error: [$errno] $errstr on line $errline of $errfile ";
//Dump all info to browser!
//WARNING: Leave this commented except for extreme cases where you need to see all variables in use!
//Using this will cause excessive processing time, and RAM. Use only as needed!
/*if (!empty($errvars)) {
echo $message . PHP_EOL . "Variables in use: <pre>";print_r($errvars); echo "</pre>";