3 December 2021

Ternary operator example in react js

import React from "react";

function TernaryOperatorEXP2(props) {
    const status=1
  return (
    <div>
      <div>
        <h1>Ternary operator example in react js</h1>
      </div>
      <button> {status === 1 ? "Active" : "DeActive"} </button>
    </div>
  );
}
export default TernaryOperatorEXP2;

 Github link: https://github.com/adi501/react-js-example

substring function in react js

import React from 'react';

function SubstringEXP(props) {
    var str = "Hello world, react js SubString example";
    return (
        <div>
            <div><h1>SubString example</h1></div>
            {str.substring(0,10)}
        </div>
    );
}

export default SubstringEXP;

Github link: https://github.com/adi501/react-js-example

Reactjs code snippets

 Reactjs code snippets

How to install: https://marketplace.visualstudio.com/items?itemName=xabikos.ReactSnippets

Below is a list of all available snippets and the triggers of each one. The  means the TAB key.

Trigger

Content

rcc→

class component skeleton

rrc→

class component skeleton with react-redux connect

rrdc→

class component skeleton with react-redux connect and dispatch

rccp→

class component skeleton with prop types after the class

rcjc→

class component skeleton without import and default export lines

rcfc→

class component skeleton that contains all the lifecycle methods

rwwd→

class component without import statements

rpc→

class pure component skeleton with prop types after the class

rsc→

stateless component skeleton

rscp→

stateless component with prop types skeleton

rscm→

memoize stateless component skeleton

rscpm→

memoize stateless component with prop types skeleton

rsf→

stateless named function skeleton

rsfp→

stateless named function with prop types skeleton

rsi→

stateless component with prop types and implicit return

fcc→

class component with flow types skeleton

fsf→

stateless named function skeleton with flow types skeleton

fsc→

stateless component with flow types skeleton

rpt→

empty propTypes declaration

rdp→

empty defaultProps declaration

con→

class default constructor with props

conc→

class default constructor with props and context

est→

empty state object

cwm→

componentWillMount method

cdm→

componentDidMount method

cwr→

componentWillReceiveProps method

scu→

shouldComponentUpdate method

cwup→

componentWillUpdate method

cdup→

componentDidUpdate method

cwun→

componentWillUnmount method

gsbu→

getSnapshotBeforeUpdate method

gdsfp→

static getDerivedStateFromProps method

cdc→

componentDidCatch method

ren→

render method

sst→

this.setState with object as parameter

ssf→

this.setState with function as parameter

props→

this.props

state→

this.state

bnd→

binds the this of method inside the constructor

disp→

MapDispatchToProps redux function

 Reference: https://marketplace.visualstudio.com/items?itemName=xabikos.ReactSnippets

Convert String to Number in react js

import React from 'react';

function ConvertStringToNumber(props) {
    const num="2000";
    return (
        <div>
            <div><h1>Convert String to Number</h1></div>
            {Number(num)}
        </div>
    );
}
export default ConvertStringToNumber;

Github link: https://github.com/adi501/react-js-example

19 October 2021

Rearrange an array in order – largest,smallest, 2nd largest , 2nd smallest,... nth largest, nth smallest

Input is Array of integers. task is to check if any duplicates is there need to print like "Invalid Input". if duplicates not there we need to print like.

1st Largest Number, 1st smallest number, 2nd largest number, 2nd smallest number,....nth largest number, nth smallest..

You can see Examples in below:

Example 1: 

 Input: arr[] = [5, 8, 1, 4, 2,2, 9, 3, 7, 6]

 Output: Invalid Input

Example 2: 

Input: arr[] = [1,3,4,2,5,7,9,8,6]

Output:

9

1

8

2

7

3

6

4

5


Solution in C#.net

using System;

using System.Linq;


