Categories
DATA SCIENCE EMBEDDED PROGRAMMING PROGRAMMING PYTHON TUTORIALS WEB DEVELOPMENT

What Are Python Reserved Keywords?

Python reserved keywords are those words in Python programming language that have a specific meaning in a program. These keywords have specific actionable functionalities defined to it in Python. We are not allowed to re-use these reserved keywords. It is also not possible to override the keywords in Python.

Why Do We Have Python Reserved Keywords?

A programming language is defined by a set of keywords that have specific functionalities attach to it. Python programming language is no different from this. There are a set of keywords defined in Python language that performs specific tasks within the program where they are used.

Python Logo For Reserved Keywords In Python

For example, print is a keyword in Python which instructs the Python interpreter (i.e. the Python environment where Python programs run) to print a string to the output terminal. So a Python program line like:

print('Hello, World!')

will print the string:

Hello, World!

to the computer output screen that its user can see. We as a programmer are never allowed to use same keyword “print” for any other purposes like variable name or function name. Thus, we say that it is a Python reserved keyword.

Similarly, the keyword input is used to receive input from the user of a Python program. So a line in the program like:

user_name = input('Enter your name')

will display the string:

Enter your name

on the user screen and wait until the user enters his name. Once he enters the name and hits the “Enter” key, the name gets stored in the variable “user_name“.

So as you can see here, each of these reserved keywords such as print, input etc. each have a very specific functionality attached to it in Python language. We cannot use these same keywords as a variable name or function names. Trying to do so will result in the interpreter throwing error at us!

So now that we understand about reserved keywords in Python, what can we do about them?

For one, we need to know about all the Python reserved keywords to avoid using them in other ways in our program. But in addition to this, knowing about these reserved keywords and their intended functionalities will also help us write useful programs.

Using Reserved Keywords In Python Programs

Python programs are nothing but a bunch of reserved keywords used upon a set of variables to perform certain operations. So we use these set of keywords to write our programs. For example, if we take a look at the below program:

user_name = input('Enter your name')
print('Hello, ' + user_name + '!')

This program simply prompts for an user to enter his name. When he does so, it will just wish Hello to him by addressing his name. So when I run this program, the output I get is something akin to this:

'Enter your name'
> Amar
> Hello, Amar!

Conclusion

So in short, we can say that reserved keywords are a set of words in Python that have pre-defined meaning and functionalities associated with them. We make use of these keywords to write our program and we are not allowed to re-use the same words in our variables or function names. In other words, we are not allowed to alter their pre-defined meaning.

Categories
DJANGO PYTHON TUTORIALS WEB DEVELOPMENT WEB SERVER

Django Web Framework Beginner Tutorial – Introduction

What is Python Django?

Django is a Python based web development framework. It is a collection of libraries and tools that can be used to develop websites and web applications. Django uses Python as its primary backend programming language.

Learn more about Frontend & Backend components of a web app here

Why use Django Web Development Framework for developing a web app?

In the early days of internet, not many programming languages or supporting libraries were available for the development of websites. So, every website developer was writing many frequently used components repeatedly.

Python Django Web Development Framework

These included features like user authentication, database read/write, Cross Site Scripting (XSS)/malware protection code, database injection prevention code etc.

Every time a new website was built, web developer had to rewrite these pieces of code over and over again. This results in an increase in time to complete the project. It also exposes the website to certain vulnerabilities due to bad testing or bad design.

In order to overcome these, developers started to create a common web development framework. This contained all the frequently used components like authentication, session management code etc. These were later made available to others as part of the web framework libraries.

Soon enough, these libraries started being developed in different programming languages as well. Django is one such web application development framework that was developed using the Python programming language.

Why Use A Web Development Framework Like Django?

The main advantage of using Django is the number of readily available components it comes with. All the bells and whistles required to develop a basic web application is present in Django. Module like user management, admin dashboard, session management component, protection against XSS, CORS support are all readily available. This makes Django one of the quickest web development framework to get started with. You can go live with a website in no time because of this.

In addition to this, Django also comes with framework extensions such as Django Rest Framework (DRF) that can be also used to enhance the capabilities of a Django Web Application.

All these features of Django makes it one of the most appealing “all batteries inclusive” web app development framework in the tech industry.

In addition to this, if you are already familiar with the Python programming, then using Django becomes very easy.

