Skip to content

Instantly share code, notes, and snippets.

Vinai Kopp Vinai

Block or report user

Report or block Vinai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Vinai
Vinai / magento-composer-issues.md
Last active May 17, 2019
My beef with composer and Magento
View magento-composer-issues.md
View set-php-version.sh
#!/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"
@Vinai
Vinai / mage-file-cache-clean.php
Last active Jan 8, 2019
Quick to invoke version of bin/magento cache:clean
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;
@Vinai
Vinai / core.clj
Created Sep 22, 2017
Roman numerals kata in Clojure early while I was learning the language.
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))])))))
@Vinai
Vinai / core.clj
Created Sep 22, 2017
Print diamond kata in Clojure early while I was learning the language.
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
@Vinai
Vinai / core.clj
Created Sep 22, 2017
String calculator kata in Clojure done early while learning the language.
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
@Vinai
Vinai / core.clj
Created Sep 22, 2017
Prime factors kata early in me learning Clojure
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)
@Vinai
Vinai / 2016-48.md
Last active Dec 4, 2018
List of past code katas. The file names are the [year]-[week-of-year].md. I'll try to update the list each week.
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.

@Vinai
Vinai / prime-factors.sh
Created Dec 13, 2016
Language or testing frameworks or the lack thereof are no reason not to write tests. All that is needed is a function that calls the function to be checked.
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
}
@Vinai
Vinai / install-mage2.sh
Created Apr 25, 2016
Steps I use to install Magento 2 community edition
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
You can’t perform that action at this time.