Hasan Zohdy
du -sh * | sort -h
terminal#terminal
Hasan Zohdy

Count all directories in directory of one level

ls -l | grep "^d" | wc -l

Count all directories in directory of recursively

find .  -type d | wc -l
Continue reading
terminal#terminal
Hasan Zohdy

Count all files in directory in one level

find -maxdepth 1 -type f | wc -l

Count all files in directory recursively

find . -type f | wc -l
Continue reading
terminal#terminal
Hasan Zohdy

Count all lines and how many lines in each file

find . -name '*.php' | xargs wc -l

Sorted

find . -name '*.php' | xargs wc -l | sort -nr
terminal#terminalgit#git
Hasan Zohdy

To restore your database we’ll use mongorestore commands to restore or import our data

Import all database in a backup directory

mongorestore backup-directory

For example

Continue reading
MONGODB#MONGODBterminal#terminal
Hasan Zohdy

We’ll use mongodump to export our database

Export all databases

Run the following command:

mongodump
Continue reading
MONGODB#MONGODBterminal#terminal
Hasan Zohdy

Open your terminal and run mongo

Then run use databaseName and change databaseName to the real name of the database

Then run the following command:

 db.dropDatabase()
Continue reading
MONGODB#MONGODBterminal#terminal
Hasan Zohdy

List All Databases In MongoDB

Hasan Zohdy2 weeks ago

Open your terminal and type mongo

Then run the following command:

db.adminCommand( { listDatabases: 1 } )
MONGODB#MONGODBterminal#terminal
Hasan Zohdy

Problem

Sometimes you update your stylesheet and and you don’t see any effects on the browser as if you had never mad any change.

Cause

The main reason behind this is that browsers download assets Images | Stylesheets | Javascript Files and cache it in the user machine, therefore whenever the browser detects the same url for the asset it will load it from the user’s machine instead of the server.

Why browser do this?

To reduce number of sent requests to the server and also to make the website runs faster as the lower the browser sends requests the faster it will load the website.

Solution

Continue reading
CSS#CSSPHP#PHPJAVASCRIPT#JAVASCRIPT
Hasan Zohdy

Run a service in background

Hasan Zohdy3 weeks ago

Running a service in the background

  • Open the terminal window
  • Type screen
  • Type nohup your-command &
  • Press Enter
  • Type exit

And that’s it

terminal#terminal
Hasan Zohdy

Check if PHP process is running

Just write the following command in the terminal window:

ps -aef | grep php

This will list all php processes that are currently working.

Continue reading
terminal#terminal
Hasan Zohdy

On Linux

/etc/mongod.conf

On Windows

<install directory>/bin/mongod.cfg 
Continue reading
MONGODB#MONGODB
Hasan Zohdy

Generating Full Backup For MongoDB Database

To generate a full backup for entire databases in MongoDB Server, run the following command:

mongodump -o "/mongodb-backups/$(date +"%d-%m-%Y-%H-%M-%S")"

This command will ceate mongodb-backups directory in the root directory and will create inside it a directory that will contain all databases with the date of the created date followed by the time.

Continue reading
MONGODB#MONGODBterminal#terminal
Hasan Zohdy

Merge Two Branches Locally

Hasan Zohdy3 months ago

To merge a branch into another, for example we need to merge development branch into master branch.

git checkout master 
git add .
git commit -m 'Some commit'
git merge development
git#git
Hasan Zohdy

How to Undo a Git Add

Hasan Zohdy4 months ago

Just run the following command after you set git add

git reset
git#git
Hasan Zohdy

Run the following Command to remove the branch from remote repository

git push origin --delete remoteBranchName

git#git
Hasan Zohdy

Delete Branch Locally

Hasan Zohdy5 months ago

To delete a branch from existing git directory in your machine, run the following command:

git branch -d localBranchName

git#git
Hasan Zohdy

When you send an email there are three options that you can add some recipients to any of these fields

To

Where the main recipient(s) receive the mail.

CC

CC stands for Carbon Copy sends a copy of the email to the recipients in this field.

The recipients in this field usually just observes what is going on between you The sender and the ones who receive this mail in the To recipients field.

Continue reading
smackdown#smackdown
conf ma

I have downloaded Xdebug and php-debug extention as https://xdebug.org/wizard instructions, but I couldn’t make (step into and step over buttons, and the break point do not work either.

PHP#PHPvscode#vscode
Hasan Zohdy

Most Important Shortcuts in VSCode

Hasan Zohdy8 months ago