Django is not the only Python web development framework. There exists other Python based web development frameworks like Flask, web2py and many more. But what makes Django different and easier to get started with is its all inclusive battery modules we discussed earlier.

Who is currently using Python Django Web Framework in real world?

Some of the top tech companies using Python Django includes Instragram, Quora, Mozilla, Disqus, National Geographic, Last.fm etc.

This was a theoretical introduction of Django. In the upcoming articles, we will get our hands dirty by using Django to develop a few simple web apps. This should give you a clear idea on the advantages of Django and why it is extremely useful.

Categories
DATA MINING DATA SCIENCE HTML JAVASCRIPT PROGRAMMING PYTHON STATIC WEBSITES TUTORIALS WEB DEVELOPMENT WEB SCRAPING

How To Extract Data From A Website Using Python

In this article, we are going to learn how to extract data from a website using Python. The term used for extracting data from a website is called “Web scraping” or “Data scraping”. We can write programs using languages such as Python to perform web scraping automatically.

In order to understand how to write a web scraper using Python, we first need to understand the basic structure of a website. We have already written an article about it here on our website. Take a quick look at it once before proceeding here to get a sense of it.

The way to scrape a webpage is to find specific HTML elements and extract its contents. So, to write a website scraper, you need to have good understanding of HTML elements and its syntax.

Assuming you have good understanding on these per-requisites, we will now proceed to learn how to extract data from website using Python.

Python logo on extracting data from a web page using Python
Python Web Scraper Development

How To Fetch A Web Page Using Python

The first step in writing a web scraper using Python is to fetch the web page from web server to our local computer. One can achieve this by making use of a readily available Python package called urllib.

We can install the Python package urllib using Python package manager pip. We just need to issue the following command to install urllib on our computer:

pip install urllib

Once we have urllib Python package installed, we can start using it to fetch the web page to scrape its data.

For the sake of this tutorial, we are going to extract data from a web page from Wikipedia on comet found here:

https://en.wikipedia.org/wiki/Comet

This wikipedia article contains a variety of HTML elements such as texts, images, tables, headings etc. We can extract each of these elements separately using Python.

How To Fetch A Web Page Using Urllib Python package.

Let us now fetch this web page using Python library urllib by issuing the following command:

import urllib.request
content = urllib.request.urlopen('https://en.wikipedia.org/wiki/Comet')

read_content = content.read()

The first line:

import urllib.request

will import the urllib package’s request function into our Python program. We will make use of this request function send an HTML GET request to Wikipedia server to render us the webpage. The URL of this web page is passed as the parameter to this request.

content = urllib.request.urlopen('https://en.wikipedia.org/wiki/Comet')

As a result of this, the wikipedia server will respond back with the HTML content of this web page. It is this content that is stored in the Python program’s “content” variable.

The content variable will hold all the HTML content sent back by the Wikipedia server. This also includes certain HTML meta tags that are used as directives to web browser such as <meta> tags. However, as a web scraper we are mostly interested only in human readable content and not so much on meta content. Hence, we need extract only non meta HTML content from the “content” variable. We achieve this in the next line of the program by calling the read() function of urllib package.

read_content = content.read()

The above line of Python code will give us only those HTML elements which contain human readable contents.

At this point in our program we have extracted all the relevant HTML elements that we would be interested in. It is now time to extract individual data elements of the web page.

How To Extract Data From Individual HTML Elements Of The Web Page

In order to extract individual HTML elements from our read_content variable, we need to make use of another Python library called Beautifulsoup. Beautifulsoup is a Python package that can understand HTML syntax and elements. Using this library, we will be able to extract out the exact HTML element we are interested in.

We can install Python Beautifulsoup package into our local development system by issuing the command:

pip install bs4

Once Beautifulsoup Python package is installed, we can start using it to extract HTML elements from our web content. Hope you remember that we had earlier stored our web content in the Python variable “read_content“. We are now going to pass this variable along with the flag ‘html.parser’ to Beautifulsoup to extract html elements as shown below:

from bs4 import BeautifulSoup
soup = BeautifulSoup(read_content,'html.parser')

From this point on wards, our “soup” Python variable holds all the HTML elements of the webpage. So we can start accessing each of these HTML elements by using the find and find_all built-in functions.

How To Extract All The Paragraphs Of A Web Page

For example, if we want to extract the first paragraph of the wikipedia comet article, we can do so using the code:

pAll = soup.find_all('p')

