Magento has recently merged an architecture proposal with the goal of removing non-composer modules.
At first this seems like a good idea, but I think there are some problems.
Magento listens to the community. That is a good thing.
(ns example.core | |
(:require [clojure.test :refer :all] | |
[clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop])) | |
;; ----------------------------------------------------------------------- | |
;; Application code to test | |
(defn includes? [needle haystack] |
Magento has recently merged an architecture proposal with the goal of removing non-composer modules.
At first this seems like a good idea, but I think there are some problems.
Magento listens to the community. That is a good thing.
#!/bin/bash | |
current=$(php --version | head -1 | cut -f2 -d' ') | |
current=$(echo "${current%.*}") | |
php_head=$(brew info php | head -1 | cut -f3 -d' ') | |
from=$([ "${current}" = "${php_head%.*}" ] && echo "php" || echo "php@${current}") | |
to=$([ "${1}" = "${php_head%.*}" ] && echo "php" || echo "php@${1}") | |
echo "Switching from $from to $to" |
#!/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; |
(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))]))))) |
(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 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 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) |
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.
#!/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 | |
} |