Naga Sheet
Naga Sheet
NIE Mysuru, where I have maintained a strong CGPA of 8.5. I have a deep passion
for web development and excel in HTML, CSS, and Data Structures and
Algorithms.
1. Can you provide an overview of your "Play Now" project and its main
functionalities?
Answer: Certainly! "Play Now" is a full-stack video-sharing platform built using
the MERN stack (MongoDB, Express.js, React, Node.js). The platform allows users
to create accounts, upload videos, comment on and like videos, and engage with
other users' content. Key functionalities include:
User Authentication: Secure sign-up and login using JSON Web Tokens
(JWT) to ensure safe content sharing.
Video Management: Integration with Cloudinary for efficient storage and
streaming of videos, optimizing both upload and playback experiences.
User Engagement: Features like video uploads, comments, and likes to
enhance interaction and community building.
Responsive Design: Built with React to provide a seamless experience
across various devices.
2. Why did you choose the MERN stack for this project?
Answer: I chose the MERN stack for several reasons:
JavaScript Consistency: Using JavaScript across both the frontend and
backend simplifies development and allows for easier code management.
React's Flexibility: React offers a robust framework for building dynamic
and responsive user interfaces, which is essential for a video-sharing
platform.
Node.js and Express.js: These provide a scalable and efficient backend
environment, suitable for handling multiple user requests and real-time
interactions.
MongoDB: As a NoSQL database, MongoDB offers flexibility in handling
the varied and potentially unstructured data associated with user-
generated content like videos and comments.
Why Cloudinary?
We can’t store large media files like videos and images directly in our local
system because:
1. It would require our server to always be on for others to access the files.
2. Storing large files on the local system can quickly use up storage and
affect performance.
With Cloudinary, a cloud-based storage solution, we upload the media files to
their servers. Cloudinary provides:
Scalable storage for media files, which is always available online.
When we upload a file (like a video or image), Cloudinary stores it and
returns a URL.
We save this URL in our database, and the file can be accessed anytime
using this link.
This way, we don’t need to manage or maintain our own storage server, making
the process more efficient and reliable.
Tell the process how u integrated it?
1. File Upload: I used Multer middleware to first save the uploaded file
temporarily in local storage.
2. Cloudinary Setup: I configured Cloudinary with the necessary API
credentials to enable uploads.
3. Upload to Cloudinary: I wrote a function that takes the local file path,
uploads the file to Cloudinary, and gets a URL in return, which I store in
the database.
4. File Cleanup: After a successful upload, I delete the file from local
storage using fs to free up space and avoid keeping unnecessary files.
This approach ensures efficient file management and cloud storage integration.
How u retrieve and update or delete?
1. Retrieve Video: I store the URL of the uploaded video in the database. To
retrieve a video, I simply access this stored URL and stream the video from
Cloudinary or display it in the application.
2. Update or Delete Video: When a user wants to update or delete a video,
I first extract the video information from the URL stored in the database.
This helps me identify the video on Cloudinary.
3. Authentication: Before allowing any updates or deletions, I check if the
request is coming from the authenticated user who owns the video,
ensuring that only the rightful user can modify or delete the video.
This ensures secure video management and smooth handling of media files.
Cloudinary works through its API. After configuring Cloudinary with your API
credentials, you can use the API to upload files by sending them from your local
storage to Cloudinary’s cloud servers. The API responds with a URL for the
uploaded file, which is stored in your database for future access. You can also use
the API to update or delete files by referencing their unique IDs stored in the
URL.
So, the whole process of uploading, retrieving, updating, or deleting media is
handled through Cloudinary’s API.
About CORS?
CORS (Cross-Origin Resource Sharing) is a security feature that controls how web
applications can request resources from different domains.
By default, browsers block requests coming from a different domain than
the one the site is hosted on (cross-origin requests).
To allow requests from other domains, the backend must specify which
domains are "whitelisted" or allowed. This means if a request comes from
a whitelisted domain, the server will respond, but if it's not whitelisted, the
server will block the request.
This helps protect against unauthorized cross-origin requests while allowing
trusted ones.
About bcrypt?
Hashing Passwords: When a user creates or updates their password,
bcrypt will hash the password before storing it in the database.
This is done in the pre("save") middleware:
Comparing Passwords: When a user logs in,
bcrypt is used to compare the entered password with the stored hashed
password.
React:
useState:
Definition: useState is used to add state to functional components.
Purpose: It lets you declare a state variable and a function to update it.
The component re-renders when the state changes.
useEffect:
Definition: useEffect is used to perform side effects in functional
components.
Purpose: It runs a set of instructions after every render or when
dependencies change (e.g., fetching data or subscribing to a service).
Helps optimize performance by preventing unnecessary re-renders . it re-
renders only when dependencies is changed
useCallback:
Definition: useCallback returns a memorized version of a callback
function.
Purpose: It helps optimize performance by preventing unnecessary re-
creations of the callback function, which can be useful for passing
callbacks to child components that rely on reference equality.
useContext:
Definition: useContext allows you to access the value of a React Context.
Purpose: It simplifies passing data through the component tree without
having to pass props down manually at every level.
useRef:
Definition: useRef creates a mutable object that persists across renders.
Purpose: It can be used to access DOM elements directly or to keep a
value that doesn't trigger re-renders when changed.
useNavigate:
Definition: useNavigate is a hook provided by React Router (v6 and later)
for navigation.
Purpose: It allows you to programmatically navigate to different routes in
your application.
Second Normal Form (2NF): To achieve 2NF, a table must first be in 1NF.
Additionally, all non-key attributes must be fully functionally dependent on the
entire primary key. For example, in a table with a composite key (StudentID,
CourseID) and a non-key column like "InstructorName," if "InstructorName" only
depends on "CourseID" and not on the entire composite key, the table is not in
2NF. To fix this, you would separate the course information into another table.
Third Normal Form (3NF): To be in 3NF, a table must be in 2NF and must not
have transitive dependencies. This means that non-key attributes should depend
only on the primary key, not on other non-key attributes. For example, if you
have a table with columns "StudentID," "AdvisorName," and "AdvisorPhone," and
"AdvisorPhone" depends on "AdvisorName," then it's a transitive dependency. To
achieve 3NF, you should create a separate table for advisor details.
A super key is a set of one or more columns (attributes) in a table that can
uniquely identify each row (tuple) in the table. It can contain extra attributes that
are not necessary for uniqueness.
A primary key is a column (or set of columns) that uniquely identifies each row
in a table. It must contain unique values and cannot contain NULLs. Each table
can have only one primary key.
A foreign key is a column or set of columns in one table that refers to the
primary key of another table. It is used to create a relationship between the two
tables and enforce referential integrity.
Primary Index:
How it works: The table is sorted based on the primary key, and the
index stores the key values and points to the corresponding rows.
Secondary Index:
How it works: The secondary index doesn't alter the physical order of the
table, but it stores a separate reference to the indexed column for quick
lookups.
Example: If EmployeeName is not the primary key but you often search
by name, a secondary index on EmployeeName will speed up those
searches.
Clustered Index:
How it works: There can only be one clustered index per table
because it organizes the actual rows in the order of the index.
View in DBMS:
A view is a virtual table that provides a way to look at data from one or more tables
without storing the actual data separately. It's essentially a saved SQL query that can
simplify complex queries or provide a layer of security by restricting access to
specific columns or rows.
A view of data in DBMS is created to display the specific information that a user
needs, rather than revealing sensitive portions of the schema that should remain
confidential to the owner.
WHERE: Filters rows before any groupings are made (used with SELECT, UPDATE,
DELETE).
HAVING: Filters groups after the GROUP BY clause has been applied.
DELETE: Removes rows from a table based on a condition, can be rolled back,
and triggers are executed.
TRUNCATE: Removes all rows from a table but does not log each row deletion, is
faster, cannot be rolled back, and does not trigger triggers.
Difference from a function: While both stored procedures and functions are
used to encapsulate SQL logic, a function typically returns a single value and can
be used in a SQL query, whereas a stored procedure does not return a value but
can perform a variety of actions, including modifying the database.
Example: Suppose you need to update multiple related tables whenever a new
employee is added. You could use a stored procedure to handle all necessary
updates in one go, ensuring that all related records are updated consistently.
Example: Suppose you have a Sales table and want to keep a log of all changes
made to this table. You can create an AFTER-UPDATE trigger that inserts a record
into an Log table whenever a row in the Sales table is updated.
OOPS:
A virtual function is a member function that is declared in the base class using
the keyword virtual and is re-defined (Overridden) in the derived class. It tells
the compiler to perform late binding where the compiler matches the object with
the right called function and executes it during the runtime. This technique falls
under Runtime Polymorphism.
Real-World Analogy:
Think of an abstract class like a blueprint for a vehicle. You can't drive a generic
"vehicle" (abstract class), but you can drive a Car or Bike (derived classes), each of
which has its own way of "driving" (implementation of the drive() method).
In OOP, static means a property or method that belongs to the class itself, not to any specific
object.
When a variable in a class is declared static, space for it is allocated for the lifetime of the
program. No matter how many objects of that class have been created, there is only one copy
of the static member. So same static member can be accessed by all the objects of that class.
A static member function can be called even if no objects of the class exist and the static
function are accessed using only the class name and the scope resolution operator ::
Key Points:
Static Variable: Shared by all objects of a class, meaning every object can access and
modify the same static variable.
Static Method: Can be called without creating an object of the class and can only
access static variables or other static methods.
In Object-Oriented Programming (OOP), the this pointer is a special pointer that refers to
the current object in a class method.
Key Points:
Shallow Copy:
Deep Copy:
Shallow Copy:
A shallow copy copies an object’s reference or memory address, meaning both the
original and copied objects share the same data. Changes in one affect the other.
Deep Copy:
A deep copy creates an entirely new object along with its own separate copy of the
data, so changes in the original object don’t affect the copied object.
Call by Value: A copy of the variable is passed to the function. Changes made inside the
function do not affect the original variable.
Call by Reference: The address of the variable is passed to the function. Changes made
inside the function directly affect the original variable.
Operating System:
Mutex (Mutual Exclusion)
A mutex is used to ensure that only one thread can access a critical
section (shared resource) at a time. Once a thread locks a mutex, no other
thread can enter that critical section until the mutex is unlocked.
Real-World Example of Mutex:
Imagine a bathroom in a house. Only one person can use the bathroom
at a time (to avoid conflict). When someone enters the bathroom, they
lock the door (mutex lock). No one else can enter (access the resource)
until they unlock the door (mutex unlock) and leave.
Lock: A person goes in and locks the door (thread enters critical
section).
Unlock: The person finishes and unlocks the door (thread leaves
critical section).
Other People: Have to wait until the door is unlocked to use the
bathroom (other threads wait for access).
Semaphore
A semaphore is similar to a mutex, but it allows multiple threads to
access the same resource simultaneously, up to a certain limit (defined by
a counter). The counter decreases when a thread accesses the resource,
and increases when the resource is released.
Real-World Example of Semaphore:
Imagine a parking lot with 5 parking spaces. If all spaces are full, cars
have to wait until a space is free.
Counter = 5: The number of available parking spaces (semaphore
value).
Car Enters: One car parks, and the counter decreases by 1 (thread
accesses resource).
Car Leaves: A car exits the lot, and the counter increases by 1
(thread releases resource).
Cars Wait: If no parking spaces are available (counter = 0), other
cars wait until a space is free (threads are blocked until they can
access the resource).
In summary:
Mutex: Only one thread can access the resource at a time (like
locking a bathroom).
Semaphore: Allows multiple threads to access the resource, but
limits the number (like a parking lot with limited spaces).
Round-Robin Scheduling is a CPU scheduling algorithm used in
operating systems to manage multiple processes.
How It Works:
Processes are placed in a circular queue.
Each process gets an equal time slice (called a "time quantum") to
execute.
If a process doesn’t finish in its time slice, it goes to the end of the
queue, and the next process gets its turn.
This cycle repeats, giving each process a fair chance to run.
Why It’s Useful:
Ensures all processes get equal CPU time, preventing any process
from monopolizing the CPU.
Ideal for time-sharing systems where response time is crucial.
Real-World Analogy:
Think of it like people standing in a circle taking turns to speak;
everyone gets an equal opportunity without anyone being skipped
for long.
A hardware solution for handling the critical region (critical section) in
an operating system is the use of "Interrupt Disabling" and "Test-and-
Set" instructions.
Examples:
1. Interrupt Disabling:
o Disables interrupts while a process is in its critical section.
o Ensures no other process can interrupt and enter the critical
section.
o Simple but not ideal for multiprocessor systems.
2. Test-and-Set Instruction:
o A special hardware instruction that tests and sets a flag
(lock) in one atomic operation.
o If the flag is not set, the process can enter the critical section.
o It prevents race conditions and ensures mutual exclusion.
These solutions ensure that only one process accesses the critical region
at a time, using hardware-level mechanisms.
Peterson's Solution (in Simple Terms)
**Peterson's Solution** is a way to solve the **critical section problem** in
multithreading, ensuring that only one thread enters the critical section at
a time, preventing data corruption. It works for two threads.
Key Concepts:
- **Critical Section**: A part of the program where shared resources are
accessed.
- **Mutual Exclusion**: Ensuring that only one thread is in the critical
section at any given time.
How It Works:
Peterson’s solution uses two variables:
1. **`flag[]`**: An array where each thread signals its intent to enter the
critical section.
- `flag[0]` for Thread 0, `flag[1]` for Thread 1.
2. **`turn`**: Indicates whose turn it is to enter the critical section.
### Steps:
1. **Thread 0** sets `flag[0] = true` and gives turn to Thread 1 by setting
`turn = 1`.
2. **Thread 1** sets `flag[1] = true` and gives turn to Thread 0 by setting
`turn = 0`.
3. A thread enters the critical section only if:
- The other thread doesn’t want to enter (`flag[other] == false`) **or**
- It’s the current thread’s turn.
Computer Networks:
In Computer Networks (CN), a switch is used to connect multiple devices
(like computers, printers, etc.) within the same network, typically in a
Local Area Network (LAN).
Where it's used:
Inside offices, homes, or data centers to create a network for
communication between devices.
Why it's used:
1. Efficient data transfer: A switch directs data only to the specific
device it's meant for, not to every device in the network (unlike
hubs).
2. Improved performance: It reduces network congestion by sending
data to the correct destination.
3. Security: Switches can be configured with VLANs (Virtual LANs) to
segment networks, enhancing security.
4. A switch operates primarily at the Data Link layer (Layer 2) of
the OSI model
5. Layer 2 (Data Link Layer): Basic switches forward data based on MAC addresses.
6. Layer 3 (Network Layer): Layer 3 switches can route data between different
networks using IP addresses.
Summary:
For example, if you have a network using one protocol (like IP) and want
to send data to a network using a different protocol (like IPX), a gateway
handles the translation between these networks.
Router: Routes data between similar networks (both using IP).
So, routers are a type of gateway, but not all gateways are routers.
Switch:
Router:
Ping:
At work, I used ping google.com to see if my internet was working. If I got
a response, it meant my connection to Google was fine. If not, I knew
there was a network issue.
Subnet:
Imagine a company with multiple departments: Sales, HR, and IT. To
manage their network efficiently:
1. Main Network: The company has a large IP address range, say
192.168.1.0/24.
2. Subnets:
o Sales: 192.168.1.0/26 (IP range: 192.168.1.1 to 192.168.1.62)
o HR: 192.168.1.64/26 (IP range: 192.168.1.65 to
192.168.1.126)
o IT: 192.168.1.128/26 (IP range: 192.168.1.129 to
192.168.1.190)
Each department has its own subnet, which:
Reduces Broadcast Traffic: Each department's devices only hear
broadcasts relevant to their subnet.
Enhances Security: Limits access between departments; for
example, the Sales subnet can’t directly access the IT subnet
without specific routing rules.
Improves Network Management: Easier to manage and
troubleshoot issues within smaller subnets.
So, subnetting helps keep the company’s network organized and efficient,
just like dividing a large office building into smaller, manageable rooms.
1. Unicasting (One-to-One Communication)
Unicasting is when data is sent from one sender to one specific
receiver. It’s the most common form of communication in networks, like
sending an email to a specific person.
Use Case:
Video Call: When you are having a video call with a friend, the data
(video and audio) is sent directly from your device to your friend's
device, making it a unicast.
PowerShell Scripting:
Definition: PowerShell is a command-line shell and scripting
language developed by Microsoft. It's used to automate tasks and
manage systems in Windows, but it also works on Linux and macOS.
Why use PowerShell?
Automation: Helps automate repetitive tasks (like creating users,
managing files, or installing software).
System Management: Used to control and configure systems,
networks, and software easily.
Scripting: PowerShell scripts are a series of commands saved in a
file (with .ps1 extension), which can be executed to perform
complex tasks automatically.