Here is a list of Visual Studio Code’s most important shortcut that will increase your productivity

  • Ctrl + P: Goto File, You can move to any file of open solution/folder in Visual Studio code.
  • Ctrl + Shift + O : Goto Symbol, You can move to any function, variable or symbol of the current file.
  • F12 : Goto Definition – You can move to the definition of symbol or function with this command
  • Ctrl + G : Goto line, You can move to particular line number
  • Alt + F12: Peek definition, You can see preview of code for a function
  • Ctrl + Shift + F: Search in all files.
  • Ctrl + Shift + H: Replace in all the files
  • Ctrl + B : Toggle Slider Bar
Continue reading
vscode#vscode
Mohamed Samir

Create Your Own Server Part1

Mohamed Samir8 months ago

In this tutorial we will prepare our server in digitalocean droplet.

After login and redirect to your dashboard

  • Click on the green button Create and choose from Droplets the drop down list, like the following image.
    Create droplet image
    After that it will open new page to complete create your droplet
  • Select your image: from distributions select Ubuntu like the following image.
    Choose a distribution
  • Then choose the suitable plan for you
Continue reading
ubuntu#ubuntuterminal#terminalnginx#nginxLARAVEL#LARAVELMYSQL#MYSQLPHP#PHP
Muhamed El-Kafrawy

There is a bad situation which you Cannot install any extensions on VSCode also trying to uninstall and re-install VSCode and not fixed, also Failed to Download it Manually.

The main problem is in the DNS server addresses.
**Here the steps to solve it:
**

  • Control Panel\Network and Internet\Network Connections
  • Change adapter setting
  • Right click on your WIFI network connection then properties
  • Internet protocol Version 4(TCP/IPv4)
  • Check the “ Use the following DNS server addresses ” option then write:
Continue reading
vscode#vscode
Hasan Zohdy

What is URL

URL stands for Uniform Resource Locator or simpler web address that locates a server “Website” or network.

URL Structure

A full structure for a URL is:

From Wikipedia:

Continue reading
Programming Concepts#Programming Concepts
Hasan Zohdy

A URL Life Cycle: Introduction

Hasan Zohdy8 months ago

Introduction

We all know when you hit a url in your browser, a website is being opened, but how that does happen and is url and the http protocol, we’ll dive deeply about that in this series.

Series Content

In this series we will get to know the following:

  • Http protocol
  • What is URL
  • URL structure
Continue reading
Programming Concepts#Programming Concepts
Hasan Zohdy

Previously we covered most meta tags that should be included in each page, now let’s have a look at the page content itself.

Headings

Headings in any pages are the hx tags, starting from the h1 to h6.

Headings structure the page content to tell Google how is your page is structured.

You probably want need more than one h1 in your page, however, you can add more than one if needed.

Continue reading
SEO#SEO
Hasan Zohdy

Twitter Cards

Works exactly the way of Facebook Open Graph, but this time is for Twitter Summary Card instead.

Meta Type

All meta tag names starts with twitter:

List Of Tags

Here is the full list of tags that should be included for each page

Continue reading
SEO#SEO
Hasan Zohdy

Previously we talked about the very basic meta tags that should be included in every single page of your website.

Now let’s talk about meta tags that is mainly used for Facebook bot crawlers to identify the content of your page, which are Open Graph.

What are Open Graph Meta Tags

Open Graph meta tags are snippets of code that control how URLs are displayed when shared on social media.

All graph meta tags starts with og:

Continue reading
SEO#SEO
Hasan Zohdy

Introduction

SEO for any website is considered one of the most important things that any owner/developer should take into considerations.

Why SEO

  • Your website will appear in search engines.
  • Your website will get more visits by being tracked by many websites/search engines.
  • And so much more.
Continue reading
SEO#SEO
Muhammed Yousrii

CSS - Complicated Nested Selectors

Muhammed Yousrii8 months ago

On this series we will go through some of the common bad CSS practices, and How and why we should avoid them,

This series addressed to different developers levels from new developers to experienced ones

Series Brief

When It comes to writing CSS, New developers (even Experienced ones) think that
using things like animations and transfroms and new CSS rules makes their CSS good,

but they overlook one important fact, that is the good CSS based on certain goals which should be achieved to make you CSS:

  • predictable
Continue reading
CSS3#CSS3CSS#CSS
Hasan Zohdy

Starting Nginx

Run the following command in your terminal:

sudo systemctl start nginx

Stopping Nginx

Run the following command in your terminal:

Continue reading
nginx#nginxubuntu#ubuntu
Hasan Zohdy

Get the process using port 80

Hasan Zohdy8 months ago

