Tuesday, 3 October 2023

How to install Azure Service Fabric in local machine.

In this Post, I will guide you how to install Azure Service Fabric in your local Machine.

First download Service Fabric run time from below link.

Then download Service fabric SDK from below link.

Now Install each above downloaded file as below.

1. Service Fabric Runtime
     Open  CMD in administrative mode and paste the command as below

     C:\Users\sony\Downloads>MicrosoftServiceFabric.9.1.1583.9590.exe /accepteula




2. Service Fabric SDK

Click on Service Fabric SDK msi package and Install it.

Once Installed, go to
C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup folder and open DevClusterSetup.ps1 file in Power Shell(Open PS in admin mode) and execute this file. 

Or paste below code in Power Shell 

& "$ENV:ProgramFiles\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1"

Once DevClusterSetup.ps1 file execute successfully, it will create service fabric cluster in your local machine.

Service Fabric Cluster:-


Saturday, 23 September 2023

What is the difference between round and ceiling in SQL Server?

In SQL Server, both the ROUND and CEILING functions are used to perform mathematical rounding of numerical values, but they have different behaviors:

  1. ROUND:

    • The ROUND function is used to round a numeric value to a specified number of decimal places.
    • It performs "normal" rounding, which means that if the decimal part is equal to or greater than 0.5, it rounds up; otherwise, it rounds down.
    • It can be used with both positive and negative numbers.
    • The ROUND function takes two arguments: the numeric value to be rounded and the number of decimal places to round to.

    Example:


    SELECT ROUND(3.14159, 2); -- Returns 3.14 
  2. SELECT ROUND(3.6); -- Returns 4 
  3. SELECT ROUND(-3.6); -- Returns -4
  4. CEILING:

    • The CEILING function is used to round a numeric value up to the nearest integer that is greater than or equal to the original value.
    • It always rounds up, regardless of the decimal part of the number.
    • It is commonly used when you want to ensure that a value is rounded up to the nearest whole number, even if the decimal part is very small.
    • The CEILING function takes a single argument, which is the numeric value to be rounded up.

    Example:

    SELECT CEILING(3.14159); -- Returns 4 SELECT CEILING(3.6); -- Returns 4 SELECT CEILING(-3.6); -- Returns -3

In summary, the key difference between ROUND and CEILING in SQL Server is in how they handle rounding. ROUND performs standard rounding based on the decimal part of the number, while CEILING always rounds up to the next integer, regardless of the decimal part. Your choice between them depends on the specific rounding behavior you need for your calculations.

How to implement Azure Application Insight in Web app?

Azure Application Insights is a powerful service for monitoring and gaining insights into the performance and usage of your web applications. To implement Application Insights in a web app, follow these steps:

Step 1: Create an Application Insights resource

