Skip to content

Instantly share code, notes, and snippets.

View carousel's full-sized avatar
🏠
Working from home

MiroslavTrninic carousel

🏠
Working from home
View GitHub Profile
<?php
require "../vendor/autoload.php";
use Symfony\Component\HttpFoundation\Request;
function curlProxy($params = null)
{
$request = Request::createFromGlobals();
$data = json_decode($request->getContent());
$curl = curl_init();
@carousel
carousel / links.js
Last active April 12, 2017 16:29
Extract links from HTML document
@carousel
carousel / Order.php
Created November 10, 2017 12:39
Guarding aggregate with invariant
<?php
class Order
{
protected $basket = [];
protected $maxSize;
protected $confirmed = false;
private function __construct($product)
{
@carousel
carousel / singleton.php
Created November 27, 2017 12:55
Singleton in PHP
<?php
class Student
{
protected static $instance;
public function __construct($name = null)
{
$this->name = $name;
}
public static function instance()
@carousel
carousel / IoCDI.php
Last active November 28, 2017 17:34
Most basic IoC/DI container in PHP
<?php
/*
|--------------------------------------------------------------------------
| PHP IoC/DI container
|--------------------------------------------------------------------------
|
| Most simple IoC/DI container implemented in PHP.
| Also includes interface implementation (duck typing is not allowed when binding
| concrete class to container)
*/
<?php
class Container
{
public $bindings = [];
/**
* @param $key
* @param $value
*/
<?php
function stackUnwind($n)
{
if ($n > 0) {
echo 'Parameter: ' . $n . PHP_EOL;
stackUnwind($n - 1);
}
foreach (debug_backtrace() as $key => $val) {
foreach ($val['args'] as $args) {
@carousel
carousel / stack.php
Created December 12, 2017 23:24
Stack abstract data structure
<?php
function push($item = null)
{
$stack = [];
if ($item) {
$stack[] = $item;
}
return $stack;
}
@carousel
carousel / binaryGap.php
Last active December 14, 2017 12:19
Binary gap algorithm
<?php
function binaryGap($n)
{
$result = [];
$tab = explode("1", decbin($n));
if ($tab[count($tab) - 1] != "") {
array_pop($tab);
}
foreach ($tab as $t) {
@carousel
carousel / hexagon.php
Created March 5, 2018 20:54
PHP hexagon + CQRS example
<?php
interface ReadPostRepository
{
public function byId(PostId $id);
public function all();
public function byCategory(CategoryId $categoryId);
public function byTag(TagId $tagId);
public function withComments(PostId $id);
public function groupedByMonth();