Skip to content

Instantly share code, notes, and snippets.

View bpacholek's full-sized avatar

Bartosz Pachołek bpacholek

View GitHub Profile

Task

Prepare test scenarios for the endpoint described below using Gherkin syntax (given when then). Try to find edge cases.

All inputs and outputs are handled in JSON format.

In sentences you may of course ignore format (json etc.) requirements and assume that you have received messages in valid structure and refer directly to particular fields by their node locations/names.

In first step you can assume anonymous user who has rights to create articles.

@bpacholek
bpacholek / hex2rgba.php
Created November 15, 2022 10:26
Converts hex to rgba
public function hex2rgba($color, $opacity = false): string
{
$default = 'rgb(0,0,0)';
//Return default if no color provided
if (empty($color)) {
return $default;
}
//Sanitize $color if "#" is provided
@bpacholek
bpacholek / gist:29d7705bed474310c7960a8de978d6ce
Created December 20, 2020 17:13
Set root password for fresh Mariadb
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
UPDATE mysql.user SET plugin = '' WHERE user = 'root' AND host = 'localhost';
FLUSH PRIVILEGES;
<?php
class FakeMoneyRounder
{
public function netToGross($net, int $tax)
{
if ($tax < 0 || $tax > 100) {
throw new InvalidArgumentException("Tax must be not be lower than 0% and not greater than 100%");
}
$taxValue = round(($tax + 100) / 100, 2);
@bpacholek
bpacholek / mssql_rows_count_per_table.sql
Created August 27, 2020 11:57
MSSQL Get rows count for tables
SELECT
t.NAME AS TableName,
i.name as indexName,
p.[Rows],
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
@bpacholek
bpacholek / php.bat
Created April 3, 2020 02:05
Allows to run PHP thru WSL
@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:d:=/mnt/d%
set v_params=%v_params:"=\"%
@bash -c "php %v_params%"
@bpacholek
bpacholek / phpcsfixer.bat
Created April 3, 2020 02:03
Allows to run PHP CS Fixer thru WSL
@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:d:=/mnt/d%
set v_params=%v_params:"=\"%
@bash -c "php-cs-fixer %v_params%"
@bpacholek
bpacholek / docker-del.bat
Created April 3, 2020 02:02
Removes all docker images
@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker rm %%i
FOR /f "tokens=*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi -f %%i
@bpacholek
bpacholek / findPrimeInRangeForWhichTwoPreviousPrimesPlusOneIsAlsoPrime.php
Created January 12, 2020 04:28
Finds prime numbers for which sum of previous primes numbers (in the range) plus 1 is also a prime number.
<?php
/**
* Checks if number is a prime number
*
* @param int $number
* @return bool
*/
function primeCheck(int $number) : bool
{
if ($number == 1) {
<?php
function mb_unserialize($string) {
$string = preg_replace_callback('#s:\d+:"(.*?)";#s', function($matches) { return sprintf('s:%d:"%s";', strlen($matches[1]), $matches[1]); }, $string);
return unserialize($string);
}