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 / Article.php
Last active December 14, 2023 21:35
I wanted to insert few Article instances to my database when I was working on a Lumen Laravel project, each Article belongs to one Category and belongs to one User. These newly generated instances have to to be related to existent category_id and user_id values in the categories table and users table. so I found this simple trick and wanted to s…
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
@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;
<?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 / 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)
@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 / 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 / portainer.md
Last active March 26, 2023 13:14
Portainer is a good alternative for docker desktop when working under Linux. Here is a small descriptive on how to get it ready to run on your machine.

This command runs a Docker container named "portainer" based on the "portainer/portainer-ce:latest" Docker image.

docker run -d -p 66666:8000 -p 66667:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

1. The "-d" flag

starts the container in the background. The "-p" flag binds two container ports (8000 and 9000) to two host ports (66666 and 66667) respectively, allowing access to the portainer web interface from outside the container.

2. The "--name" flag

sets the name of the container as "portainer". The "--restart" flag ensures that the container is always restarted automatically if it stops or if the Docker daemon is restarted.

@Azer5C74
Azer5C74 / sPhpStorm.sh
Last active March 26, 2023 12:58
Run phpstorm as sudo so you can edit all the project files. Make sure to add the permission to execute to the file by running this command : $ chmod +x sPhpStorm.sh
#!/bin/bash
# Find the path to PhpStorm
phpstorm_path=$(find / -name "phpstorm.sh" 2>/dev/null | head -n 1)
# Check if PhpStorm was found
if [[ -z "$phpstorm_path" ]]; then
echo "PhpStorm not found"
exit 1
fi
@Azer5C74
Azer5C74 / dockerwithoutsudo.md
Created March 9, 2023 17:49
Run Docker commands without sudo

Run Docker commands without sudo

  1. Add the docker group if it doesn't already exist

$ sudo groupadd docker

  1. Add the connected user $USER to the docker group

Optionally change the username to match your preferred user.

$ sudo gpasswd -a $USER docker

@Azer5C74
Azer5C74 / redshift configuration for all day night mode
Last active August 30, 2022 13:55
redshift.conf - configuration file for redshift and gtk-redshift (works fine for me with Linux Mint Mate) with Tromsø, Norway Lon and Lat parameter, 3500k date and night screen temperatures. You pick your city's coordinates from http://www.geonames.org/.
; Global settings for redshift
[redshift]
; Set the day and night screen temperatures
temp-day=3500
temp-night=3500
; Disable the smooth fade between temperatures when Redshift starts and stops.
; 0 will cause an immediate change between screen temperatures.
; 1 will gradually apply the new screen temperature over a couple of seconds.
fade=1