Skip to content

Instantly share code, notes, and snippets.

@Eyad-Bereh
Eyad-Bereh / backup-storage.bash
Created January 18, 2024 21:09
A simple Bash Script To Backup Your Laravel Storage Folder And Send It To Telegram
#!/bin/bash
TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN"
TELEGRAM_CHAT_ID="TELEGRAM_CHAT_ID"
TELEGRAM_API_URL="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument"
STORAGE_PATH="/path/to/storage/folder"
PATH="/tmp/storage-backup" # temporary path to store backups
DATETIME=$(/usr/bin/date "+%F-%H-%M-%S") # get datetime in the format YYYY-MM-DD HH:MM:SS
FILENAME=$(printf "storage-backup-%s" "${DATETIME}") # form file name using the format
ZIP=$(printf "%s.zip" "${FILENAME}") # append ".zip" extension to resultant name
@Eyad-Bereh
Eyad-Bereh / EmailVerificationRequest.php
Last active April 6, 2023 07:51
Laravel E-mail verification without having the user to be logged in
<?php
// The original Illuminate\Foundation\Auth\EmailVerificationRequest which contains code that requires user to be logged in
// So that the verification process can work, since it's retrieving the user from the $request object
// Here, we are reading the id parameter from the route and using it to find the correct User model instead
// IMPORTANT NOTES:
// 1. This will only work with the App\Models\User model
// 2. Don't forget to remove the (auth) middleware from the (verification.verify) route
@Eyad-Bereh
Eyad-Bereh / laravel remove index.php from url.md
Created January 1, 2022 22:23 — forked from slow-is-fast/laravel remove index.php from url.md
[nginx] laravel remove index.php from url
# Remove index.php$
if ($request_uri ~* "^(.*/)index\.php$") {
    return 301 $1;
}

location / {
    try_files $uri $uri/ /index.php?$query_string;

    # Remove from everywhere index.php

if ($request_uri ~* "^(./)index.php(/?)(.)") {

@Eyad-Bereh
Eyad-Bereh / User.php
Created August 2, 2020 23:37
An example demonstrating how to implement Serializable and JsonSerializable interfaces in PHP - Exclusive for the group: https://www.facebook.com/groups/HTML.CSSandJavaScript/
<?php //php 7.2.24
declare(strict_types = 1);
class User implements Serializable, JsonSerializable {
private $id; /** @var string user id */
private $firstname; /** @var string user's firstname */
private $lastname; /** @var string user's lastname */
private $email; /** @var string user's email */
@Eyad-Bereh
Eyad-Bereh / CustomArray.php
Created July 31, 2020 14:22
An example demonstrating how to implement SeekableIterator, ArrayAccess, and Countable interfaces in PHP - Exclusive for the group: https://www.facebook.com/groups/HTML.CSSandJavaScript/
<?php //php 7.2.24
declare(strict_types = 1); // Necessary for type hinting to work
class CustomArray implements SeekableIterator, ArrayAccess, Countable {
private $arr; /** @var array contains the underlying array */
private $position; /** @var int contains the current position of the iterator */
private $size; /** @var int contains the current size of the array */
/**
@Eyad-Bereh
Eyad-Bereh / ClientApp.java
Created July 27, 2020 17:57
NAD Chapter 8 - 1 & 2 solutions
package app;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;
public class ClientApp {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
@Eyad-Bereh
Eyad-Bereh / App.java
Created June 26, 2020 18:41
Using a pool of threads, write a server in Java that echo any received message along with IP addresses and port number of the client.
package app;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class App {
private static final int POOL_SIZE = 10;
public static void main(String[] args) throws Exception {
@Eyad-Bereh
Eyad-Bereh / App.java
Last active June 26, 2020 18:37
Using the thread per connection, write a server in Java that echo any received message along with IP addresses and port number of the client.
package app;
import java.net.ServerSocket;
import java.net.Socket;
public class App {
public static void main(String[] args) throws Exception {
try (ServerSocket server = new ServerSocket(49512)) {
while (true) {
try {
package app;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class App {
public static void main(String[] args) throws Exception {
int PORT_NUMBER = 45012;