Kernal, Linux commands, Uncategorized

LINUX(For Beginners) EP-1

Terminal:

The terminal isn’t just a simple terminal; it’s more like a terminal emulator. It’s a physical tool, much like a keyboard or monitor, used for interacting with the Shell through commands. The Shell is the user interface we use to communicate with the Linux operating system’s core, known as the Linux kernel. There are various shells available, such as bash and zsh.

You can identify which shell you’re using by executing the following command:

Mastering the Art of Linux Commands:

Now, let’s say you’re not so great at remembering all those complex commands. When you need assistance with any command, you can consult the manual by using the “man” command. For example:

if you’re unsure about how the “ls” command works, type:

Now, imagine you’re typing a command, like “Uname,” and you forget how it works. To get help with that specific command, you can use:

The Secret Weapon: “Apropos”

Sometimes, you may not even know which command to use for a specific task. In such cases, there’s a secret weapon – the “apropos” command. It helps you find the right command based on your intent.

For instance, if you need to discover what devices are connected to your computer through USB but can’t recall the command, try this:

Similarly, if you’re on a quest to find the perfect command for compressing a file, simply enter:

In simple terms, the terminal is like a communication tool that lets you talk to your computer’s core. If you forget a command or need help finding the right one, just use “man” or “apropos” to get the information you need. It’s like having a handy guide to navigate your way through Linux.

Uncategorized

HTTP & Web Servers

Prerequisites:

 You will need to install Python 3 locally on your Laptop.

Debian/Ubuntu/Mint: In the terminal, run

sudo apt-get install python3

After Installation make sure python3 is installed successfully, by checking the version

python3 --version

Nmap Network testing tooling

You’ll also need to install ncat, which is part of the Nmap network testing toolkit. We’ll be using ncat to investigate how web servers and browsers talk to each other.

Debian/Ubuntu/Mint: In the terminal, run

sudo apt-get install nmap

sudo apt-get install ncat

To check whether ncat is installed and working, open up two terminals. In one of them, run

ncat -l 9999

 in the other,

ncat localhost 9999

Then type something into each terminal and press Enter. You should see the message on the opposite terminal.

What is a Server

A server is just a program that accepts connections from other programs on the network.

When you start a server program, it waits for clients to connect to it. server waiting for your web browser to ask it for a page. Then when a connection comes in, the server runs a piece of code like calling a function to handle each incoming connection. A connection in this sense is like a phone call, it’s a channel through which the client and server can talk to each other. Web clients send requests over these connections, and servers send responses back.

a web server provides support for HTTP (Hypertext Transfer Protocol). As its name implies, HTTP specifies how to transfer hypertext (linked web documents) between two computers.

Running the first web server

So, let’s get started with the demo web server:

  1. Open up a terminal.
  2. cd into a directory that has some files in it ( text files, HTML files, or images ).
  3. Run python3 -m http.server 8000 in your terminal.

Look! The server tells me that it’s serving HTTP on port 8000.

When you start up the demo server, it will print a message telling you that it’s serving HTTP. Leave it running, and leave the terminal open. Now try accessing http://localhost:8000/ from your browser. You should see something like this

In my web browser, I see the demo server showing the same files that are in my Documents directory.

And that’s the Python demo web server, running on your own computer. It serves up files on your local disk so you can look at them in your browser.

When you put localhost:8000 in your browser, your browser sends an HTTP request to the Python program you’re running. That program responds with a piece of data, which your browser presents to you.

Look in the terminal where you ran the demo server. You’ll see a server log with an entry for each request your browser sent.

Hostnames

HTTPS URI includes the hostname of the web server, like www.google.com or www.cheeseboardcollective.coop

A hostname in a URI can also be an IP address: for example, if you put http://216.58.194.174/ in your browser, you’ll end up at Google.

The Internet tells computers apart by their IP addresses; every piece of network traffic on the Internet is labeled with the IP addresses of the sending and receiving computers. In order to connect to a web server such as www.google.com, a client needs to translate the hostname into an IP address. Your operating system’s network configuration uses the Domain Name Service (DNS)  a set of servers maintained by Internet Service Providers (ISPs) and other network users to look up hostnames and get back IP addresses.

In the terminal, you can use the host program to look up hostnames in DNS:

The output shows both an IPv4 address and an IPv6 address.

Another similar command called nslookup

This command also displays the IP address for the hostname you give it; but it also shows the IP address of the DNS server that’s giving it the answer

Send a Request

use ncat to connect to the demo server and send it an HTTP request.

Use ncat 127.0.0.1 8000 to connect your terminal to the demo server.

Then type these two lines:

GET / HTTP/1.1

Host: localhost

After the second line, press Enter twice. As soon as you do, the response from the server will be displayed a lot of text on your terminal.

Everything after the line Host: localhost is part of the server’s response.

Be a web server!

Use ncat -l 9999 to listen on port 9999. Connect to it with your web browser at http://localhost:9999/.

and see the response from the server in your terminal

Next, send an HTTP response to your browser by typing it into the terminal, right under where you see the headers the browser sent to you.

HTTP/1.1 307 Temporary Redirect

Location: https://www.eff.org/

At the end, press Enter twice to send a blank line to mark the end of headers.

Now again run http://localhost:9999/ on your browser you will see a webpage like.

So, that is it for this blog. Hope you will do it yourself. Do let me know your feedback in the comment section. I will really appreciate it.

Uncategorized

Docker on Ubuntu

Introduction

Docker is a Linux-based, open-source platform that developers use to build, run, and package applications for deployment using containers.

Containers:

Unlike virtual machine, Docker containers offer:

  • Allow running multiple applications in Isolation
  • Faster application execution
  • Lightweight( no need of full-blown Operating system)
  • Need less hardware resources
  • Use OS of the host

Docker containers essentially modularize the functionality of your application into multiple components that can be deployed, tested, or scaled independently as needed.

IMAGES:

Images contain instructions for creating a Docker container. Images define:

  • Application dependencies
  • The processes that should run when the application launches

You can get images from DockerHub or create your own images by including specific instructions within a file called Dockerfile

Docker Engine:

Docker Engine is the core component of a Docker architecture on which the application runs. Docker Engine as the application that’s installed on the system that manages containers, images, and builds.

A Docker Engine uses a client-server architecture 

Installing docker on Ubuntu

———————————————————————————————————————

Update the “apt” package index.

sudo apt update

To install docker type the following command in your terminal.

sudo apt install docker.io

Then start the docker services using command

sudo systemctl start docker

To download/pull the image for docker run the following command

docker pull hello-docker

check the downloaded images using command

docker image ls

we will run our hello-docker image using following command

docker run hello-docker

Output

Uncategorized

JavaSCRIPt

What is JavaScript? 

  • High level programming language.
  • Interpreted compiled programming language.
  • Language of the Browser/client.

JavaScript is an open source and cross-platform language and therefore mostly used for creating network-centric applications. JavaScript is used in web technologies to make web pages interactive. Along with HTML and CSS, JavaScript is widely used in web servers and databases.

Why to learn JavaScript?

  • It is client-side/browser programming language.
  • Build very interactive user interfaces with frameworks.
  • Interpreted (no need of compilers)
  • It is most popular & loved language around the globe.
  • Used to build client-side applications, also with the help of its frameworks namely Node.js and Express.js, it is now widely used to build server-side applications too.

VS code or any simple editor you can use to start Javascript.

let’s move to Javascript code.

Print hello world! in JavaScript

console.log("hello world!");

JavaScript console API

console.log("Hello World" , 4+6, "from Waqar");
console.warn("this is warning");
console.error("this is an error");

Variables in JavaScript


var number1 = 3.8;
var number2 = 2.2;
console.log(number1 + number2); 

Data types in JavaScript

//strings

var str1 = "This is Waqar";
var str2 = "This is also Waqar";
console.log(str1) 

//numbers
var num1 = 455;
var num2 = 34.21;

//objects
var marks = {
    Waqar: 97,
    Kashif: 98.32,
    kausar: 80

}
console.log(marks)

//Booleans
var a = true;
var b = false;
console.log(a,b);

