Skip to content

Instantly share code, notes, and snippets.

View Chemaclass's full-sized avatar
🏗️
building

Jose M. Valera Reales Chemaclass

🏗️
building
View GitHub Profile
(ns phel-exercises\exercise\count-words)
(defn- fill-keys
"Exchanges all keys with their associated values in an array."
[xs v]
(-> (to-php-array xs)
(php/array_fill_keys v)
(php-array-to-table)))
######################
@Chemaclass
Chemaclass / is_descent_branch.sh
Created April 15, 2021 20:06
Is descent git branch
pushedrev=$1
basename=${2:-develop}
if ! baserev="$(git rev-parse --verify refs/heads/"$basename" 2>/dev/null)"; then
echo "'$basename' is missing, call for help!"
exit 1
fi
parents_of_commits_beyond_base="$(
git rev-list --pretty=tformat:%P "$pushedrev" --not "$baserev" |
@Chemaclass
Chemaclass / moby-dick.txt
Last active March 22, 2021 19:44
Moby Dick (txt)
THE WORKS OF
HERMAN MELVILLE
STANDARD EDITION
VOLUME
VII
@Chemaclass
Chemaclass / MyBusinessLogicTest.php
Last active June 20, 2021 11:05
Unit testing effectively - Test example (Part II)
<?php
declare(strict_types=1);
namespace CompanyTest\Domain;
use PHPUnit\Framework\TestCase;
final class MyBusinessLogicTest extends TestCase
{
@Chemaclass
Chemaclass / MyBusinessLogic.php
Last active August 9, 2020 11:08
Unit testing effectively - Logic example (Part I)
<?php declare(strict_types=1);
namespace Company\Domain;
final class MyBusinessLogic
{
private DependencyInterface $dependencyInterface;
private ConcreteDependency $concrete;
public function __construct(
@Chemaclass
Chemaclass / TestLoggerSpy.php
Created June 8, 2020 03:41
An example using a Test Double Spy
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
interface Logger {
public function log(string $message): void;
}
final class LoggerSpy implements Logger {
public array $messages = [];
@Chemaclass
Chemaclass / CachedRemoteSiteManager.php
Last active April 17, 2020 08:10
This is the code that I used to verify locally my answer for a concret stackoverflow question
<?php declare(strict_types=1);
# https://stackoverflow.com/a/61230034/3454593
// Usage example:
$cacheManager = new CachedRemoteSiteManager(
new class implements CacheNormalizer {
public function normalize(string $text): string {
return substr($text, 17, 2);
}
},
@Chemaclass
Chemaclass / YieldTraining1.php
Last active April 17, 2020 08:10
This is the code that I used to verify locally my answer for a concret stackoverflow question
<?php declare(strict_types=1);
# https://stackoverflow.com/a/58767497/3454593
// Usage example:
$postWithImage = new PostWithImage(
$chaptersUrlApi = 'https://httpbin.org/get',
$imagesUrlApi = 'https://httpbin.org/get?{$key}={$value}'
);
foreach ($postWithImage->generate(20) as $post) {
@Chemaclass
Chemaclass / EdiFileGenerator.php
Last active October 17, 2019 13:57
EdiFileGenerator
<?php declare(strict_types=1);
final class EdiFileGenerator
{
private const MESSAGE_TEMPLATE = <<<STR
UNH+%d+IFTMIN:S:93A:UN:PN001'
BGM+340+0035800000000819%d+9'
DTM+10:20191002:102'
TSR+19+A2'
CNT+7:0.1:KGM'
@Chemaclass
Chemaclass / StripTagsWithArrayOfTagNames.php
Created September 22, 2019 12:55
Docu - Strip_tags() with array of tag names
<?php
// Instead of:
strip_tags($str, '<a><p>')
// You can now write:
strip_tags($str, ['a', 'p'])