On Linux systems, to check who uses a certain port i.e 80 run the following command:

netstat -tulpn | grep :80
terminal#terminalubuntu#ubuntu
Hasan Zohdy

Get ssh key

Hasan Zohdy8 months ago

To get the generated ssh key, open your command line and write down the following command:

cat ~/.ssh/id_rsa.pub

Let’s examine the command.

  • cat >> print the content of the following file
  • ~ is the home directory
Continue reading
git#git
Hasan Zohdy

Default Config File Path

Hasan Zohdy8 months ago

On Linux, a default config file path is:

/etc/mongod.conf
MONGODB#MONGODB
Hasan Zohdy

Create root user in MongoDB

Hasan Zohdy8 months ago

To create root user open the terminal then start the mongo shell

mongo

After its opened, run the following command:

use admin;
Continue reading
MONGODB#MONGODB
Hasan Zohdy

Run MongoDB in the background

Hasan Zohdy8 months ago

By adding the --fork option in the command, MongoDB will start in background.

For Example

mongod --fork --logpath /var/log/mongodb/mongod.log

Set database path

Continue reading
MONGODB#MONGODB
Hasan Zohdy

Sometimes you get the following error while trying to pull updates from remote repoistory:

fatal: refusing to merge unrelated histories

Two possibilities when this can happen:

  1. You have cloned a project and, somehow, the .git directory got deleted or corrupted. This leads Git to be unaware of your local history and will, therefore, cause it to throw this error when you try to push to or pull from the remote repository.

  2. You have created a new repository, added a few commits to it, and now you are trying to pull from a remote repository that already has some commits of its own. Git will also throw the error in this case, since it has no idea how the two projects are related.

Continue reading
git#git
Hasan Zohdy

Generate SSH key

Hasan Zohdy9 months ago

Prerequisites

You will need to have Git Bash installed first.

Generating SSH Key

To Generate SSH key, open your terminal and write down the following command but change the mail to yours first:

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

You can skip all the following settings by pressing Enter

Continue reading
git#git
Amr Fekry

Traits

Amr Fekry9 months ago

As we have seen, interfaces help you manage the fact that, like Java, PHP does not support multiple inheritance. In other words, a class in PHP can only extend a single parent. However, you can make a class promise to implement as many interfaces as you like; for each interface it implements, the class takes on the corresponding type.So interfaces provide types without implementation. But what if you want to share an implementation across inheritance hierarchies? PHP 5.4 introduced traits, and these let you do just that.

A trait is a class-like structure that cannot itself be instantiated but can be incorporated into classes. Any methods defined in a trait become available as part of any class that uses it. A trait changes the structure of a class, but doesn’t change its type. Think of traits as includes for classes.Let’s look at why a trait might be useful.

A Problem for Traits to Solve

Here is a version of the ShopProduct class with a calculateTax() method:

<?php
Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Interfaces

Amr Fekry9 months ago

Although abstract classes let you provide some measure of implementation, interfaces are pure templates. An interface
can only define functionality; it can never implement it. An interface is declared with the interface keyword. It can contain
properties and method declarations but not method bodies.

<?php
interface Chargeable
{    
    public function getPrice(): float;
}
Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Abstract Classes

Amr Fekry9 months ago

An abstract class cannot be instantiated. Instead it defines (and, optionally, partially implements) the interface for any class that might extend it.You define an abstract class with the abstract keyword. Here I redefine the ShopProductWriter class
I created in the previous post, this time as an abstract class:

<?php
abstract class ShopProductWriter
{    
    protected $products = [];    
    
