Skip to content

Instantly share code, notes, and snippets.

View Azer5C74's full-sized avatar
💭
I may be slow to respond.

Azer Taboubi Azer5C74

💭
I may be slow to respond.
View GitHub Profile
@Azer5C74
Azer5C74 / Decorator.php
Last active April 8, 2023 14:45
This is an example of decorator pattern usage written in php. We tried to add functionalities costs and descriptions dynamically without breaking the open-closed principle and modifying the basic inspection class.
<?php
interface CarService
{
public function getCost();
public function getDescription();
}
@Azer5C74
Azer5C74 / Strategy.php
Created April 8, 2023 17:09
This is an example of strategy pattern usage written in php. It helps to encapsulate a family of algorithms that perform similar functions, here we tried encapsulating various logging methods to an interface and making them interchangeable.
<?php
// Defining a family of algorithms
class LogToFile implements Logger
{
public function log($data)
{
var_dump('Log the data to a file.');
@Azer5C74
Azer5C74 / WheelSize.php
Created April 18, 2023 14:58
In this example each case in the WheelSize enum class has a $price property and a constructor that initializes the property. The getPrice() method is used to retrieve the price of a particular enum case. The $wheelSizePrices associative array maps prices to the corresponding WheelSize enum cases.
<?php
enum WheelSize: int
{
case size_20 = 20;
case size_24 = 24;
case size_28 = 28;
private int $price;
public function __construct(int $price)
<?php
// Loose comparison
if (0 == false) {
echo "0 equals false";
} else {
echo "0 does not equal false";
}
// Output: "0 equals false"
// Type juggling
@Azer5C74
Azer5C74 / databases_size.sql
Last active October 25, 2023 12:23
Smple SQL query to list all databases and sizes
SELECT
table_schema AS "information_schema",
SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)"
FROM information_schema.tables GROUP BY table_schema;