Open your terminal then open MongoDB
mongo
Navigate to your database
use myDbName;
Open your terminal then open MongoDB
mongo
Navigate to your database
use myDbName;
Open your terminal then open MongoDB
mongo
Navigate to your database
use myDbName;
Open your terminal then open Mongo Shell
mongo
Select your database
use myDbName
du -sh * | sort -h
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()
Open your terminal and type mongo
Then run the following command:
db.adminCommand( { listDatabases: 1 } )
Sometimes you update your stylesheet and and you don’t see any effects on the browser as if you had never mad any change.
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.
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.
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.
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
Just run the following command after you set git add
git reset
Run the following Command to remove the branch from remote repository
git push origin --delete remoteBranchName
To delete a branch from existing git directory in your machine, run the following command:
git branch -d localBranchName
When you send an email there are three options that you can add some recipients to any of these fields
Where the main recipient(s) receive the mail.
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.
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.
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 commandCtrl + G
: Goto line, You can move to particular line numberAlt + F12
: Peek definition, You can see preview of code for a functionCtrl + Shift + F
: Search in all files.Ctrl + Shift + H
: Replace in all the filesCtrl + B
: Toggle Slider BarIn this tutorial we will prepare our server in digitalocean droplet.
After login and redirect to your dashboard
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:
**
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 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.
Works exactly the way of Facebook Open Graph, but this time is for Twitter Summary Card instead.
All meta tag names starts with twitter:
Here is the full list of tags that should be included for each page
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
.
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:
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
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:
On Linux systems, to check who uses a certain port i.e 80
run the following command:
netstat -tulpn | grep :80
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
On Linux, a default config file path is:
/etc/mongod.conf
To create root user open the terminal then start the mongo shell
mongo
After its opened, run the following command:
use admin;
Sometimes you get the following error while trying to pull updates from remote repoistory:
fatal: refusing to merge unrelated histories
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.
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.
You will need to have Git Bash installed first.
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
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.
Here is a version of the ShopProduct class with a calculateTax()
method:
<?php
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;
}
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) {
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;
}
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
{
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.
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;
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)
{
// ...
}
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:
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
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.
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’s open source?
Why is it so important to know?
How to contribute to open source projects?
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
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:
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
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, 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);
The major highlights of Laravel 5.6 :-
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
Laravel 5.6 allows developers to easily change date format as per the project’s requirements.
Laravel 5.5 will require PHP 7.0+.
public function store()
{
$post = request()->validate([
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.
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?
Always the ceil method rounds any float
to the next integer.
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;
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.
These three are types of naming conversions used to declare variables, constants, functions and classes names.
StudlyCaseWords
Also called Pascal Case which makes the first letter of each word capital with no space or underscore between words.
Usually this type of naming conversion used with class names
in OOP in general