Above code will extract all the paragraphs present in the article and assign it to the variable pAll. Now pAll contains a list of all paragraphs, so each individual paragraphs can be accessed through indexing. So in order to access the first paragraph, we issue the command:

pAll[0].text

The output we obtain is:

\n

So the first paragraph only contained a new line. What if we try the next index?

pAll[1].text
'\n'

We again get a newline! Now what about the third index?

pAll[2].text
"A comet is an icy, small Solar System body that..."

And now we get the text of the first paragraph of the article! If we continue further with indexing, we can see that we continue to get access to every other HTML <p> element of the article. In a similar way, we can extract other HTML elements too as shown in the next section.

How To Extract All The H2 Elements Of A Web Page

Extracting H2 elements of a web page can also be achieved in a similar way as how we did for the paragraphs earlier. By simply issuing the following command:

h2All = soup.find_all('h2')

we can filter and store all H2 elements into our h2All variable.

So with this we can now access each of the h2 element by indexing the h2All variable:

>>> h2All[0].text
'Contents'
>>> h2All[2].text
'Physical characteristics[edit]'

Conclusion

So there you have it. This is how we extract data from website using Python. By making use of the two important libraries – urllib and Beautifulsoup.

We first pull the web page content from the web server using urllib and then we use Beautifulsoup over the content. Beautifulsoup will then provides us with many useful functions (find_all, text etc) to extract individual HTML elements of the web page. By making use of these functions, we can address individual elements of the web page.

So far we have seen how we could extract paragraphs and h2 elements from our web page. But we do not stop there. We can extract any type of HTML elements using similar approach – be it images, links, tables etc. If you want to verify this, checkout this other article where we have taken similar approach to extract table elements from another wikipedia article.

How to scrape HTML tables using Python

Categories
TUTORIALS VPS WEB DEVELOPMENT

Tutorial – Setting up a Ubuntu 16.04 VPS Instance on Vultr

In this article, we will learn about how to create a simple Virtual Private Server (VPS) running 64-bit Ubuntu 16.04 Operating System.

In case you have not created an account yet on Vultr, you can do so by visiting the link in the next paragraph and get $50 worth FREE CREDITS that you can use to create and use your Vultr Ubuntu VPS instances

Get Vultr VPS Worth $50 FOR FREE If you too would like to use Vultr VPS instance (which I strongly advise) while following these tutorial series, you can use the following Link to create your Vultr account and get $50 Free Credit which is more than sufficient to use and learn all about Linux, Web Development and much more for FREE!

Once you have created your Vultr account using the link above, you log into your Vultr account by visiting the Vultr Web App. Once you have logged in, you should be in the Products tab which would list all the Vultr instances you have created until now. Since your Vultr account is new, you will not have any instances listed there.

Vultr Dashboard displaying list of active Vultr instances created until now.
Vultr Dashboard displaying list of active Vultr instances created until now

But do not worry, this is about to change now.

Create a new Vultr VPS by clicking on the link that read “deploy now” at the end of that Vultr dashboard web page. You will then be taken to a new web page as shown below:

Vultr Deployment screen where new VPS instance can be created and deployed.
Vultr Deployment screen where new VPS instance can be created and deployed

Do not get perplexed by such a long web page with numerous options. While they may look baffling at first, it is actually pretty easy to use to create your first Vultr VPS instance. We will go through each of these options in a step by step fashion so that it is easier for you to follow and replicate.

Step 1 – Choose Server: Vultr not just provides services to deploy a VPS server, but also many more other products including Bare Metal Machine, Dedicated Cloud etc. However, in our case, we are only interested in deploying a simple VPS server running 64-bit Ubuntu 16.04 OS. Hence, we will simply choose “Cloud Compute” option which is what creates a VPS server.

Step 2 – Server Location: Next, we need to select where we want our VPS server to reside at. Vultr has its data centers spread across the globe and hence we have option to choose our VPS servers from various cities across the world as listed in the option. Choose the one which is closest to your and your web app’s visitors location is. This is because you will get a quick turn around time (time taken by the server’s response to be received) from your server if it is closest to your own location.

Step 3 – Server Type: In this option, we need to choose the type of Operating System (OS) we need to use. If for example we want to install 64-bit Ubuntu 16.04 OS, we select it over here.

Step 4 – Server Size: Next comes the size of the VPS server you want to deploy. This depends on a number of factors such as the amount of data size your app is going to use, the amount of traffic it gets, the speed of the CPU and the number of cores it holds etc. For tutorials and experiments, I usually just use the default selection of $10 per month VPS instance which gives comfortable performance for my requirements.

