Skip to content

Instantly share code, notes, and snippets.

View alexsoyes's full-sized avatar

Alex alexsoyes

View GitHub Profile
@alexsoyes
alexsoyes / backup-owncloud.sh
Created September 22, 2019 16:46
Owncloud backup with database and directories
#!/bin/bash
set -e
# @explain this script is run by a cronjob every week
### “At 04:00 on Saturday.”
### 0 4 * * 6 /opt/backup-owncloud.sh > /home/alex/backup-owncloud.log 2>&1
# @vars defined
MAX_BACKUP_FILES=52 # keep my backup files during one year
@alexsoyes
alexsoyes / clamav-scan.sh
Created November 24, 2019 10:27
Weekly ClamAV scan with CLI
#!/bin/bash
set -e
# @explain this script is run by a cronjob every week
### “At 04:00 on Friday.”
### 0 4 * * 5 /opt/clamscan.sh > /home/alex/clamav.log 2>&1
# @vars defined
MAX_FILE_SIZE=128M # do not check files with size higher
DIRECTORY_TO_SCAN=/home/web/html/owncloud/
@alexsoyes
alexsoyes / open-closed-principle.php
Last active March 22, 2021 05:51
Open-Closed Principle : PHP
<?php
/**
* Open/Closed Principle in PHP
*/
interface NameableInterface {
public function theName(): void;
}
class User implements NameableInterface
@alexsoyes
alexsoyes / open-closed-principle-not-working.php
Last active March 22, 2021 05:52
Open-Closed Principle : PHP (not working)
<?php
/**
* Open/Closed principle in PHP (not working)
*/
class User
{
public $name;
public $firstname;
@alexsoyes
alexsoyes / single-responsibility-principle-not-working.php
Last active March 16, 2021 06:33
Single Responsibility Principle in PHP (not working)
<?php
/**
*** Single Responsibility Principle in PHP (not working)
**/
class UserService
{
public function updateFromAPI( User $user): User
{
// ...
@alexsoyes
alexsoyes / liskov-s-substitution-principle.php
Last active March 22, 2021 06:39
Liskov’s Substitution Principle in PHP
<?php
/**
* Liskov’s Substitution Principle (LSP) in PHP
*/
abstract class CMS
{
abstract public function findArticles(int $limit = 10): array;
/**
@alexsoyes
alexsoyes / interface-segregation-principle-isp.php
Last active March 25, 2021 05:02
Interface Segregation Principle (ISP) in PHP
<?php
/**
* Interface Segregation Principle (ISP) in PHP
*
* We have 2 dedicated Interfaces for 2 different needs.
*/
interface EntityInterface
{
public function getId(): int;
@alexsoyes
alexsoyes / interface-segregation-principle-isp-not-working.php
Last active March 23, 2021 05:38
Interface Segregation Principle (ISP) in PHP (not working)
<?php
/**
* Interface Segregation Principle (ISP) in PHP (not working)
*/
// ❌ We have only 1 interface for 2 different needs.
interface EntityInterface
{
public function getId(): int;
public function getName(): string;
@alexsoyes
alexsoyes / dependency-inversion-principle-dip-not-working.php
Last active March 22, 2021 17:02
Dependency Inversion Principle (DIP) in PHP (not working)
<?php
/**
* Dependency Inversion Principle (DIP) in PHP (not working)
*/
class PayPal
{
public function pay(int $amount): void
{
echo "Discussing with PayPal...\n";
@alexsoyes
alexsoyes / dependency-inversion-principle-dip.php
Last active March 20, 2023 10:38
Dependency Inversion Principle (DIP) in PHP
<?php
/**
* Dependency Inversion Principle (DIP) in PHP
*/
interface PaymentInterface
{
public function pay(int $amount): void;
}