Nodejs, Express and NPM Introduction


Nodejs is an open-source, server-side, running environment.

  • Cross platform
  • Uses JS as language


Web developement framework for nodejs.


Node Package Manager.

  • Easy update and version management.
  • npm init => make package.json
  • npm install <package-name> –save => saves the package to package.json
    When saving a package to package.json there can be these string formats:
    “^4.x.x”  [Any release 4 major or minor version]
    “~4.13.x”  [Any minor version of 4.13]
    “4.13.2”  [Exact version]
    “*”  [Newest]
  • in  package.json, in scripts object write “start”: “node index.js”, in console write npm start. The start object would get run.

Some AI Terms

AI Applications:

  • Speech Recognition
  • Q&A
  • Automatic Dialog System
  • Text-to-Speech Converter
  • Machine Translation
  • Web Search
  • Spam Filtering, Text Classification
  • Face Recognition
  • Scene Segmentation
  • Image Classification
  • Robots
  • Theorem Provers
  • NASA Fault Diagnosis
  • IBM’s DeepBlue, the chess player
  • Google’s AlphaGo, the GO player
  • Fraud Detection
  • Recommendations


Rational Agent: An agent that can act and perceive in a way that maximizes utility.

Reflex Agent: Works on current state of world, uses mostly if-else.

Planning Agent: Asks what-if. Has a model of the world. Captures future.

Search Problems: 
[INPUT]: Abstract world state i.e. search space,
A successor function, updates and calculates
A start and a goal state
[OUTPUT]: Sequence of states, from start to goal state.

State Space Graph: Have set of search states connected with edges having cost or other related entities. No state is repeated. It is exponentially big.

Search Tree: Has start state as root and then each node is explored by the next possible move. No need to build the whole tree. A cycle in the graph means an infinite tree.

Introduction to AI/Computational Rationality

What is AI?
The definition is never definite. From the name, it is->Human-made Intelligence. Then question arises; what is Intelligence? I am going to answer this at the end.

There are four ways to arrive at the output of an AI based agent,
1. Think Like people
2. Act Like People
3. Think Rationally
4. Act Rationally
In the edX course, our objective is to learn the last method.

Rational means achieving your pre-defined goals to fullest by maximizing expected utility. Rationality is the outcome not the thought behind it.

Key Terms:
Act Rationally [That I am gonna read in the course]

Introduction to Machine Learning

What is Machine Learning?

Wikipedia: Field of study that gives machines the ability to learn without being explicitly programmed.
Examples are:
* Google, ever wondered how google suggests you searches using google instant and how pages are ranked in such a manner?
* How facebook identifies your friend(s) in a photo and how gives you ads?
* How Gmail decides whether a certain message is a spam or not?
* How Quora feed is organized and in what order digest mails are sent in your inbox?

Why we need Machine Learning?

Because of large data. The organizations have data to analyze and make models, if the work is given to some human it would be inefficient and error-prone. While the same work, if given to a machine, can be easily done without errors(if the error is not programmed!).

Mainly there are two types of applications: Classification and Clustering.
I will be writing about these in future posts.

Task: sudokuSolver

Finally, after so many days I am building something. It is a Sudoku Solver. We are team of two, Nancy and me.

So far, we have successfully executed the C++ code, now the task is to make a GUI of the solver. After taking some suggestion from around, umm.. one person, we are working on Qt for the GUI.
We both have downloaded qtcreator on our favorite OS Ubuntu with the command: sudo apt-get intsall qtcreator.
It is working fine with a good speed. Now , we are learning some basics of Qt from this youtube channel(The new boston), then we would be developing the main application.

The code would always be available here.


new, No Memory Allocation

via Dynamic memory – C++ Tutorials.

When new throws exception


using namespace std;

int main(void)
          int * ptr = new int[100000000];
     catch(bad_alloc &err)
          cerr<<"Error: "<<err.what();

When memory cannot be allocated further, then returning NULL from new expression

int *ptr = new (nothrow) int;
if(ptr == NULL) {cerr<<"Memory cannot be allocated.";}

If in the first case no try-catch would be used then program will crash. The first one is better than the second, because it is not required to check explicitly for the ptr to be NULL.

C vs. C++: Pass by value and reference

Recently I was reading insertion in a linked list in C and C++.
(Assuming that reader has some knowledge of basic coding of linked list)
If start pointer is passed in the function then double pointer is used in C and in C++, & is used to change start pointer(double pointer can also be used in C++, as C++ has many features of C).

