Skip to content

Instantly share code, notes, and snippets.

View moaalaa's full-sized avatar

Mohamed Alaa El-Din moaalaa

View GitHub Profile

Basic Query

# 6371 number is radius of earth in Km so we can use it to get distance in KM and 3959 to get distance in miles.

# Search Part: 6371 * acos( cos( radians($lat) ) * cos( radians( stores.latitude ) ) * cos( radians( stores.longitude ) - radians($long) ) + sin( radians($lat) ) * sin( radians( stores.latitude ) ) );

# SQL Ex: get all nearest places by KM
SELECT id, ( 6371 * acos( cos( radians($lat) ) * cos( radians( stores.latitude ) ) * cos( radians( stores.longitude ) - radians($long) ) + sin( radians($lat) ) * sin( radians( stores.latitude ) ) ) ) AS distance FROM stores ORDER BY distance;

# SQL Ex: get all nearest places by Miles
@moaalaa
moaalaa / Laravel-Container.md
Created September 14, 2021 17:04
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

input.addEventListener('keydown', stopNumbersInInput);
input2.addEventListener('keydown', allowNumbersInInput);
function stopNumbersInInput(e) {
let keyCode = (e.keyCode ? e.keyCode : e.which);
if (keyCode > 47 && keyCode < 58) {
e.preventDefault();
}
}
@moaalaa
moaalaa / 01 - Secure your new server.md
Last active December 4, 2025 16:34
Secure Server And Install cPanel

Secure your new server

All our commands are for AlmaLinux 9 and Ubuntu 24.04 only

Open Your ssh and start typing the following commands

Update System

# AlmaLinux 9
@moaalaa
moaalaa / 1.sh
Last active September 13, 2022 06:07
cPanel EasyApache 4 Installing Imagemagick and imagick PHP extension
yum -y install ImageMagick-devel ImageMagick-c++-devel ImageMagick-perl
@moaalaa
moaalaa / steps.html
Last active June 21, 2021 10:55
Set a Hash on uri and get it to change page dynamically on reload with the last view user has select
<div class="step" data-target="#basic-info">
<button data-tab-hash="basic-tab" type="button" class="step-trigger" role="tab" aria-controls="basic-info" id="basic-info-trigger" >
basic info
</button>
</div>
<div class="line"></div>
<div class="step" data-target="#comments-info">
<button data-tab-hash="comments-tab" type="button" class="step-trigger" role="tab" aria-controls="comments-info" id="comments-info-trigger">
SELECT full_name, phone, COUNT(phone) FROM users GROUP BY full_name, phone HAVING COUNT(phone) > 1
@moaalaa
moaalaa / 0- install nodejs and redis.sh
Last active February 13, 2025 11:12
How to run PM2 with laravel queue and laravel echo server
# Node Js
# Centos7
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install nodejs
# Ubuntu 20.04
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install nodejs
@moaalaa
moaalaa / BroadcastServiceProvider.php
Last active March 18, 2025 12:15
Realtime work around
<?php
namespace MixCode\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
@moaalaa
moaalaa / README.md
Created December 28, 2020 09:58 — forked from developius/README.md
Setup SSH keys for use with GitHub/GitLab/BitBucket etc

Create a new repository, or reuse an existing one.

Generate a new SSH key:

ssh-keygen -t rsa -C "your_email@example.com"

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings (https://github.com/settings/keys).

Test SSH key: