alias gitdir="cd ~/Git/" (This means gitdir switches to the ~/Git/ directory, but I wanted it to switch directly to a repository.) So, I wrote a Bash function.
Write Code to .bashrc File
The .bashrc file runs when a new terminal window is opened. So, we need to write the function inside this file.
Code
gitrepo() {
# Exact Match
repoList=$(ls $HOME/Git)
if [ -n "$(echo "$repoList" | grep -w $1)" ]; then
cd $HOME/Git/$1
else
# Relevant Match
getRepoName=$(echo "$repoList" | grep -i -m 1 $1)
if [ -n "$getRepoName" ]; then
cd "$HOME/Git/$getRepoName"
else
echo "Repository Not Founded"
cd $HOME/Git
fi
fi
}
Code Explanation
The $repoList variable stores the list of directories inside the Git folder.
Function Logic Has Two Parts:
Exact Match
Relevant Match
Exact Match
if [ -n "$(echo "$repoList" | grep -w $1)" ]; then
cd $HOME/Git/$1
If condition: The $repoList variable parses input for grep.
grep -w matches only whole words.
$1 is the functionβs argument in bash.
-n checks if a variable is not empty. Example syntax: [ a != "" ] is equivalent to [ -n a ]
Relevant Match
getRepoName=$(echo "$repoList" | grep -i -m 1 $1)
if [ -n "$getRepoName" ]; then
cd "$HOME/Git/$getRepoName"
Relevant search: If no Exact Match is found, this logic is executed next.
getRepoName="$repoList" | grep -i -m 1 $1
-i ignores case sensitivity.
-m 1 returns only the first match.
Example of -m with grep: ls | grep i3 It returns i3WM and i3status, but -m 1 ensures only i3WM is selected.
No Match
If no match is found, it simply changes the directory to the Git folder.
type casting int : <class 'int'>
type casting float : <class 'float'>
type casting string : <class 'str'>
type casting boolean : <class 'bool'>
type casting list : <class 'list'>
type casting set : <class 'set'>
type casting tuple : <class 'tuple'>
Delete Variable
Delete an existing variable using Pythonβs del keyword.
temp = 1
print("temp variable is : ",temp)
del temp
# print(temp) => throw NameError : temp not defined
Output
temp variable is : 1
Find Variable Memory Address
Use the id() function to find the memory address of a variable.
temp = "hi"
print("address of temp variable : ",id(temp))
Output
address of temp variable : 140710894284672
Constants
Python does not have a direct keyword for constants, but namedtuple can be used to create constants.
from collections import namedtuple
const = namedtuple("const",["PI"])
math = const(3.14)
print("namedtuple PI = ",math.PI)
print("namedtuple type =",type(math))
Output
namedtuple PI = 3.14
namedtuple type = <class '__main__.const'>
Global Keyword
Before understanding global keyword, understand function-scoped variables.
Function inside variable are stored in stack memory.
A function cannot modify an outside (global) variable directly, but it can access it.
To create a reference to a global variable inside a function, use the global keyword.
A REST API (Representational State Transfer) is a web service that allows different applications to communicate over the internet using standard HTTP methods like GET, POST, PUT, and DELETE. It follows REST principles, making it lightweight, scalable, and easy to use.
REST API Principles
Client-Server Architecture
A REST API follows a client-server architecture, where the client and server are separate. The client sends requests, and the server processes them and responds, allowing different clients like web and mobile apps to communicate with the same backend.
Statelessness
Before understanding statelessness, you need to understand statefulness.
Statefulness: The server stores and manages user session data, such as authentication details and recent activities.
Statelessness: The server does not store any information. Each request is independent, and the client must include all necessary data, like authentication details and query parameters, in every request.
This behavior makes the server scalable, reliable, and reduces server load.
Caching
Caching improves performance by storing responses that can be reused, reducing the need for repeated requests to the server. This minimizes response time and server load.
Uniform Interface
A uniform interface ensures consistency by using standard HTTP methods like GET, POST, PUT, and DELETE. This makes the API predictable and easy to use.
Layered System
A layered system divides tasks into separate layers, like security, caching, and user requests. The client only interacts with the top layer, making the system easier to manage and more flexible.
Start To Code
I use Node.js and some popular packages:
Express: A Node.js web framework used for building web applications and APIs.
Joi: A package used to validate user input, ensuring data integrity and security.
basic code
const express = require("express");
const app = express();
const joi = require("joi");
app.use(express.json());
//data
customers = [
{name : "user1", id : 1},
{name : "user2", id : 2},
{name : "user3", id : 3}
]
//listen
const port = process.env.PORT || 8080;
app.listen(port, ()=> console.log("listening on ",port));
//function
function validateUserName(customer){
schema = joi.object({
name : joi.string().min(3).required()
});
return schema.validate(customer)
}
GET
GET is used to retrieve data from the server. the response code is 200 if successful.
app.delete('/api/customer/:id', (req,res)=>{
const user = customers.find(user => user.id == req.params.id);
index = customers.indexOf(user);
if(!user){
console.log("test")
res.status(404).send("Data Not Found");
}
else{
customers.splice(index,1);
res.status(200).send("successfully deleted");
}
});
What I Learned
CRUD Operations with REST API
I learned the basics of REST API and CRUD operations, including the uniform methods GET, POST, PUT, PATCH, and DELETE.
Status Codes
REST APIs strictly follow status codes:
200 β OK
201 β Created successfully
400 β Bad request
204 β No content
404 β Page not found
Joi Package
For server-side validation, the Joi package is used. It helps verify user data easily.
Middleware
Using app.use(express.json()) as middleware ensures that for POST, PATCH, and PUT methods, JSON-formatted user data is parsed into an object accessible via req.body.
This is a Python-based single-file application designed for typing practice. It provides a simple interface to improve typing accuracy and speed. Over time, this minimal program has gradually increased my typing skill.
What I Learned from This Project
2D Array Validation I first simply used a 1D array to store user input, but I noticed some issues. After implementing a 2D array, I understood why the 2D array was more appropriate for handling user inputs.
Tkinter I wanted to visually see and update correct, wrong, and incomplete typing inputs, but I didnβt know how to implement it in the terminal. So, I used a simple Tkinter gui window
Run This Program
It depends on the following applications:
Python 3
python3-tk
Installation Command on Debian-Based Systems
sudo apt install python3 python3-tk
Clone repository and run program
git clone https://github.com/github-CS-krishna/TerminalTyping cd TerminalTyping python3 terminalType.py
I created a website called Vinmeen that allows users to rent products for temporary needs at a low cost. The goal was to design a simple UI for users to easily rent things they need temporarily.
Technologies Used
Node.js & Express
Node Packages
Express
EJS
Nodemailer
Bcrypt
Multer
Sync-SQL
MySQL
MySQL
What I Learned from This Project
This project helped me understand how dynamic websites work and how template rendering is done. I used EJS for rendering templates, MySQL for database handling, and Bcrypt for securely storing user passwords through hashing. I also learned how to send email notifications with OTP and rent requests, among other things.
Files.io offers a free MySQL database with a 10MB size limit and a maximum of 5 concurrent connections. Itβs ideal for students and self-study projects, but not recommended for startups or businesses.