void insert(struct node** start, int val)
    ... //do something
    *start = somethingNew;
... //function will be called as


void insert(struct node*& start, int val)
     ... //do something
     start = somethingNew;
... //function will be called as

By closely observing, it can be seen that in C there is nothing like passing by reference. C will always copy the argument(s) that will be passed to functions. In the above case(of C), the reference to start pointer is copied and the changes are done that will remain even after the function exits with respect to start node(extra: changes to the reference of start won’t be accounted outside). While C++ is genuine here, when it uses ampersand, it passes that object by reference and changes it.

To make it clear, lets take the case of insertion somewhere in the list, in that case the node after which some new node is to be inserted is passed to the function, in both languages single pointer does the job, Why?

void someFunction(struct node* someNode)
     someNode->data = 1;
     someNode->link = NULL;
     //someNode = someNewValue;

When some pointer is passed to this function, then copy of the address is made and when someNode->data (extracted as * is executed then the address would be dereferenced first, and data value is changed (similar for someNode->link).  Third line, if decommented, won’t make any difference outside this function (still not making any difference) as the copied address will change only.

MAC, IP and Gateway address

I was thinking of writing all about it by myself but this answer on Quora was so well written and knowledgeable that I thought of pasting it instead. This is the answer by anonymous:

MAC Address

A MAC address is a 6-byte hexadecimal address that allows a NIC to be uniquely identified on the network. The MAC address forms the basis of network communication, regardless of the protocol used to achieve network connection.A Media Access Control address (MAC address) is a  unique identifier assigned to a network interface card (NIC) by its  manufacturer. The network interface card is used to connect to the  Ethernet network. Each NIC has its own unique MAC address. The MAC  addresses are assigned permanently to adapters and cannot be changed as  they are a unique identification of the hardware interface of network.

The MAC addresses are stored in the NIC’s hardware, its read-only  memory, or some other firmware mechanism. The address encodes the  manufacturer’s registered identification number. A MAC address can also  be referred to as the burned-in address, Ethernet hardware address  (EHA), hardware address or physical address.

Packets that are sent on the ethernet are always coming from a MAC  address and sent to a MAC address. If a network adapter is receiving a  packet, it is comparing the packet’s destination MAC address to the  adapter’s own MAC address. If the addresses match, the packet is  processed, otherwise it is discarded.

The MAC addresses are formed and assigned according to the rules of one  of three numbering name spaces managed by the Institute of Electrical  and Electronics Engineers (IEEE): MAC-48, EUI-48, and EUI-64. The first  half of the MAC address tells what brand/model the card is, and the  second half is a unique identifier specific to that card.

For example, consider the MAC address of the computer on which this book is being written: 00:D0:59:09:07:51. The first three bytes (00:D0:59) identify the manufacturer of the card; because only this manufacturer can use this address, it is known as the Organizational Unique Identifier(OUI). The last three bytes (09:07:51) are then referred to as the Universal LAN MAC address: They make this interface unique.

How to find the MAC address of your computer(any version of Windows):-

  1. Open the command prompt. Press the Win+R keys and type cmd into the Run field. Press Enter(↵) to start the Command Prompt.
  2. Run GetMAC. At the command prompt, type getmac /v /fo list and press Enter(↵). This will display configuration information for all of your network connections.
  3. Look for the physical address which would be your MAC address

IP address
In order to transfer data from one location to another, it must first  know where the users are located. IP distinguishes these as IP  addresses. The IP address is a number that is assigned to each device,  such as a computer, a printer, etc. It describes where on the Internet  your computer is located. An IP address is required by any device that  participates in a computer network that uses the Internet Protocol for  communication.

There are two standards for IP addresses: IP Version 4 (IPv4) and IP  Version 6 (IPv6). All computers with IP addresses have an IPv4 address,  and many are starting to use the new IPv6 address system as well. Here’s  what these two address types mean:

  • IPv4 uses 32 binary bits  to create a single unique address on the network. An IPv4 address is  expressed by four numbers separated by dots. Each number is the decimal  (base-10) representation for an eight-digit binary (base-2) number, also  called an octet. For example:
  • IPv6 uses 128  binary bits to create a single unique address on the network. An IPv6  address is expressed by eight groups of hexadecimal (base-16) numbers  separated by colons, as in 2001:cdba:0000:0000:0000:0000:3257:9652.  Groups of numbers that contain all zeros are often omitted to save  space, leaving a colon separator to mark the gap (as in  2001:cdba::3257:9652).

How does your computer get its IP address? An IP address can be either  dynamic or static. A static address is one that you configure yourself  by editing your computer’s network settings. This type of address is  rare, and it can create network issues if you use it without a good  understanding of TCP/IP. Dynamic addresses are the most common. They’re  assigned by the Dynamic Host Configuration Protocol (DHCP), a service  running on the network. DHCP typically runs on network hardware such as routers or dedicated DHCP servers.

IP Classes
  • — This represents the default network, which is the abstract concept of just being connected to a TCP/IP network.
  • — This address is reserved for network broadcasts, or messages that should go to all computers on the network.
  • — This is called the loopback address, meaning your computer’s way of  identifying itself, whether or not it has an assigned IP address.
  • to — This is the Automatic Private IP Addressing (APIPA) range of  addresses assigned automatically when a computer’s unsuccessful getting  an address from a DHCP server.

The other IP address  reservations are for subnet classes. A subnet is a smaller network of  computers connected to a larger network through a router. The subnet can  have its own address system so computers on the same subnet can  communicate quickly without sending data across the larger network. A  router on a TCP/IP network, including the Internet, is configured to  recognize one or more subnets and route network traffic appropriately.

The following are the IP addresses reserved for subnets: to — This falls within the Class A address range of to, in which the first bit is 0.

  •  to — This falls within the Class B address range of to, in which the first two bits are 10.
  •  to — This falls within the Class C range of  through, in which the first three bits are 110.
  • Multi-cast  (formerly called Class D) — The first four bits in the address are  1110, with addresses ranging from to
  • Reserved for future/experimental use (formerly called Class E) — addresses to

Check this link to find the IP address:- How to Find the IP Address of Your PC

Gateway address
The gateway address (or default gateway) is a router interface connected to the local network that sends packets out of the local network. The gateway has a physical and a logical address.

Logical Gateway Address

The gateway operates at the network layer (Layer 3) of the OSI Model. The gateway is used when transmitting packets. When packets are sent over a network, the destination IP address is examined. If the destination IP is outside of the network, then the  packet goes to the gateway for transmission outside of the network. The  gateway is on the same network as end devices. The gateway address must  have the same subnet mask as host devices. Each host on the network uses the same gateway.
The gateway should have a static address, as changing the address  would cause packets not to be delivered. The gateway is typically  assigned either the highest or lowest network address. This is not a  requirement, but many organizations use a consistent addressing scheme  to facilitate network planning.

Physical Gateway Address

The gateway also operates at the data link layer (Layer 2) of the OSI network model. The physical gateway address is called the media access control(MAC) address or burned in address (BIA). The physical address is assigned when the device is manufactured, and cannot be changed. When a frame is sent to a device not on the local network, the gateway’s MAC address is used in the frame header.

You will need your default gateway to allow you to access your admin settings on your router.

After you find out what your default gateway is, you will  be able to make changes to your routers settings. You will use the  default gateway address to access your admin settings of your router. To  do this, type the default gateway address into the address bar of your  browser and hit enter. You will then be prompted for a username and  password. This information can sometimes be found on your router or  direction pamphlet. If you can’t find it on either, you can search the  internet by typing your routers make and model and “default  administrator password”. This will only work if you have not changed the  password on your router. If you have changed the default password and  forget it, you will need to reset your router.  or are both examples of default gateways.

How to find your Gateway address(for Windows users):-

1) Open the command prompt:- Press the Win+R keys and type cmd into the Run field. Press to start the Command Prompt.

2) Type “ipconfig”:- Next type ‘ipconfig’ and press enter Enter(↵) .

3)Look for the “default gateway” which would be the gateway address you are looking for.

#define and typedef

#define is a macro in C++ used as:

For example, `#define SIZE 100`,
Macro makes the replacements at the time of preprocessing, before compilation. All the values are put in expanded code before usual compilation starts.

typedef gives another name to a type and it is used as:
typedef TYPE NEW_TYPE;

Unlike #define it is interpreted by compiler and works as a new name for `TYPE`

See they are looking similiar, if I write #define TYPE int or typedef int INT what’s the difference here.

Difference: #define CHAR_PTR char* and typedef char* CHAR_PTR, lets take them one by one:

#define CHAR_PTR char*
CHAR_PTR a, b; //typeid(a).name = char* and typeid(b).name = char
               //because it is simply a replacement

typedef char* CHAR_PTR;
CHAR_PTR a,c; //typeid(a).name() = typeid(b).name = char*

Sources: StackOverflow, Let Us C, The C Programming Language -K&R