Step 5 – Additional Features: These are some advanced options which are not selected by default. These includes option to select IPV6 network addresses, backups etc. which I usually leave at its default unchecked state (in other words, I do not use it).

Step 6 – Startup Scripts: This option is useful if you need to run any additional scripts at the startup of your VPS instance. I have never used it until now so I may not be the right person to comment much about it! Sorry!! 😛

Step 7 – SSH Keys: SSH keys are special software keys that are used to create a secured shell protocol connection between your laptop/computer to your Vultr VPS server. In this option, you can generate SSH keys (using this tutorial) for your laptop and take the public part of the SSH keys and paste it here on the Vultr dashboard under this option. This way, you would not need to type in login and password every time you want to connect to your Vultr VPS server from your laptop’s command prompt.

Step 8 – Server Hostname & Label: Finally, you can create a new Hostname and label for your VPS server. This will result in the Vultr dashboard displaying this instance of the VPS server using this Hostname & Label.

Once you are done with filling up with all the above details in your Vultr dashboard, you can click on the “Deploy Now” button to create and deploy your Vultr VPS server. It may take a few minutes since clicking on the button after which your Vultr VPS server should be ready for use!

Hope this article gave you an insight into how to create and deploy a new Vultr VPS instance using Vultr dashboard. If you have any queries or any feedback on this article, do let me know in the comments below. Until next time, happy coding! 🙂

Categories
TUTORIALS VPS WEB DEVELOPMENT WEB SERVER

Things To Consider When Designing & Developing A Website

So you have decided to design and develop your own website? Great! But are you aware of all the things that you need to keep in the back of your mind when designing and developing your website? In this article, we will list some of the most important thing you need to consider when developing your website in 2019 & 2020.

1. Domain Name

The internet today is made up of over a billion of websites and web applications. With so many options at the tip of their hand, your website visitors will not be able to remember your website until and unless its name stands out from the crowd. So, pick a catchy website domain name that is easier for your website visitors to recollect in the future. Use the Namecheap’s search bar extensively to identify an easy to remember and available domain name. Ideally, a .com domain name is preferable over other domain name extensions as most of the non technical visitors by default assume the domain name to end with a .COM extension. It is also advisable not to use a name that is too long to remember or too many non interpret able characters such as vooooooooz.com (Here, it will be very difficult for your users to remember how many o’s are there in the domain name).

2. Web Hosting

Web hosting is the web server provider where your website will reside or hosted finally after web development activity is done. Where you host your website is very important as that becomes an important criteria in determining your website visitors satisfaction! Confused? You see, your website visitors will be very happy when your websites loads as quickly as possible. If it takes more than 10 seconds to load a web page, your website visitors will get frustrated and might close your website rather than waiting for it to completely load. As a result, the speed at which your web server delivers your website to its visitors plays a vital role in determining the ultimate customer satisfaction.

So how to determine which is the best web server to use?

Ideally, your web server must be located as close to your website visitor as possible. So for example, if your website visitors are mostly from the United States (US), you should host your website in a server located within the US. If your website is located in a far away location such as Australia, the amount of time required to deliver the web pages of your website from the server ot your website visitor will increase a lot!

What if your website visitors are coming from all across the world?

If you have a very generic website that appeals to all the people across the world, chances are you will have visitors coming into your website from across the globe round the clock. In such a case, where should we host the website? Well, the answer for this is to host your webserver across the globe!

Wait…what???

Yeah, you heard it right. If you are getting visitors from across the world, you will still need to deliver your web pages from the web server closer to your user’s location! But how to do that? Allow me to introduce you to the “Content Delivery Network” or CDN for short.

What does a Content Delivery Network or CDN do?

Content Delivery Network or CDN is a type of web service provided by certain set of CDN service providers whose main job is to host copies of your website across multiple web servers around the world. They will take care of determining where your website visitors are coming from and decide upon which CDN web server to use to serve web pages to them. In that way, you are ensuring that all of your visitors coming from across the world will get the same quality of website access as every other user from any other location in the world.

If you are just beginning with your website, you dont normally need to go for a CDN until you are able to determine the geographical locations from where majority of your website user base is located at. So, we will revisit again regarding CDN in the future and ignore it for now.

So now that we understand that our web servers need to be very fast and located closer to the website’s userbase, where do we look for a web server and how to determine a web hosting provider?