var und;    //here we just declare a variable there is nothing stored in und so it in undefined
console.log(und);

var n = null;
console.log(n);         //null stored in var n

Operators in JavaScript


//Arithmatic operators
var s = 100
var t = 10
console.log("The value of s + t is " ,s+t );
console.log("The value of s - t is " ,s-t );
console.log("The value of s * t is " ,s*t );
console.log("The value of s / t is " ,s/t );

//Assignment operators
var c = s
c += 5;
console.log(c);

//Comparison operators
var x = 34
var y = 30
console.log(x>= y);
console.log(x<= y);
console.log(x == y);

// Logical operators   (AND)
console.log(true && true)
console.log(true && false)
console.log(false && true)
console.log(false && false)


// Logical operators   (OR)
console.log(true || true)
console.log(true || false)
console.log(false || true)
console.log(false || false)


// Logical not !

console.log(!false)
console.log(!true)

Function in JavaScript


function avg(a , b)
{
    return (a+b)/2;
}

//DRY = do not repeat yourself
c1 = avg(4,6);
c2 = avg(14,16);
console.log(c1, c2);

Conditional statements in JavaScript


//Single statement
var age = 10;
if(age > 18)
{
    console.log("You are Eligible");
}

//if-else statements
if(age > 18)
{
    console.log("You are Eligible");
}
else{
    console.log("You are not Eligible");
}

//if-else ladder

var marks  = 90;
if(marks >= 86)
{
    console.log("A+");
}
else if(marks > 78)
{
    console.log("A-");
}
else if(marks > 70)
{
    console.log("B+");
}
else if(marks > 50)
{
    console.log("pass");

}

else{
    console.log("F");
}

Arrays & it’s methods in JavaScript



let myArr = ["Fan" , true , null, 444];
console.log(myArr.length);
(myArr.pop());    //pop will delete last item from array
console.log(myArr);
myArr.push("waqar");  //it will add item into array
console.log(myArr);
myArr.shift();     //draw the first element  
console.log(myArr);
const  newLen = myArr.unshift("Ahmed");   //unshift will add item at start of Array
console.log(newLen);
console.log(myArr);

//string methods in JAVASCRIPT 

let mystring = "Waqar is good boy, Yes good boy";
console.log(mystring.length);
console.log(mystring.indexOf("Waqar"));    //Indexof will return index of string from start

console.log(mystring.lastIndexOf("Yes")); // lastIndexof will return  index of string from last 

console.log(mystring.slice(0,3));  

console.log(mystring.replace("Waqar" , "Ahmed"));

Iteration (Loops) in JavaScript


var array = [1,2,3,4,5];
for(let i =0; i<array.length; i++)
{
    console.log(array[i]);
}

let j = 0;
while(j<array.length)
{
    console.log(array[j]);
    j++;
}

do{
    console.log(array[j]);
    j++;
}while(j<array.length)


//break and continue statements

let arr1 = [1,2,3,4,5];
for(let i =0; i<array.length; i++)
{   
    if(i == 2)
        break;
    console.log(array[i]);
}

for(let i =0; i<array.length; i++)
{   
    if(i == 2)
        continue;
    console.log(array[i]);
}

Date and time in JavaScript

myDate = new Date();
console.log(myDate);
console.log(myDate.getTime());   //getTime will return time in seconds
console.log(myDate.getDay());  //getDay will return number from monday to that day
console.log(myDate.getFullYear()); //getFullYear will return years
console.log(myDate.getMinutes());   //getMinutes will return minutes currently

JavaScript DOM Manipulation


//DOM document object model (in any page links , images, names) are DOM
//we have some Dom methods with the help of these methods we can manipulate  the HTML as Dyanamacilly by JAVASCRIPT

// //DOM manipulation
let elem = document.getElementById('click'); 
console.log(elem);

let elemClass = document.getElementsByClassName('container');
console.log(elemClass); 

elemClass[1].style.background = 'red';
elemClass[1].classList.add('bg-primary');      //adding class to another class
elemClass[1].classList.add('text-success'); 

console.log(elemClass[0].innerHTML)  
console.log(elemClass[0].innerText)


