Instantly share code, notes, and snippets.

View mage-file-cache-clean.php
#!/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;
View core.clj
(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))])))))
View core.clj
(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
View core.clj
(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
View core.clj
(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)
View 2016-48.md

The first kata is the classic BowlingGame Kata from Uncle Bob.

Write a class named Game that has two methods

  • roll(pins : int) is called each time the player rolls a ball. The argument is the number of pins knocked down.
  • score() : int is called only at the very end of the game. It returns the total score for that game.

Here is the original PowerPoint from Uncle Bob with the instructions including the solution steps. The PPT file also includes the rules for the scoring of a bowling game.

View prime-factors.sh
#!/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
}
View install-mage2.sh
#!/bin/bash
FOLDER=example
DB_NAME=magento2
DB_USER=m2
DB_PWD=wiener
BASE_URL=http://example.dev/
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $FOLDER
View phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
colors="true"
bootstrap="./framework/bootstrap.php"
>
<!-- Test suites definition -->
<testsuites>
<!-- Memory tests run first to prevent influence of other tests on accuracy of memory measurements -->
<testsuite name="Memory Usage Tests">
View M2 acl.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
</resource>
</resources>
</acl>
</config>