How to choose a web hosting provider?

There are different types of web hosting providers in the market. Some of them provide us with a managed hosting where they will manage the entire web server related issues and you will only need to worry about your website related parts. They also usually host not just your website on their server, but many other websites from other website owners as well in the same server. So, in other words, you will be sharing your website’s web server with other websites and hence they are usually called as the Shared Web Hosting service providers. One of the best example of such a Shared Web Hosting provider is the Namecheap shared hosting provider as shown below.

Shared Hosting with Namecheap

Using a shared hosting provider has its own set of advantages and disadvantages. One of the main advantage of using a shared hosting provider is that in that case the webmaster (aka website owner or website maintainer) need not worry about maintaining the web server part as it will be taken care of by the shared hosting service provider. On the other hand, one of the main disadvantage of a shared hosting provider is that since the same web server will be shared with other websites as well, the speed of the web server will be nondeterministic and usually slower. If one of the website in that shared hosting server gets high traffic, the other websites in the same server will be affected with its response time, thereby frustrating its users.

If you do not want to go for shared hosting, there are other types of web servers available to you. One such option is the Virtual Private Server (VPS).

In case of a Virtual Private Server (VPS), you will be the sole person in control of an entire virtual private server and it will not be shared with anyone else. This results in an increase and deterministic response time, all the time by your website to your website visitors. The other advantage of a VPS server is that since you have access to the complete VPS computer, you can install any software that you choose to, something that may not be possible when using a shared web hosting service provider. The downside, however is that this VPS will not be managed by the service provider and you will be completely responsible for maintaining the VPS server. There are many Virtual Private Server (VPS) providers in the market that are highly competitive and cost effective. One such service provider is the Vultr VPS service provider which provides a VPS server for as low as $2.5 per month! We highly recommend this VPS server if you are looking in to a VPS server option.

3. Design A Responsive Website For Mobiles

Now that we have covered the infrastructure part of a website – domain name and the web server, let us now start looking into the design aspects of a website.

Over 70% of the website traffic these days come from smartphones and tablets. As the mobile data rates continue to fall along with the fall of smartphone prices with excellent technical specs, this number of mobile visitors is only going to increase in the future. So what does this mean to your website?

Make your website responsive and mobile friendly!

What do we mean by a responsive website?

In the early days of web development, where there were not many devices with varying form factor – that is the size of the screen did not vary a lot, designing a website for these computer devices where reasonably easy. But with the advent of smartphone since 2007 – the year iPhone was launched, most of the website traffic started coming from these smartphones and every year this is only increasing. With the introduction of smartphones, web developerf faced a new challenge – huge range of smartphone computing device screen sizes!

By default, what the operating system of these smartphones do – such as the iOS of iPhone or Android is to shrink the size of a website to just fit enough into the screen size of the smartphone.

However, problem with such a scheme is that many of the links and buttons of the websites where user was supposed to take action on, became extremely difficult to click on thereby reducing the user experience (UX) of the website. This can be extremely frustrating to your website visitors and hence, an alternative design had to be thought of to handle mobile visitors to the website. This is when the Responsive Website Design was born!

In a Responsive Web Design, the website is designed in such a way that the size of the buttons, links, texts or images and the overall layout of the web page are determined depending on the size of the device’s screen and rendering accordingly, automatically!

The advantage now is that the visitors of your website need not have to fight with their smartphones and tablets to interact with your website. So always build your website using responsive design strategy.

One of the easiest way to design a responsive website if you do not have the time to learn every aspect of a responsive design is to use a frontend website framework such as Twitter’s Bootstrap. Using Bootstrap framework while building the frontend of your website will ensure that your website is always responsive!

4. Search Engine Optimization (SEO)

Finally, we also need to ensure our website is optimized for search engines such as Google, Bing, Yahoo, DuckDuckGo etc.

What is Search Engine Optimization (SEO)?

Most of the people use search engines such as Google or Bing to find answers to their queries. In return, the search engine will display a list of websites that is expected to answer those queries. In the early days of our website, when not many people will know about its existence will mostly end up on our website mainly through these search engines. If our website has answers to the queries asked by the search engine’s users and the searach engine thinks our website’s answers are better than other websites’ answers, it will display our website link above other websites, there by increasing the probability of the search engine user to click our link and visit our website.

So then, what are the parameters that we need to take care of to ensure the search engine such as Google places our website at the top of the search result? It is these set of parameters that becomes the basis of Search Engine Optimization (SEO).

