Skip to content

Instantly share code, notes, and snippets.

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

Mostafa Ezz MostafaEzzelden

🏠
Working from home
View GitHub Profile
@MostafaEzzelden
MostafaEzzelden / ftp_download.php
Created September 14, 2020 09:56 — forked from staatzstreich/ftp_download.php
Download a directory from an FTP Server
<?php
// ftp_sync - copy directory and file structure
// based on http://www.php.net/manual/es/function.ftp-get.php#90910
// main function witch is called recursivly
function ftp_sync($dir, $conn_id) {
if ($dir !== '.') {
if (ftp_chdir($conn_id, $dir) === FALSE) {
echo 'Change dir failed: ' . $dir . PHP_EOL;
return;
@MostafaEzzelden
MostafaEzzelden / mongo_dump_restore.md
Last active May 16, 2020 17:49 — forked from saggiyogesh/mongo_dump_restore.md
Mongodb dump and restore from mlab
  • install mongodb on local machine (mongodump & mongorestore) commands are required.
  • command dumping. to dump locally

mongodump -d dbname -o dumpname -u username -p password

  • command dumping to dump mlab database

mongodump -h xxx11.mlab.com:11 -u user -p password --authenticationDatabase release-db -d release-db -o /home/dumps

**Options** `-h`: mlab host:port, `-u`: db user, `-p`: db user password, `--authenticationDatabase` `-d`: mlab dbname, `-o`: path to store backupfiles
  • restore command, to restore locally

> mongorestore --db dname /home/dumps

@MostafaEzzelden
MostafaEzzelden / custom-paginator.md
Created March 2, 2020 10:09 — forked from paulofreitas/custom-paginator.md
Custom Google-like length-aware paginator for Laravel 5.4+
  • Save the helpers.php file in your app directory
  • Edit your composer.json manifest file to auloload this file:
    "autoload": {
        "files": [
            "app/helpers.php"
        ],
    // ...
@MostafaEzzelden
MostafaEzzelden / ID.js
Created October 30, 2019 09:42
ID - a unique ID/name generator for JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`
@MostafaEzzelden
MostafaEzzelden / portscanner.c
Created August 30, 2019 17:55 — forked from fffaraz/portscanner.c
Port scanner code in c
#include "stdio.h"
#include "sys/socket.h"
#include "errno.h"
#include "netdb.h"
#include "string.h"
#include "stdlib.h"
int main(int argc , char **argv)
{
struct hostent *host;
@MostafaEzzelden
MostafaEzzelden / perms.md
Last active July 23, 2019 19:26 — forked from stefanbc/perms.md
Set proper permissions on /var/www/

HOWTO

To set up permissions on /var/www where your files are served from by default:

sudo addgroup webmasters
sudo adduser $USER webmasters
sudo chown -R root:webmasters /var/www/html
sudo find /var/www/html -type f -exec chmod 664 {} \;
sudo find /var/www/html -type d -exec chmod 775 {} \;
@MostafaEzzelden
MostafaEzzelden / Laravel-Container.md
Created July 1, 2019 20:44
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).

@MostafaEzzelden
MostafaEzzelden / animatedScrollTo.js
Created February 7, 2019 13:03 — forked from joshbeckman/animatedScrollTo.js
ScrollTo animation using pure javascript and no jquery
document.getElementsByTagName('button')[0].onclick = function () {
scrollTo(document.body, 0, 1250);
}
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;
@MostafaEzzelden
MostafaEzzelden / flattenExceptionBacktrace.php
Created January 8, 2019 14:23 — forked from Thinkscape/flattenExceptionBacktrace.php
Make any PHP Exception serializable by flattening complex values in backtrace.
<?php
function flattenExceptionBacktrace(\Exception $exception) {
$traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace');
$traceProperty->setAccessible(true);
$flatten = function(&$value, $key) {
if ($value instanceof \Closure) {
$closureReflection = new \ReflectionFunction($value);
$value = sprintf(
'(Closure at %s:%s)',
@MostafaEzzelden
MostafaEzzelden / guzzle_post.php
Created December 25, 2018 10:28 — forked from juampynr/guzzle_post.php
Sample POST request with Guzzle
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'http://example.com',
]);