Log in to the Azure portal (https://portal.azure.com).

Click on "+ Create a resource" on the left-hand menu.

Search for "Application Insights" in the Azure Marketplace.

Select "Application Insights" from the search results.

Click the "Create" button to create a new Application Insights resource.

Fill in the required details like Subscription, Resource Group, Region, and give it a name. You can also configure the pricing tier based on your needs. Click "Review + create" and then "Create" to provision the resource.

Step 2: Instrument your Web App

Now that you have an Application Insights resource, you need to instrument your web app to send telemetry data to it. This involves adding the Application Insights SDK to your application code. The exact steps may vary depending on the technology stack of your web app.

Below are some common scenarios:

ASP.NET Core Application (C#):

Open your ASP.NET Core project in Visual Studio.

Install the Microsoft.ApplicationInsights.AspNetCore NuGet package if not already installed:


Install-Package Microsoft.ApplicationInsights.AspNetCore

In the Startup.cs file, add the following code in the ConfigureServices method to configure Application Insights:


services.AddApplicationInsightsTelemetry(Configuration["ApplicationInsights:InstrumentationKey"]);
In the appsettings.json file, add your Application Insights Instrumentation Key:


"ApplicationInsights": {
  "InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
}

Node.js Application:

Install the applicationinsights npm package:


npm install applicationinsights --save

In your Node.js code, require and configure Application Insights using your Instrumentation Key:


const appInsights = require("applicationinsights");
appInsights.setup("YOUR_INSTRUMENTATION_KEY").start();

Other Platforms: Application Insights has SDKs and integrations for various platforms. You can find specific instructions for your technology stack in the official documentation.

Step 3: Verify Integration

After instrumenting your web app, you can verify if telemetry data is being sent to Application Insights:

Run your web app.

In the Azure portal, navigate to your Application Insights resource.

Go to the "Overview" or "Logs" section to see telemetry data, including requests, exceptions, and performance metrics.

Step 4: Analyze and Monitor

With Application Insights set up, you can use it to:

  • Monitor application performance and detect issues.
  • Create custom dashboards and alerts.
  • Analyze user behavior and track conversions.
  • Debug and diagnose problems using distributed tracing.
Application Insights is a powerful tool for gaining insights into your web app's behaviour and performance, helping you improve its reliability and user experience.

Whay is difference between Azure Service Fabric and Azure Function App.

Azure Service Fabric and Azure Function App are both Azure services that can be used for building and deploying applications, but they serve different purposes and have distinct characteristics. Here's a comparison of Azure Service Fabric and Azure Function App: Azure Service Fabric: Service Type: Service Fabric is a platform for building and managing microservices-based applications. It allows you to create and manage services that can be stateful or stateless and supports complex, multi-service applications. Programming Model: You have more control over the code and architecture of your services in Service Fabric. You can choose to use various programming languages (e.g., C#, Java, etc.) and frameworks (e.g., ASP.NET Core, Java Spring Boot) to develop your services. Service Types: Service Fabric supports stateful and stateless services, allowing you to build applications with persistent data and complex service orchestration. Scaling: It provides more granular control over scaling and load balancing. You can manually scale or use auto-scaling rules. Application Types: Service Fabric is suitable for building a wide range of applications, including microservices, containers, and legacy applications. Deployment: You have more control over how services are deployed and upgraded, including version management and rolling upgrades. Use Cases: It's ideal for complex, large-scale applications, especially those requiring high availability, stateful services, and complex service orchestration. Azure Function App: Service Type: Azure Functions is a serverless compute service that allows you to execute code in response to events without managing the underlying infrastructure. Programming Model: Azure Functions use a serverless programming model, where you write individual functions that are triggered by events (e.g., HTTP requests, timers, message queues). You don't need to worry about infrastructure management. Service Types: Azure Functions are typically stateless and designed to execute small units of code in a stateless manner. Scaling: Scaling is handled automatically by Azure Functions based on the number of incoming events or requests. You're billed only for the actual compute resources used during execution. Application Types: Azure Functions are well-suited for event-driven, small-to-medium-sized workloads where you want to focus on code and not worry about infrastructure management. Deployment: You deploy individual functions or sets of functions. Each function can have its own dependencies. Use Cases: Azure Functions are great for event-driven scenarios, such as processing messages from queues, handling HTTP requests, or responding to changes in data. In summary, the choice between Azure Service Fabric and Azure Function App depends on your specific application requirements: Choose Azure Service Fabric if you need fine-grained control over service architecture, stateful services, complex service orchestration, and you're building larger, complex applications. Choose Azure Function App if you want a serverless, event-driven architecture that automatically scales and you're building smaller, more focused functions that respond to events and triggers. Often, both services can be used together within a larger Azure solution to handle different parts of your application's functionality.

Saturday, 20 August 2022

ReactJs Interview Questions Part -3

21.    What are forward refs?

Ref forwarding is a feature that lets some components take a ref they receive, and pass it further down to a child.

const ButtonElement = React.forwardRef((props, ref) => (
  <button ref={ref} className="CustomButton">
    {props.children}
  </button>
));
 
// Create ref to the DOM button:
const ref = React.createRef();
<ButtonElement ref={ref}>{'Forward Ref'}</ButtonElement>

22.   Which is preferred option with in callback refs and findDOMNode()?

It is preferred to use callback refs over findDOMNode() API. Because findDOMNode() prevents certain improvements in React in the future.

The legacy approach of using findDOMNode:

class MyComponent extends Component {
  componentDidMount() {
    findDOMNode(this).scrollIntoView()
  }
 
  render() {
    return <div />
  }
}

The recommended approach is:

class MyComponent extends Component {
  constructor(props){
    super(props);
    this.node = createRef();
  }
  componentDidMount() {
    this.node.current.scrollIntoView();
  }
 
  render() {
    return <div ref={this.node} />
  }
}

23. Why are String Refs legacy?

If you worked with React before, you might be familiar with an older API where the ref attribute is a string, like ref={'textInput'}, and the DOM node is accessed as this.refs.textInput. We advise against it because string refs have below issues, and are considered legacy. String refs were removed in React v16.

                                 i.            They force React to keep track of currently executing component. This is problematic because it makes react module stateful, and thus causes weird errors when react module is duplicated in the bundle.

                               ii.            They are not composable — if a library puts a ref on the passed child, the user can't put another ref on it. Callback refs are perfectly composable.

                             iii.            They don't work with static analysis like Flow. Flow can't guess the magic that framework does to make the string ref appear on this.refs, as well as its type (which could be different). Callback refs are friendlier to static analysis.

                             iv.            It doesn't work as most people would expect with the "render callback" pattern (e.g. )

            v.     class MyComponent extends Component {
           vi.       renderRow = (index) => {
         vii.         // This won't work. Ref will get attached to DataTable rather than MyComponent:
        viii.         return <input ref={'input-' + index} />;
           ix.      
            x.         // This would work though! Callback refs are awesome.
           xi.         return <input ref={input => this['input-' + index] = input} />;
         xii.       }
        xiii.      
         xiv.       render() {
           xv.         return <DataTable data={this.props.data} renderRow={this.renderRow} />
         xvi.       }
}

24.  What is Virtual DOM?

The Virtual DOM (VDOM) is an in-memory representation of Real DOM. The representation of a UI is kept in memory and synced with the "real" DOM. It's a step that happens between the render function being called and the displaying of elements on the screen. This entire process is called reconciliation.

25.  How Virtual DOM works?

The Virtual DOM works in three simple steps.

                                i.            Whenever any underlying data changes, the entire UI is re-rendered in Virtual DOM representation.



                              ii.            Then the difference between the previous DOM representation and the new one is calculated.



                            iii.            Once the calculations are done, the real DOM will be updated with only the things that have actually changed.



26. What is the difference between Shadow DOM and Virtual DOM?

The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The Virtual DOM is a concept implemented by libraries in JavaScript on top of browser APIs.

27.    What is React Fiber?

Fiber is the new reconciliation engine or reimplementation of core algorithm in React v16. The goal of React Fiber is to increase its suitability for areas like animation, layout, gestures, ability to pause, abort, or reuse work and assign priority to different types of updates; and new concurrency primitives.

28.   What is the main goal of React Fiber?

The goal of React Fiber is to increase its suitability for areas like animation, layout, and gestures. Its headline feature is incremental rendering: the ability to split rendering work into chunks and spread it out over multiple frames.

from documentation

Its main goals are:

                                 i.            Ability to split interruptible work in chunks.

                               ii.            Ability to prioritize, rebase and reuse work in progress.

                             iii.            Ability to yield back and forth between parents and children to support layout in React.

                             iv.            Ability to return multiple elements from render().

                               v.            Better support for error boundaries.

29. What are controlled components?

A component that controls the input elements within the forms on subsequent user input is called Controlled Component, i.e, every state mutation will have an associated handler function.

For example, to write all the names in uppercase letters, we use handleChange as below,

handleChange(event) {
  this.setState({value: event.target.value.toUpperCase()})
}

30.  What are uncontrolled components?

The Uncontrolled Components are the ones that store their own state internally, and you query the DOM using a ref to find its current value when you need it. This is a bit more like traditional HTML.

In the below UserProfile component, the name input is accessed using ref.

class UserProfile extends React.Component {
  constructor(props) {
    super(props)
    this.handleSubmit = this.handleSubmit.bind(this)
    this.input = React.createRef()
  }
 
  handleSubmit(event) {
    alert('A name was submitted: ' + this.input.current.value)
    event.preventDefault()
  }
 
  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          {'Name:'}
          <input type="text" ref={this.input} />
        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}

In most cases, it's recommend to use controlled components to implement forms. In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by the DOM itself.