Search Engine Optimization (SEO) as the name suggests, is the optimization methodology used on our websites to ensure that the search engines can easily traverse throughout our website’s web pages, analyze the content of our website for quality and hopefully determine the best position of our website in its results displayed to its users. The position given to our website in the search result for a particular query is called the search engine ranking of our web page for that query.

Our aim hence, will always be to figure out a way to get our articles to the top of as many search query results as possible. This is usually achieved by ensuring quality of the content of the website, ease of navigation across the web pages throughout the website – both for search engine bots as well as our website users, proper use of appropriate HTML tags depending on the content, easy readable hyperlinks & URLs, good amount of highly authoritative websites linking back (aka backlinks) to our web pages there by signalling the search engines that our articles are highly recommended by them etc.

Categories
HTML JAVASCRIPT LAMP PHP STATIC WEBSITES TUTORIALS WEB DEVELOPMENT WEB SERVER

Beginners Tutorial – What Is A Website?

We have all heard about different websites present on the internet such as Google, Youtube, Facebook, Twitter etc. But what exactly is a website? What is it made up of?

Imagine you just found a 100 year old book in your attic that contains a wealth of information about the world wars. It also has a collection of photographs that revealed some secrets that are lesser known to the public. You wanted to share this information with the world, but how?

One way is to go to the newspapers and get it published, but it can still not reach all the people across the world. What would be an easy and best possible way to share this information to people around the world? Publish it on the internet!

When you publish it on the internet, anyone from around the world having a computer or a smartphone with an access to the internet will be able to consume your content.

You can publish this information on social networking websites such as Facebook, Twitter or Youtube or create your own website to publish it.

A website example

So, a website, simply put, is a collection of information present in different formats such as texts, images, videos, graphs that is published on the internet to helps its users consume them.

But just like you, there are millions of people who are sharing information on the internet, so how do you make your contents accessible from other people’s information? This problem is very similar to having thousands of building in a city and needing to find a particular building. How do we do that? We will discuss about this in the future articles

Categories
HTML JAVASCRIPT LAMP PHP PYTHON TUTORIALS WEB DEVELOPMENT WEB SERVER

Basic Structure Of A Web App/Website

A website or a web app is usually made up of the following 3 web components:

These components are arranged as shown in the following diagram.

Structure Of A Web App
Location of the web app components on the internet

Web App Back-End component

All the core logic of a web app or website is usually implemented in the web app’s back-end component. This includes all the algorithms of the web app, code to perform any storing and retrieval of data from the database, url based route handling etc. All these code forms the back-end of a web app or website and runs on a specialized computer called the web server.

Backend component of the above image

The code for back-end programming can be written using several different programming languages such as PHP, Python, Java, Javascript, Ruby etc. Each of these programming languages comes with their own advantages and disadvantages like for example choosing a language like Python comes with the great benefit of having several readily available libraries useful for data crunching activities, however they can be relatively slow compared to other programming languages. So which backend programming language to choose largely depends on the type of functionalities required for the particular web app that is going to be developed.

Web App Front-End Component

All the visual and interactive elements of a web app or website comes under the Web app’s front-end component. Whenever the user of a web app or website visits the website, he will only see and interact with the web app’s front-end component. So as far as he is concerned, a web app for him is usually just the front-end component. It is what he sees and interacts with in his web browser.

Front end component of the above image

However, these front-end components will not usually store all the relevant data of a web page within itself but instead, will query for them by sending requests to the web app’s back-end component that was discussed earlier. These requests are usually sent using the HTTP protocol.

The programming languages used to write web app’s front end component includes HTML, CSS & Javascript. Among these, HTML is a markup language that a web browser will use to interpret what HTML components needs to be drawn on the browser screen to represent the website. CSS is a styling language used to customize the style (like change the color, size, background color etc.) of these HTML components. Finally Javascript is a programming language that can be used to add interactive functionalities to these HTML components.

With the help of these 3 programming languages, your front end should be highly interactive and user friendly for any non technical person to start using your web app.

Database component

A database is a specialized software used to store and retrieve data efficiently on a computer or a server. The database can sit in a web server along side the server software or can be present in its own seperate dedicated database server.

Database component

