Create documentation for your projects. Like so:
- Up/Down - Previous/Next Gist
- Ctrl+e - Edit a selected Gist
- Ctrl+s - Save Gist
<?php | |
// I almost never use $installer = $this; instead I prefer to use the following | |
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup'); | |
// This is just an example of instantiating the setup class in the script. Of | |
// course I choose the appropriate setup class and resource on a case by case basis. | |
// That way it is very visible what setup class is being used. It can also be | |
// switched within a single setup script, for example to add attributes to |
#!/usr/bin/env bash | |
function assert_array_same { | |
if [ "${expected[*]}" != "${actual[*]}" ]; then | |
echo -e "\nFailed $1\nExpected: ${expected[*]}\nActual: ${actual[*]}" && exit 1 | |
else | |
echo -en "." | |
fi | |
} |
<?php | |
// app/code/local/Example/Profiler/Model/Observer.php | |
class Example_Profiler_Model_Observer | |
{ | |
/** | |
* Log the profiler statistics plus some information that helps identify the request | |
* | |
* @param Varien_Event_Observer $observer |
(ns prime-factors.core) | |
(defn generate-recursive | |
"Prime factor kata that does not use tail call optimization" | |
([n] (generate-recursive n [] 2)) | |
([n primes candidate] | |
(if (= 1 n) | |
primes | |
(if (= 0 (mod n candidate)) | |
(generate-recursive (/ n candidate) (conj primes candidate) candidate) |
(ns string-calculator.core | |
(:require [clojure.string :refer [join]])) | |
(defn numbers-from-string | |
[string] | |
(map #(Integer. %) (re-seq #"-?\d+" string))) | |
(defn add | |
[string] | |
(if (empty? string) 0 |
(ns print-diamond.core) | |
(defmacro abs | |
"Return the absolute value of the specified number. | |
This is a macro only for practice. | |
A regular function (max value (- value)) would work just as well" | |
[value] | |
`(if (pos? ~value) ~value (- ~value))) | |
(defn size |
(ns roman-numerals.core) | |
(def roman-numerals-map (array-map "M" 1000, "CM" 900, "D" 500, "CD" 400, "C" 100, "XC" 90, | |
"L" 50, "XL" 40, "X" 10, "IX" 9, "V" 5, "IV" 4, "I" 1)) | |
(defn arabic->roman | |
[n] | |
(if (= 0 n) "" | |
(let [[r v] (some (fn [[r v]] (if (<= v n) [r v])) roman-numerals-map)] | |
(apply str (concat (repeat (int (/ n v)) r) [(arabic->roman (rem n v))]))))) |
# I want to change the configured sample data name for a given magento package. | |
# | |
# (Alternatively I would like to change the source URL for a sample data package.) | |
# | |
# The following does not work as I intend it to. | |
# It adds a new record to the $this->commandConfig['magento-packages'] | |
# array instead of overwriting the extra sample-data value. | |
# | |
# Can this be done? |
#!/usr/bin/env php | |
<?php declare(strict_types=1); | |
use function array_reduce as reduce; | |
use function array_slice as slice; | |
use function array_filter as filter; | |
use function array_map as map; | |
$basedir = reduce(['.', '..', '../..', '../../..'], function ($acc, $basedir) { | |
return file_exists($basedir . '/vendor/autoload.php') ? $basedir : $acc; |