Skip to content

Instantly share code, notes, and snippets.

Avatar
🇪🇬

Kobus kobus1998

🇪🇬
View GitHub Profile
@kobus1998
kobus1998 / calculation-structure.php
Created Feb 12, 2021
simple price calculation structure
View calculation-structure.php
<?php
class Price
{
public function getAmount(): int
{
return 0;
}
}
@kobus1998
kobus1998 / extendable-singleton.php
Created Feb 8, 2021
extendable singleton class
View extendable-singleton.php
<?php
class Singleton
{
protected static $instanches = [];
private function __construct()
{
}
@kobus1998
kobus1998 / index.html
Created Jan 8, 2021
create custom html5 form rules
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="/" id="form">
<input type="text" fixed="abc" id="custom">
@kobus1998
kobus1998 / routes_example.php
Created Dec 29, 2020
php attributes example routes
View routes_example.php
<?php
#[attribute]
class Route
{
public $method;
public $path;
public function __construct($method, $path) {
@kobus1998
kobus1998 / csv_generator.php
Created Dec 17, 2020
generate a csv using a single function
View csv_generator.php
<?php
/**
* @var array[]
* @var string
* @var string
*/
function csv($aCsv, $sDelimiter = ',', $sLineBreak = "\n")
{
return implode($sLineBreak, array_map(
View flushExample.php
<?php
echo "Begin ...\n";
for( $i = 0 ; $i < 10 ; $i++ )
{
echo $i . "\n";
flush();
sleep(1);
}
echo "End ...\n";
@kobus1998
kobus1998 / Bcdec.php
Created Nov 24, 2020
bc math decimals wrapper
View Bcdec.php
<?php
declare(strict_types=1);
/**
* wrapper around the bcdec extension
*
* @see https://www.php.net/manual/en/book.bc.php
*/
class Bcdec
@kobus1998
kobus1998 / simple_backtrace.php
Created Nov 20, 2020
simple backtrace formatter
View simple_backtrace.php
<?php
/**
* clear overview of backtrace
*
* @return string
*/
function backTrace($traces = null)
{
$traces = $traces ?? debug_backtrace();
@kobus1998
kobus1998 / Singleton.php
Created Nov 16, 2020
Singleton extend class
View Singleton.php
<?php
class singleton
{
/**
* protect the construct
*/
protected function __construct()
{
}
@kobus1998
kobus1998 / LoggingMiddleware.php
Created Nov 10, 2020
log all outgoing requests using guzzle's handlers
View LoggingMiddleware.php
<?php
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
class LoggingMiddleware
{
/** @var LoggerInterface */
private $logger;