    public function addProduct(ShopProduct $shopProduct)    {
Continue reading
PHP#PHPOOP#OOP
Amr Fekry

Constant Properties

Amr Fekry9 months ago

Some properties should not be changed. The Answer to Life, the Universe, and Everything is 42, and you want it to stay that way. Error and status flags will often be hard-coded into your classes. Although they should be publicly and statically available, client code should not be able to change them.
PHP allows you to define constant properties within a class. Like global constants, class constants cannot be changed once they are set. A constant property is declared with the const keyword. Constants are not prefixed with a dollar sign like regular properties. By convention, they are often named using only uppercase characters:

<?php
class ShopProduct
{    
    const AVAILABLE      = 0;
    const OUT_OF_STOCK   = 1;
}
Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Static Methods and Properties

Amr Fekry9 months ago

All of the examples in the previous posts worked with objects. I characterized classes as templates from which objects are
produced, and objects as active instances of classes the things whose methods you invoke and whose properties you access.
I implied that, in object-oriented programming, the real work is done by instances of classes. Classes, after all, are merely
templates for objects.In fact, it is not that simple. You can access both methods and properties in the context of a class rather than that of an object. Such methods and properties are static and must be declared as such by using the static keyword:

<?php

class StaticExample
{    
Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Arguments and Types

Amr Fekry9 months ago

Type determines the way data can be managed in your scripts. You use the string type to display character data, for example,
and manipulate such data with string functions. Integers are used in mathematical expressions,
booleans are used in test expressions, and so on.
these categories are known as primitive types. On a higher level, though, a class defines a type. A ShopProduct object,
therefore, belongs to the primitive type object, but it also belongs to the ShopProduct class type. In this section,
I will look at types of both kinds in relation to class methods.Method and function definitions do not necessarily require that an argument should be of a particular type. This is both a curse and a blessing. The fact that an argument can be of any type offers you flexibility. You can build methods that respond intelligently to different data types, tailoring functionality to changing circumstances. This flexibility can also cause ambiguity to creep into code when a method body expects an argument to hold one type but gets another.

PHP is a loosely typed language. This means that there is no necessity for a variable to be declared to hold a particular data type. The variable $number could hold the value 2 and the string “two” within the same scope.
In strongly typed languages, such as C# or Java, you must declare the type of a variable before assigning a value to it, and, of course, the value must be of the specified type.This does not mean that PHP has no concept of type. Every value that can be assigned to a variable has a type. You can determine the type of a variable’s value using one of PHP’s type-checking functions.

Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Constructors

Amr Fekry9 months ago

A constructor method is invoked when an object is created.
You can use it to set things up, ensuring that essential properties are assigned values, essential methods are invoked and any necessary preliminary work is completed.

<?php

class ShopProduct
{    
    public $title;
    public $producerMainName;
Continue reading
PHP#PHPOOP#OOP
Amr Fekry

Methods

Amr Fekry9 months ago

Just as properties allow your objects to store data, methods allow your objects to perform tasks.
Methods are special functions declared within a class.
As you might expect, a method declaration resembles a function declaration. The function keyword precedes a method name, followed by an optional list of argument variables in parentheses. The method body is enclosed by braces:

<?php
public function myMethod($argument, $another)
{        
    // ...    
}
Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Objects

Amr Fekry9 months ago

If a class is a template for generating objects, it follows that an object is data that has been structured according to the template defined in a class. An object is said to be an instance of its class.

The new operator is invoked with a class name as its only operand and returns an instance of that class.

$product1 = new ShopProduct();
$product2 = new ShopProduct();

If you are still confused, Think of a class as a cast in a machine that makes plastic ducks. Our objects are the ducks that this machine generates. The type of thing generated is determined by the mold from which it is pressed. The ducks look identical in every way, but they are distinct entities. In other words, they are different instances of the same type. The ducks may even have their own serial numbers to prove their identities. Every object that is created in a PHP script is also given its own unique identifier. (Note that the identifier is unique for the life of the object; that is, PHP reuses identifiers, even within a process). I can demonstrate this by printing out the $product1 and $product2 objects:

Continue reading
OOP#OOPPHP#PHP
Amr Fekry

Classes

Amr Fekry9 months ago

In short, a class is a code template used to generate one or more objects
And a class is an entity that determines how an objects will behave and what the objects will contain, in other words it’s a blueprint to build to build a specific type of objects

You declare a class with the class keyword and an followed by the class name. Class names can be any combination of numbers and letters, although they must not begin with a number. The code associated with a class must be enclosed within braces.

<?php
class ShopProduct
{    
    // class body
Continue reading
PHP#PHPOOP#OOP
Amr Fekry

Object-Oriented Programming or OOPs refers to languages that uses objects in programming. Object oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc in programming. The main aim of oop is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.

OOP#OOPPHP#PHP
Mohamed Saad

One of the most important and helpful concepts is open source. It keeps our field, specially software, dynamic and active. Every developer should contribute in an open source project. Technologies and tools like React & Lodash are open source and waiting for contribution to enhance it and keep it efficient and great. Let’s see how is it going…

What we’ll talk about

  • What’s open source?

  • Why is it so important to know?

  • How to contribute to open source projects?

Continue reading
Programming Concepts#Programming Conceptsgit#git
Muhammed Yousrii

Creating links - Accessibility side

Muhammed Yousrii1 year ago

Introduction

Accessibility is one of the most ignored subject between developers in day-to-day developing.
And I argue you to visit Accessibility brief to know how accessibility is an important factor to concern on your next project


Anchor tag

The anchor tag is approximately the main building block of any project you worked on or you will work on, It can be used to refer to another:

Continue reading
HTML5#HTML5HTML#HTML
Hasan Zohdy

Pure Functions is part of Functional Programming that a function doesn’t depend on any external resources such as global variables, other functions, any type of remote requests or anything else except The given inputs which are the function arguments.

Another key of Pure Functions that it MUST NOT have a side effect such as throwing an error, logging or calling another function that may produce such things like these.

So Pure Functions are simply function that perform certain operations on the given arguments only that will always, always return same result.

Let’s see some examples to clarify it.

// js snippet code
Continue reading
Programming Concepts#Programming Concepts
Hasan Zohdy

What is Monkey Patch

Hasan Zohdy1 year ago

What is Monkey Patch?

In simple terms, Monkey Patch is a way to extend or modify an existing program or code.

Modifying existing code

Let’s say we want to change Math.PI from 3.141592653589793 to be 3.2

We can do it in that way:

Continue reading
Programming Concepts#Programming ConceptsJAVASCRIPT#JAVASCRIPT
shreen taher

What's New in PHP 7.4

shreen taher1 year ago

In this post we’re covering several changes and features that should be added to the language with the final release of PHP 7.4, which is scheduled to be released in November of 2019 :

Arrow functions

Arrow functions, also called “short closures”, are a way of writing shorter functions in PHP.

// A collection of Post objects
$posts = [/* … */];

$ids = array_map(fn($post) => $post->id, $posts);

Continue reading
PHP#PHP
shreen taher

What's New in Laravel 5.6

shreen taher1 year ago

The major highlights of Laravel 5.6 :-

API Controller Generation

Laravel 5.6 now offers API controllers that reduces the number of unnecessary create and edit actions that only return HTML. Use the following command to use API controller generation:

php artisan make:controller API/PhotoController --api

Eloquent Date Casting

Laravel 5.6 allows developers to easily change date format as per the project’s requirements.

Continue reading
PHP#PHPLARAVEL#LARAVEL
Hasan Zohdy

As web development grew up rapidly in the last few years, creating a website now takes different approach than the past.

Nowadays there are two ways to develop a website:

  • Single Page Application SPA.

  • Multi Page Application MPA.

What is Singe Page Application

Continue reading
smackdown#smackdown
shreen taher

What's New in Laravel 5.5

shreen taher1 year ago

Laravel 5.5 will require PHP 7.0+.

Sreamlined Request Validation

  • you can now directly call the validate method on your Request instance.
  • You also no longer need to pass the request as the first argument to the validator.
  • The second change made is that the validator returns the request data which you can store in a variable and pass on to the create method of the model.
public function store()
{
    $post = request()->validate([
Continue reading
LARAVEL#LARAVELPHP#PHP
Mohamed Samir

# General

  • Code MUST follow a “coding style guide” PSR [PSR-1]
<?php
namespace Vendor\Model;

class Foo
{
    const VERSION = '1.0';
    const DATE_APPROVED = '2019-06-01';
Continue reading
PHP#PHPOOP#OOP
Hasan Zohdy

Ceil VS Floor VS Round

Hasan Zohdy1 year ago

Almost in every programming language there is a Math class that offers these three methods ceil, floor and round, so what’s the difference between them.

Rounding numbers

First off, let’s understand what does these functions do.

In simple words, these methods round floats numbers to be integers but the point here is to what number they round these fractions?

Ceil

Always the ceil method rounds any float to the next integer.

Continue reading
smackdown#smackdown
shreen taher

What's new in php 7.3 ?

shreen taher1 year ago

is_countable check if something is countable.

When counting uncountable objects,you get warning. The is_countable function can help prevent this warning.

Note This is New feature in PHP 7.3 not exist in php 7.2 or lower version.

bool is_countable ( mixed $var )
$count = is_countable($variable) ? count($variable) : null;
Continue reading
PHP#PHP
Hasan Zohdy

What is PSR

And why it’s that important to know?

Who uses PSR?

PSR stands for PHP Standards Recommendations.

PHP Framework Interop Group! We’re a group of established PHP projects whose goal is to talk about commonalities between our projects and find ways we can work better together.

Continue reading
PHP#PHP
Hasan Zohdy

These three are types of naming conversions used to declare variables, constants, functions and classes names.

Studly Case

StudlyCaseWords
Also called Pascal Case which makes the first letter of each word capital with no space or underscore between words.

Used in

Usually this type of naming conversion used with class names in OOP in general

Continue reading
smackdown#smackdown