Databases are usually used in a web app (or website) to store all relevant data of that web app such as user data, session data, web app specific data etc. There are many different forms of databases available such as relational databases, NoSQL databases, Document Oriented databases, Graph databases etc. Each of these variants of databases have certain unique features that are useful in certain specific situations. The most common database type used in web apps are usually relational databases such as MySQL, PostgreSQL. However Document Oriented databases such as MongoDB are also used frequently.

So these 3 components forms the fundamental elements of a web application. Of course there can be more than these 3 components required as your web app continues to grow. You may need to add multiple servers, load balancers to manage higher traffic, caching mechanisms etc. We will discuss more on these modules further in future articles, but having the knowledge of above three fundamental components of a web app should give you the best start to learn and start working on the development of your first web application.

Do comment below if you liked the article or if you have any questions regarding the above topic and I will be happy to answer your questions. Until then, happy learning! 🙂

Categories
JAVASCRIPT STATIC WEBSITES TUTORIALS WEB BROWSER WEB DEVELOPMENT WEB SERVER

This one value in Javascript is not equal to itself!

We know that Javascript supports all kinds of values such as strings, numbers, constants etc. All these values are deterministic values in that their weights always remains the same. For example, an integer value of 25 is always equal to 25 in Javascript no matter what. Similarly a string value of “Hello” is also always equal to another string “Hello”.

In other words, these values in Javascript can always be compared with another value to determine if they are the same or different. To understand this better with an example, let us open up our browser console. In my case I am using Google Chrome browser console where we will create 3 variables with these values:

We can note from the above Javascript demo video that when the variable a and c are compared, since both their values are same holding a value of 2, they return true when compared with each other. On the other hand when variable a was compared with b, since their values were different, the comparison resulted in a return value of false.

This is true for all type of values present in Javascript – be it string, integers, floats, booleans anything you can think of.

However, there exists one special value in Javascript that is never equal to another variable having the same value. In other words its value is never equal to itself. This value is the NaN value!

NaN in Javascript stands for “Not a Number” and it is that one special value in Javascript which does not return true if it is compared with itself.

Why does NaN not equal to itself in Javascript?

Now you might be wondering why a NaN value does not equal to itself? The answer for this lies in the way Javascript language has been designed.

NaN or Not a Number is a special value in Javascript which is used to represent a nonsensical value – that is it is the value returned whenever a non sensical operation is performed. Now this is where it gets interesting. Why does a non sensical value not be the same all the time or at all the place? In other words, why is this happening here:

Why is it returning false?

The answer is that NaN as mentioned earlier is a value that is used to represent a non sensical values. So if the result of an operation performed is something that cannot be represented by ordinary or normal values, Javascript returns a value of NaN.

Now, if two operations results in non sensical values, they are not necessarily equal. Each of these operations can be returning two non sensical values of different weights. However, they both need to be represented by the value of NaN. Hence, the Javascript treats two NaNs as two different values and never equal to each other.

I learnt about this and many other similar anomalies in the book Eloquent Javascript. This is a very good book to learn and understand such interesting things about Javascript so I will definitely recommend this to anyone interesting in learning Javascript in depth.

If you are also aware of any other similar interesting things about Javascript do let me know in the comments below. Until then, happy coding! 🙂

Categories
BROWSER EXTENSION HTML JAVASCRIPT TUTORIALS WEB DEVELOPMENT

Write A Google Chrome Extension In 5 Minutes

What is a Google Chrome Extension and what does it do?

Google Chrome extension is a Google Chrome browser extension that acts like a plug-in which adds additional functionalities to your default Google Chrome web browser experience.

Google Chrome web browser comes with a default set of functionalities that are applicable to a wide range of use cases as utilized by all the websites out there. But if you have a requirement for additional browser functionalities that are not already supported by default in your browser, you can try to make use of the available Google Chrome browser extension APIs to create a browser extension that would fulfill your such requirement.

In other words, Google Chrome Extensions extends the functionality of the default Chrome browser by introducing new set of functionalities into it.

What programming language is used to write a Google Chrome Extension?

In order to write a Google Chrome browser extension, you just need to have basic web development knowledge. The programming languages used to develop Google Chrome browser extension are HTML, CSS and Javascript. Using just these 3 languages along with the provided Google Chrome Browser Extension Application Programming Interfaces (APIs), you will be able to develop your Google Chrome browser extension in no time!

With this background information in hand, let us now figure out how to write a new Chrome browser extension.

Getting started with developing Google Chrome extension

