Posts

Showing posts from February, 2024

week4.1 DOM

// eg: adding two number by taking user input. **   <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Document</title> </head>   <body>     <script>         function populateDiv() {         const a = document.getElementById("firstNumber").value;         const b = document.getElementById("secondNumber").value;         const element = document.getElementById("finalSum")         element.innerHTML = parseInt(a) + parseInt(b);                  }     </script>     <input id="firstNumbe...

week3.3 jwt and auth recape

const express = require ( "express" ); const mongoose = require ( "mongoose" ); const app = express (); app. use ( express . json ()) // const { string } = require("zod"); mongoose. connect ( "mongodb+srv://luciferdk:noNQzfSoBo6C56GH@cluster2.c277dmn.mongodb.net/bobo" ); const User = mongoose. model ( 'Users' , { name : String , email : String , password : String }); app. post ( "/signup" , async function ( req , res ) {     const username = req .body.username;     const password = req .body.password;     const name = req .body.name;     const existingUser = await User. findOne ({email:username});     if (existingUser) {         return res . status ( 400 ). send ( "Username Already exists" );     }     const user = new User ({         name: name,         email: username,         password: password }); user. save ()...

2D array

Image
    // This is called 2metrix in programing world //calculating memory consumption rule is:- (rows*columns)*datatypesize = total memory consumption;       _       _ eg: | 2     6 |        | 5      5 |   =>  (rows*columns)*datatypesize  => (2*2)*4 => 16 bytes is memory consumption       -        -    1 D array deceleration is :- int[] number = new int[size]; 2 D array  deceleration is :- int[][] number = new int[rows][columns];    eg: //Example of 2darray and calculating sum  int a[][], i, j,sum=0; printf("Enetr element of matrix:  :");   for(i=0;i<2;i++){ for(j=0; j<3;j++){ sacnf("%d", &a[i][j]); } }   printf("Martix is\n"); for(i=0;i<2;i++){ for(j=0; j<3;j++){ printf("%d\t",  a[i][j]); sum = sum + a[i][j]; } printf("\n"); }  printf("\n Sum = ...

Time and Space Complexity.

TIME COMPLEXITY Definition:-  Relation between input Size & Running time(Operations) time complexity is directly proportional to   the input size . Time complexity has three cases BEST CASE Ω(1) AVERAGE CASE Ө(n+1/2) WORST CASE O(n) time complexity is represented by (n) // In the nested loop time complexity is calculated by n*n; eg-2,3; //In a nonnested loop time complexity is calculated by n+n; eg-4;

week3.2 fetch, authentication and database

//time stamp16:48 creating fetch API code* <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Document</title> </head> <body>     <script>         function getAnimalData() {             fetch("https://fakerapi.it/api/v1/persons")         .then(function (response) {                 response.json()                     .then(function (finalData) {                         console.log(finalData);                     })             })             }     </scr...

week 3.1 express and authentication

//To Check kidney input* Time Stamp 24:23 Ugly way to write code const express = require("express"); const app = express(); app.get("/health-checkup", function (req, res) {   const username = req.headers.username;   const password = req.headers.password;   const kidneyId = req.query.kidneyId;   if (username != "harkirat" || password != "pass") {     res.status(400).json({ msg: "somthing is up" });     return;   }   if (kidneyId != 1 && kidneyId != 2) {     res.status(400).json({ msg: "somthing yup" });     return;   }   res.json({ msg: "uou kidney is fine" }); }); app.listen(3000);

git & gitHUB

Git & GitHub Things 1.   git init //to initialize the git in the folder 2. git remote add origin https://github.com/luciferdk/01JS.git   ||   git clone  https://github.com/luciferdk/01JS.git   //to initialize the github in the local folder   git pull origin master //to verify your project is righ to setup if you remotely add Origin   git merge master //if you remote add the origin 3.    git add -A || git add .   // to add the file in stazing area 4.  git commit -m "meaningfull-message" //now your code is in statizing area. 5.   git push |  git push -u || git push origin master  / /to push all the git code in your GitHub 6.  git -rm --cached .   //to unstated all commit  dot. is repesent all file will unstaged          git push origin HEAD:main   //after changing  branch name you might need this code to push repo ===============================...

Map, Filter, Arrows-fn's || weak2.6

 // map, filter, arrowss fns. /*  ---------------------> Syntax // normal function syntax //  In js function sum(a, b) {     return a+b;     } // In express app.get("/", function (req, res) { }) // arrow function syntax // In js const sum = (a, b) => {         return a + b;     } // In express app.get("/", (req, res) => {      })     const ans = sum (1,2);     console.log(ans);      <-------------------------*/ /* ---------------------> Porblem Statement1.         // given an array, me back a new array in which every value multiplied by 2  // [1,2,3,4,5]  // [2,4,6,8,10] //  Ugnly Way To Write Code  const input = [1,2,3,4,5];      // solution      const newArray =[];      for (let i = 0; i < input.length; i++) {          newArray.push(inp...

Express with examples week2.5

HTTP is a Protocall you can write in any language.  Express is one of them.  //without express function calculateSum(n) { let ans = 0; for(let i = 1; i<n;  i++){ ans = ans + i; } return ans; } let ans = calculateSum(10) console.log(ans);  //with express cont exptess ("express") function calculateSum(n) { let ans = 0; for(let i = 1; i<n;  i++){ ans = ans + i; } return ans; } const app = express(); app.get("/", function(req,res){ const n= req.quer.n; cosnt ans = calculateSum(n) res.send(ans); }) app.listen(3000); let ans = calculateSum(10) console.log(ans); // // Creatin http server to calculate the sum of natural number // node dufult labirary const express = require("express"); const app = express(); function sum(n) {     let ans = 0;     for (let i = 1; i <= n; i++) {         ans = ans + i;     }     return ans; } app.get("/", function (req, res) {     const n = req.query.n;   ...