tn = document.getElementsByTagName('div');
console.log(tn);

Events in JavsScript

function clicked()
{
    console.log("The button was clicked");
}
window.onload = function()
{
    console.log("The document was loaded");
}

//once our document loaded we can perform some operations
//here we work on first container

firstcontainer = addEventListener("click" , function(){      //it will be print on first container
    document.querySelectorAll('.container')[1].innerHTML = "<b> We have clicked </b>"
    console.log("click hua")



}) 


firstcontainer = addEventListener("mouseover" , function(){
    console.log("Mouse on container");

})


firstcontainer = addEventListener("mouseout" , function(){
    console.log("Mouse out of  container");
    
})
let prevHTML  =   document.querySelectorAll('.container')[1].innerHTML;
firstcontainer = addEventListener("mouseup" , function(){
    document.querySelectorAll('.container')[1].innerHTML = prevHTML;
    console.log("Mouse up on container");
    
})

firstcontainer = addEventListener("mousedown" , function(){      //when you will click 
    document.querySelectorAll('.container')[1].innerHTML = "<b> We have clicked </b>"
    console.log("Mouse down on container");
    
    
})

Arrow function in JavaScript


function summ(a,b){
    return a+b;
}

summ = (a,b)=>{   //we can write function by arrow which is same as normal fun but it will help when we have need a function between code.
    return a+b;
}

logkaro = ()=>{
    document.querySelectorAll('.container')[1].innerHTML = "<b>  set interval fired</b>"
    console.log("I am your log")
}

setTimeout and setInterval in JavsScript

setTimeout(logkaro , 2000);

clr = setInterval(logkaro , 2000);

//use clearInterval(clr)/clearTimeout(clr) to cancel setInterval and setTimeout

JavaScript localstorage


localStorage.setItem("name" , "waqar")
localStorage
localStorage.getItem("name")
localStorage.clear()
localStorage.removeItem("name")

JSON

obj = {"name": 'waqar', length: 1 , age: 25}
jso = JSON.stringify(obj)
console.log(jso)
console.log(typeof jso)

console.log(typeof obj)

So, that’s for JavaScript. Trust you appreciate it.

Uncategorized

MASM INSTALLATION In Windows/Ubuntu

In this blog, You will learn how to Install 32-bit masm. MASM (Microsoft macro assembler ) is a compiler that is used to compile the Assembly code to your machine.

If you are using Ubuntu or any Debian Linux OS then first you need to download** Virtualbox **and install **Windows OS **on it.

Video Link For Downloading and installing Virtualbox on Ubuntu:
https://youtu.be/NV9Vrm2qa_0

Now we will see how to install MASM in windows.

First, you need to go to your browser and download **MASM **you can go to the following link
https://www.masm32.com/

Click on download
Picture1.png

After that click on Western Europe

Picture2.png

Now Click on Download Dos MASM32 ….(4.72mb)

Picture3.png

Once it is downloaded to download and extract there. Then double click on the install it will start the installation. This will ask for many permission just click OK.

WhatsApp Image 2021-10-02 at 2.30.37 AM.jpeg

This will take some time. Once done, it will open the Welcome file. When you see that it means that the masm has been successfully installed.

WhatsApp Image 2021-10-02 at 2.38.02 AM.jpeg

HELLO WORLD IN ASSEMBLY LANGUAGE

Now open the masm and copy this code into it. This code will produce Hello World.

.

386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.

data

msg db "Hello world!!!", 0
cpt db "MY FIRST PROGRAM!!!", 0

.code
start:

invoke MessageBox, NULL, addr msg, addr cpt, MB_OK

invoke ExitProcess, NULL

end start

Save this file in the directory where you have masm installed. Put this file in the masm32 folder.

Then open masm and click on option project and then click on build all. Then it will Build and compile our code.

Picture4.png

Then you will open **CMD **in the directory in which u saved your **.asm file **and then you simply type your filename without .asm and then hit enter and you are done! You can see the output

Picture5.png

So, that’s it for this web journal. Trust you appreciate it. Do let me know about your criticism within the comment segment. I will truly appreciate it.