Thursday, November 2, 2023

Backend API interview Question

1) How to improve performance?

2) PATCH  (Partial Update):PUT (Replace or Full Update):

3) Do you know what is Database Indexes ? Database Primary Index have only one / Secondary Index 

4) Concept of middleware in Express.js

    execute code during the request-response cycle. Middleware functions have access to the request object (req), the response object (res), and the next function in the application's request-response cycle. They can perform tasks, modify the request or response objects, and either terminate the cycle or pass control to the next middleware function by invoking the next function. Middleware functions in Express.js can be used for various purposes, such as logging, authentication, handling errors, modifying the request or response, and more.

5) What is the purpose of the async and await keywords in Node.js?

  • Answer: async and await are used to work with Promises in a more synchronous style. The async keyword is used to declare an asynchronous function, and await is used inside an async function to pause execution until the Promise is resolved.

Tuesday, October 31, 2023

React Interview Questions

 What is state in React, and how is it different from props? 

  • State is an object that belongs to a React component and can be used to store and manage data that can change over time. It is mutable and can be changed by the component itself. In contrast,  
  • props are read-only and passed from a parent component to a child component. 

What are React Hooks, and how do they work? 
  • React Hooks are functions that allow functional components to manage state and side effects.
  •  The most common hooks are useState, useEffect, and useContext
  • Hooks enable functional components to have state and lifecycle features that were previously exclusive to class components. 
  • Example const [count, setCount] = useState(0); 
  • useEffect hook can be used in two primary ways: with a dependency array (an array of values) and without a dependency array. 
    • with a dependency array, the effect will run under specific conditions
    • without a dependency array - runs on every render. 

When Use Redux and Context ? 
    Use Redux when: You're working on a large and complex application with extensive state management needs, or when you need to handle complex asynchronous actions, middleware, and a single source of truth. Redux's predictability and mature ecosystem make it a good choice for such scenarios. 

    Use React Context when: You have simpler state management needs, such as sharing data between parent and deeply nested child components. React Context is great for avoiding prop drilling and keeping your component tree clean. 

     

    Friday, August 4, 2023

    SQL Server Express and Port

    set SQL Express with another port, e.g. here 1066
    then you can connect it with localhost, 1066



    Tuesday, April 11, 2023

    Fetching API in parallel

      const [memberResults, cartItemResult] = await Promise.all([

    makeAPIRequest("get", `members/${currentUser.uid}`),
    makeAPIRequest("get", `memberCart/get/cart/items/${currentUser.uid}`),
    ]);

    Thursday, February 23, 2023

    How Access Between Angular

    • From Parent to access child component
      • @ViewChild()
    • Pass Data between child and parent component
      • @Input() 
        • data from parent to child
        • @Input() item = ''; // decorate the property with @Input()
        • Directive From Parent Component
        • <app-item-detail [item]="currentItem"></app-item-detail>
      • @Output()
        • data from child to parent with the help of the event.
        • to raise event must have EventEmitter

    Angular Question

    • Type of Data Binding
      • One Way Binding
        • Interpolation Bnding
          • data move in one direction from components (typescript) to HTML
          • <p>{{ message }}</p> 
        • Property Binding
          • set properites to HTML elements.
          • [value]="user.email" or <img [src]="imageUrl"> 
      • Two Way Binding 
        • component and view are always in sync
        • Changes in user interface to model state.
        • Changes in model state reflect to user interface
        • <input [(ngModel)]="name">
    • Event Binding
      • One Way Binding
      • for event trigger
      • <button (click)="doSomething()">Click me</button> 


    • How does one share data between components in Angular? 
      • Parent to child using @Input decorator 

      • Child to parent using @ViewChild decorator 
      • Child to parent using @Output and EventEmitter 
    • Decorators
      • Design Pattern & function
      • modification to a class, service or filter
      • 4 Types
        • Class Decorators
        • Property Decorators
        • Method Decorators
        • Parameter Decorators
    • Advantages
      • MVC architecture
      • Modules
        • componentes
        • directives
        • pipe
        • services
      • Dependency Injection
        • component dependent on other components can easily worked around
      • Others
        • clean and maintainable code
        • reusable components
        • data binding
        • unit testing
    • Directives
      • attributes allow user write new HTML syntax
      • 3 Types
        • Component Directives
        • Structural Directives
        • Attribute Directives

      • myHighlist is Directives
    • Template
      • HTML View
      • seperate template file such **.html
    • Template Statements
      • properties or methods
      • (click)='addUser()"
      • addUser is template
    • Promises and Observables
      • Promises
        • emit single value at a time
        • Execute immediately after creation and not cancellable
        • Push Errors to child Promises
      • Observables
        • execute when subscribe()
        • emit Mutiple value over a period of time
        • perform forEach, filter and retry
        • Deliver errors to subscribers.
        • When unsubsribe() is called, listener stop receive further values.
    • ObservablePromise
      Declarative: Computation does not start until subscription so that they can be run whenever you need the resultExecute immediately on creation
      Provide multiple values over timeProvide only one
      Subscribe method is used for error handling which makes centralized and predictable error handlingPush errors to the child promises
      Provides chaining and subscription to handle complex applicationsUses only .then() clause
    • Difference AngularJS and Angular
    • AngularJSAngular
      It is based on MVC architectureThis is based on Service/Controller
      It uses JavaScript to build the applicationUses TypeScript to build the application
      Based on controllers conceptThis is a component based UI approach
      No support for mobile platformsFully supports mobile platforms
      Difficult to build SEO friendly applicationEase to build SEO friendly

    Sunday, February 19, 2023

    Dependency Injection 2

    What is Dependency Injection

    • Produce a loosely coupled code
    • Any change in the class without affecting other object.
    • Type of DI
      • Constructor Injection
        • parameter to inject dependencies in a class
        • One parameterized constructor but no default constructor and you need to pass specified values to the constructor


      • Setter Injection
        • through properties of a class


      • Interface-based injection
        • through method


    • Advantage
      • Maintainability
        • maintain code structure, single principle
      • Flexibility
        • loosely coupled code, flexible to use different ways.
      • Testability
        • easy to do unit testing
      • Readability
        • Logic in constructor.













    Friday, August 19, 2022

    Back to previous commit

     # Resets index to former commit; replace '56e05fced' with your commit code

    git reset 56e05fced 
    
    # Moves pointer back to previous HEAD
    git reset --soft HEAD@{1}
    
    git commit -m "Revert to 56e05fced"
    
    # Updates working copy to reflect the new commit
    git reset --hard

    Monday, June 20, 2022

    bootstrap footer always bottom

    <div class="d-flex flex-column min-vh-100">
    <footer class="mt-auto earth">
    </footer>
    </div>

    Thursday, June 9, 2022

    Git Change Repo

    both are Same (Set new origin)

    git remote set-url origin https://github.com/123123.git

    git branch -M main

    git push -u origin main

    -----------------


    git remote rm origin

    git remote add origin https://github.com/123123.git

    git branch -M main

    git push -u origin main


    ------------------


    after git push

    git tag v1.0.1

    git checkout v1.0.1


    firebase login:use <email>



    Tuesday, May 31, 2022

    Change Firebase Project

    1.  firebasesrc change to correct firebase project
    2. Enable Firestore (set region asiasoutheast1)
    3. Try to Deploy First (must blaze project)

    firebase login:add
    firebase login:list
    firebase login:use


    change another login and deploy

    Wednesday, May 25, 2022

    Git Replace without MR


     https://www.nickang.com/2017-09-30-replace-git-branch-code/

    Monday, September 20, 2021

    POSTMAN Running

    Running and store the result to Environment



    • Runner to Run CSV file 
    • In the collection, click "Run Button"

    • This how you put the Body mapping to csv file.
    • Careful the ""
    • Import the CSV and run.
    • can be json file too
    x

    Sunday, June 14, 2020

    C# Interview questions

    What is serialization?
    When transport an object through a network, then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization.
    Deserialization is the reverse process of creating an object from a stream of bytes.
    Can we use "this" command within a static method?
    We can't use 'This' in a static method because we can only use static variables/methods in a static method.
    What is the difference between constants and read-only?
    Constant variables are declared and initialized at compile time. The value can't be changed afterward. Read-only is used only when we want to assign the value at run time.
    What are sealed classes ?
    We create sealed classes when we want to restrict the class to be inherited. Sealed modifier used to prevent derivation from a class. If we forcefully specify a sealed class as base class, then a compile-time error occurs.
    What is an object pool in .NET?
    An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.
    Object Pooling allows objects to keep in the memory pool so the objects can be reused without recreating them.
    Use the Factory pattern for this purpose. which will take care of the creation of objects.If there is any object available within the allowed limit, it will return the object, otherwise, a new object will be created and give you back.
    What are delegates in C# and the uses of delegates?
    Is an abstraction of one or more function pointers 
    You can treat a function as data. 
    It allow functions to be passed as parameters.
    Why Do We Need Delegates?
    Callback is to handle button-clicking.
    is a solution for situations in which you want to pass methods around to other methods.
    You do not know at compile time what this second method is. That information is available only at runtime, hence Delegates are the device to overcome such complications.
    What is a Virtual Method in C#?
    A virtual method is a method that can be redefined in derived classes. A virtual method has an implementation in a base class as well as derived the class.
    The overriding method also provides more than one form for a method. Hence, it is also an example of polymorphism.



    Monday, November 26, 2018

    Redis Cache Test in Local Host

    port : 6379
    - In Local, for Redis, need to create a Redis Server to debug:
    -Download server: https://github.com/MicrosoftArchive/redis/releases version 3.2.1
    -Unzip on a directory  (for example C:\Program Files\RedisServer 5.0)
    - cd C:\Program Files\RedisServer 5.0
    - redis-server --service-install redis.windows-service.conf --loglevel verbose    ßinstall service
    - redis-server --service-start  ß start Service
    - redis-cli.exe ßrun client to check keys (get, set, delete)
    -Change in app.config ip for Redis (msHost) with 127.0.0.1

    Tuesday, October 9, 2018

    Windows Form Application Publish OnceClick

    Publish Folder Location : is the path (e.g. C:\Publish\App)
    Installation Folder URL : is IIS (e.g. http:\\localhost\AppInstall)

    E.g. http://localhost/AppInstall/publish.htm

    Assembly Name Product Name can be make it to different application

    Friday, June 29, 2018

    Git & IONIC

    git branch develop
    git checkout develop //use
    git commit -am "change channel"
    git push ionic develop

    git checkout master
    git merge develop
    git commit -am "merge conflict" // checkin local
    git push origin // push to server
    git push ionic master // push to server

    git status

    Friday, June 1, 2018

    Dowload Attachment From Google Mail using IMAP


    //POP is temporary only, so use IMAP better
    //Nuget S22.IMAP

    using (ImapClient client = new ImapClient("imap.gmail.com", 993, "Email", "App Password", AuthMethod.Login, true))
    {
        IEnumerable<uint> uids = client.Search(
             SearchCondition.From("from@mail")
             .And(SearchCondition.SentSince(new DateTime(2018, 05, 01)))
              .And(SearchCondition.SentBefore(new DateTime(2018, 06, 01))), "Mail box Name");

        Console.WriteLine(uids.Count() + " Emails:");

        foreach (var uid in uids)
        {
            MailMessage message = client.GetMessage(uid,mailbox:"Mail box Name");

            Console.WriteLine(message.Subject);

            foreach (Attachment attachment in message.Attachments)
            {
                byte[] allBytes = new byte[attachment.ContentStream.Length];
                int bytesRead = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length);
                string destinationFile = @"C:\\myfile\\" + attachment.Name;
                BinaryWriter writer = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
                writer.Write(allBytes);
                writer.Close();
            }
       }
    }