Posts

Showing posts from January, 2024

Common Things

 bash video 1. pwd  //present directory 2. cd  // to change directory 3. ls   // to see the directory and files 4.mkdir //to create directory 5. touch // to create file 6. cat 7. vi 8. mv  hello.cpp  ../Dev   // move file   source and destination 8. mv  hello.cpp rename.cpp  // to rename the file  [{old name} {new name}] 9. cp '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Relative Units EM : Relative to the parent element REM : Relative to the root element (HTML tag) % : Relative to the parent element VW : Relative to the viewport’s width ...

week2.2/express

The thing the exposes the machine  leraning  code in server   // for local machine the code   import cors from "cors"; import express, { Request, Response } from 'express'   const express = require ('express')   const Port: number = 3000 ; const app = express();     app.use(cors()); app.use(express.json())   app.get ('/', (req, res) => {   res.send ('Hello World!')   }   app.listen (port, () => {   console.log(` Example  app listening on port ${port}')   })  

function and callbacks, class, object(oops)

 functions Q: what is a function? Ans:  A function in a JavaScript is a set of statement that performs a task or calculate a value It should take some input and return an output where there is some obvious relationship between the input and the output. Function Syntax: function findSum(n) { let ans = 0; for (let i = 0; i<n; i++) { ans = ans +i } return ans; } let ans = findSum(100) console.log(ans); Example function sum (a,b){ return  a+ b; } 1 Without using Function. let n = 100; let ans = 0; for (let i=1; i<n; i++) { ans = ans + i } console.log(ans); -------------- let n2 = 1000; let ans2 = 0; for (let i=1; i<n; i++) { ans2 = ans2 + i } console.log(ans2); 2 With Function type  function findSum(n) { let ans = 0; for (let i = 0; i<n; i++) { ans = ans +i } return ans; } let ans = findSum(100) console.log(ans); let ans = findSum(1000) console.log(ans); Callback Functions you can call one function inside another function? Example Without callback function co...

promise and await

Promise Q: what is Promises? Ans:- Promises are syntactical sugar that make this code slightly more readable. 1) Example of Promises Code:- const fs = require('fs'); // my own asynchronous function function kiratsReadFile() { return new Promise(function(resolve) { fs.readFile("a.txt", "utf-8", function(err, data) { resolve(data); }); })  } // callback function to call function onDone(data) { console.log(data)  } kiratsReadFile().then(onDone); Here's a line-by-line explanation of the code: 1.  const fs = require('fs'); Imports the built-in  fs   (file system) module, providing functions for interacting with files. 2.  unction kiratsReadFile() {.....} Defines a function named  kiratsReadFile  that handles asynchronous file reading. 3.  return new Promise(function(resolve) {. . . }); Returns a new Promise object, enabling cleaner handling of the asynchronous operation. 4.  fs.readFile("a.txt", "utf-8", function(err...