namespace ConsoleApp4

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] input1 = new int[] { 1, 2, 3, 4, 5, 7, 8, 9, 6 };

            BigAndSmallNumbers(input1);

            Console.ReadKey();

        }

        public static void BigAndSmallNumbers(int[] input1)

        {

            bool duplicate = false;

            for (int i = 0; i < input1.Length; i++)

            {

                for (int j = i + 1; j < input1.Length; j++)

                {

                    if (input1[i] == input1[j])

                    {

                        duplicate = true;

                    }

                }

            }


            if (duplicate == false)

            {

                Array.Sort(input1);

                Array.Reverse(input1);

                int n = input1.Length;

                int ArrIndex = 0;

                int[] output = new int[input1.Length];


                for (int i = 0, j = n - 1; i <= n / 2 || j > n / 2; i++, j--)

                {


                    if (ArrIndex < n)

                    {

                        output[ArrIndex] = input1[i];

                        ArrIndex++;

                    }


                    if (ArrIndex < n)

                    {

                        output[ArrIndex] = input1[j];

                        ArrIndex++;

                    }

                }


                foreach (var a in output)

                {

                    Console.WriteLine(a);

                }

            }

            else

            {

                Console.WriteLine("Invalid Input");

            }

        }

    }

}


Code in Git: 
https://github.com/adi501/Rearrange-an-array-in-order-largest-smallest-2nd-largest-2nd-smallest-...-nth-largest-nth-smal





18 October 2021

How to install missing node modules in react js

npm install 

npm install: it will install all dependencies that are specified in the package.json

14 October 2021

usesqlserver not found .net core

 

First install the Microsoft.EntityFrameworkCore.SqlServer using NuGet Package like below

PM > Install-Package Microsoft.EntityFrameworkCore.SqlServer


Then, import the namespace in file

using Microsoft.EntityFrameworkCore;

28 September 2021

How to update models in VS 2019 from database in Entity Framework in ASP.NET Core


  • Go to Tools -> Nuget Package Manager -> Package Manager Console (as below image)


  • Next go to Package Manager Console and add below script and run as below image. To Update already created models via Scaffold-DbContext we need to use "Force" param as below script

Scaffold-DbContext "Server=ServerName;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force






1 August 2021

How to enable CORS in ASP.NET Core

 open startup.cs page .net core project

In ConfigureServices() method:

public void ConfigureServices(IServiceCollection services)

{

 --------                 

  services.AddCors();

 --------

}

In Configure() method:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

  {

  --------

   app.UseCors(builder =>

          builder.AllowAnyOrigin()

          .AllowAnyHeader()

          .AllowAnyMethod()

        );

  --------

  }


22 July 2021

Exponent operator in javascript

const data = 2 ** 4;
//same as :Math.pow(2,4);
console.log(data);

Output:

16           

Github link : https://github.com/adi501/JavaScriptExamples.git

 

Template string in javascript

const name = "world";
const message = `Hello ${name}`;
console.log(message);

Output:

Hello world           

Github link : https://github.com/adi501/JavaScriptExamples.git



Multiline string example in Javascript

console.log(`
this is a
multiline string
example`);

Output:

this is a 

multiline string 

example           

Github link : https://github.com/adi501/JavaScriptExamples.git



Default parameters in javascript

function print(a = 100) {
console.log(a);
}
print();
print(200);

Output:

100

200            

Github link : https://github.com/adi501/JavaScriptExamples.git






Arrow function in javascript

const sum = (a, b) => a + b;
console.log(sum(2, 5));

Output: 7

Github link : https://github.com/adi501/JavaScriptExamples.git





 

13 July 2021

How to find recently executed queries in SQL Server

select dest.text as Query,deqs.last_execution_time 

from sys.dm_exec_query_stats as deqs

cross apply sys.dm_exec_sql_text(deqs.sql_handle) as dest

order by deqs.last_execution_time desc


(or)


select dest.text as Query,deqs.last_execution_time 

from sys.dm_exec_query_stats as deqs

cross apply sys.dm_exec_sql_text(deqs.sql_handle) as dest

where dest.text like '%dm_exec_query_stats%'

order by deqs.last_execution_time desc