Skip to content

Instantly share code, notes, and snippets.

View nadyshalaby's full-sized avatar
🏠
Working from home

Nady Shalaby nadyshalaby

🏠
Working from home
View GitHub Profile
@nadyshalaby
nadyshalaby / Copy to Clipboard using Javascript
Created August 25, 2022 04:46
Snippet that allows you to copy data to clipboard using javascript
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
@nadyshalaby
nadyshalaby / worktree.md
Last active May 26, 2022 14:25
Git Worktree Most Used Command

Worktree most used commands

To open worktree from current bransh

git worktree add --detach <worktree-path> <branch-name>

To open worktree from remote branch

git worktree add --detach <worktree-path> <remote-name>/<branch-name>

To open worktree from commit

git worktree add --detach

@nadyshalaby
nadyshalaby / merge-tables.sql
Created April 20, 2022 13:11
This sql script can merge two tables with different columns without carrying out the headache of specifying the whole list of column names. This script can guess the match column names and remove duplicates on insertion process.
SET @target_table = '`klame_new`.`url`';
SET @source_table = '`klame_url`.`url`';
SELECT GROUP_CONCAT(column_name)
FROM INFORMATION_SCHEMA.COLUMNS a
WHERE a.TABLE_NAME = 'url'
AND a.TABLE_SCHEMA = 'klame_url'
AND a.COLUMN_NAME IN (
SELECT b.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS b
@nadyshalaby
nadyshalaby / .htaccess
Last active September 24, 2022 22:43 — forked from shakee93/.htaccess
Laravel Apache hide .env and several security settings via .htaccess
RewriteEngine on
# Disable Directory listing
Options -Indexes
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
@nadyshalaby
nadyshalaby / Dockerfile
Last active November 11, 2022 01:36
Docker Compose & Dockerfile to build any php application.
FROM php:8.1-apache
RUN apt-get update && apt-get install -y git \
libpng-dev \
zlib1g-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev libxpm-dev \
libfreetype6-dev
RUN docker-php-ext-configure gd \
@nadyshalaby
nadyshalaby / mysqldump.sh
Created January 7, 2022 22:00
Shell script to ease the database backup/restore process (Data Only)
#!/bin/sh
# This script is used to as a seeder for the database.
# It will dump a database data only or populate it.
# Show a drawing of word "MySQL Dumper Script by @nadyshalaby" on the screen.
echo "
_____________________________________
< MySQL Dumper Script by @nadyshalaby >
-------------------------------------
@nadyshalaby
nadyshalaby / .htaccess
Created October 20, 2021 13:06
Laravel .htaccess to enable routing from the base
RewriteEngine on
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
@nadyshalaby
nadyshalaby / AuthKey.p8
Last active February 10, 2021 11:54
Django Social Auth AppleID OAuth2 Backend for authenticating users across Flutter APP using package (sign_in_with_apple)[https://pub.dev/packages/sign_in_with_apple]
-----BEGIN PRIVATE KEY-----
MIGTAgohoMGByqGS....
.....etc.
-----END PRIVATE KEY-----
@nadyshalaby
nadyshalaby / gist:a6b0d3e98caf67e4e0c3a6d3741c531a
Created November 18, 2020 08:01 — forked from LuenCC/gist:e8dcf4a38096617799f3002644012af6
Laravel find nearest location in km from lat, long database
private function findNearestLocation(Request $request)
{
$location = DB::table('locations')
->select('name', 'latitude', 'longitude', 'region', DB::raw(sprintf(
'(6371 * acos(cos(radians(%1$.7f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%2$.7f)) + sin(radians(%1$.7f)) * sin(radians(latitude)))) AS distance',
$request->input('latitude'),
$request->input('longitude')
)))
->having('distance', '<', 50)
->orderBy('distance', 'asc')
@nadyshalaby
nadyshalaby / iframechange.js
Created November 11, 2020 07:32 — forked from hdodov/iframechange.js
HTML iframe URL change listener for tracking when a new iframe page starts to load
function iframeURLChange(iframe, callback) {
var lastDispatched = null;
var dispatchChange = function () {
var newHref = iframe.contentWindow.location.href;
if (newHref !== lastDispatched) {
callback(newHref);
lastDispatched = newHref;
}