All Google Chrome browser extensions must have one required file, the manifest.json file. It is using this manifest.json file that the Google Chrome web browser can identify and display all the available information about your Google Chrome extension.

The manifest.json file will have entries related to your Google Chrome browser extension such as its name, description, version number of the extension, author name, permissions and many other metadata, all stored in JSON format.

So let us now go ahead and create a new directory which I called coolExt where we will store all the files related to this Google Chrome extension. Under this newly created directory, create our manifest.json file with the following content:

manifest.json (The only file required to get Chrome extension started!)
{
    "name":"Cool Extension",
    "description":"My new cool extension",
    "manifest_version":2,
    "version":"1.0",
    "author":"@digitallyamar"
}

You can see that this file contains a set of JSON key:value pairs. Here, each of these JSON key values such as “name”, “manifest_version”, “author” etc are already defined by Google’s Chrome API and hence we cannot alter it but use it as is. On the other hand, the values of these are determined by us according to how we want to describe and design our Chrome browser extension!

With the manifest.json file and its contents in place, it is now time to test our Google Chrome extension. In order to do so, open up your Google Chrome browser and in the address bar type: chrome://extensions

This should now open up a new Chrome Extensions window listing any Google Chrome extensions you might have already installed. At the top of this window, you should see an button called “Load unpacked“, click on it and browse to the “coolExt” directory where we have the above manifest.json file saved in and open it. This should now result in our Google Chrome extension getting installed into our Google Chrome browser and displayed as an installed extension in chrome://extensions

Google Chrome Extension Development In Action

There we have it! A basic version of our simple Google Chrome extension is created and installed into our Google Chrome browser. Although at the moment the Google Chrome extension is not doing much other than just describing itself and some other meta information, we have successfully created the basic framework for our Chrome extension.

We will in the next article continue to develop on this basic Chrome extension to bring in some interesting functionalities to our browser and to some of the websites we will visit. But that will be in the next article, so for now hope you got a basic understanding of how Chrome extensions are built under the hood. Checkout for the next article and if you have any comments on queries with respect to this article, do let me know in the comments below.

Until next time, happy coding! 🙂

Categories
HTML STATIC WEBSITES TUTORIALS WEB DEVELOPMENT WORDPRESS

Difference Between Link & Anchor Tag In HTML

HTML provides us with 2 different tags called the Anchor tag (represented by <a>) and the Link tag (represented by <link>). But what is the difference between the two? Can they be interchanged with one another? We will explore these queries in this article.

What is an HTML Anchor tag?

An anchor tag is used in an HTML file to help us link our HTML file’s texts to certain other web pages. In other words, it helps in the creation of hyper texts (<a>these are the hyper texts</a>) in HTML documents.

These other web pages that is linked into by the anchor tags can be present within the same website, or can be residing in a different website on a different web server altogether. But what is important is that the Anchor tags <a></a> are responsible for linking different web documents together through hyper texts and help user navigate from one web page to other in a simple mouse click!

It must be noted that all anchor tags are present only within the <body></body> section of an HTML page. They are never used in the <head></head> section of the HTML page. This is because the primary function of the Anchor tags <a></a> is to let web page users to move from one page to the other page. As the web page users can never see the content of <head> section, anchor tags are never used there!

So, in other words, we can say that Anchor tags <a> are used in the user visible part of an HTML web page so that the web page user can click on the Hyper Texts created by these Anchor tags and move from one web page to another.

What is an HTML Link tag?

On the other hand, our web page is not just made up of HTML web pages, but consists of one or more of Cascading Style Sheets (CSS) that are used to style the web page. It also consists of one or more Javascript files to provide interactive functionalities to the web page. These CSS files and the Javascript files are thus part and parcel of the web page and hence need to be linked to the web page. This is achieved using the <link> HTML tag.

The <link> HTML tag is hence used to link up all external resources such as CSS and Javascript files associated with a web page. This linking does not need to be seen by the final user as he only needs to get an integrated HTML web page rendered. As a result, the linking of these files, done through the use of <link> tag is done in the <head> meta section of the web page.

So these were the difference between Link tag Vs Anchor tag in HTML. Each of these tags have very unique functionalities to fulfill in their own roles and cannot be used interchangeably as we suspected in the beginning of the article.

With this, hope it became clear on the differences between Link and Anchor tags’ purpose in the creation of an HTML document. If you have any more queries or doubts between Link and anchor tags, let me know in the comments below and I will try to clarify your doubts.

Until next time, happy coding! 🙂