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

14 June 2021

Comma Separated Value in SQL Query

 

--- create Table

create table Tbl_Exp(Id int identity(1,1) primary key,Emp_Name varchar(50),Working_Day varchar(5))


-- insert some test data

insert into Tbl_Exp values('Adi','M')

insert into Tbl_Exp values('Adi','T')

insert into Tbl_Exp values('Adi','W')

insert into Tbl_Exp values('Adi','TH')

insert into Tbl_Exp values('Pavan','F')

insert into Tbl_Exp values('Pavan','S')

insert into Tbl_Exp values('Pavan','M')

insert into Tbl_Exp values('Madhan','T')

insert into Tbl_Exp values('Madhan','W')


select * from Tbl_Exp


--how to use stuff [to replace some data], by using below query we are going to Replace 1st 2 letters with "***"

select stuff('abcdef',1,2,'***')


-- How to get comma separated value using XML path


Select ','+Working_Day from Tbl_Exp for xml path('')


-- how to remove 1 st values using stuff


select stuff((Select ','+Working_Day from Tbl_Exp for xml path('')),1,1,'')


-- Final Query


select distinct Emp_Name,

(select stuff((Select ','+Working_Day from Tbl_Exp as a where a.Emp_Name=b.Emp_Name for xml path('')),1,1,'') as a) as 'comma_separated'

from Tbl_Exp as b





How to Display the Previous Row and Next Row value in SELECT statement

 In SQL Server by using LAG & LEAD We can find then Previous & Next row values as below example.

-- create Table

create table Tbl_Test(Id int)


-- Insert some test data into Table

insert into Tbl_Test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11)


-- find Current,Previous Row Value

select Id,Lag(Id,1,0) over(Order by Id) as Previous_Value  from Tbl_Test



-- find Current,Next Row Value 

select Id,LEAD(Id,1,0) over(Order by Id) as Next_Value  from Tbl_Test



-- Display Previous,Current, Next row Values

select Lag(Id,1,0) over(Order by Id) as Previous_Value,Id as Current_Value,LEAD(Id,1,0) over(Order by Id) as Next_Value  from Tbl_Test



-- Display 2nd Previous,Current, 2nd Next row Values

select Lag(Id,2,0) over(Order by Id) as '2nd_Previous_Value',Id as Current_Value,LEAD(Id,2,0) over(Order by Id) as '2nd_Next_Value'  from Tbl_Test



5 June 2021

tab delimited text file writing and reading in c#

 

using System;

using System.IO;

using System.Text;


namespace tab_delimited

{

    class Program

    {

        static void Main(string[] args)

        {

            string fileName = @"C:\Temp\Adi.txt";

            try

            {

                // Check if file already exists. If yes, delete it.     

                if (File.Exists(fileName))

                {

                    File.Delete(fileName);

                }


                var delimiter = "\t";

                var newline = "\n";

                StringBuilder sb = new StringBuilder();

                sb.Append("1" + delimiter + "2" + delimiter + "3" + delimiter + "4" + delimiter + "5");

                sb.Append(newline);

                sb.Append("6" + delimiter + "7" + delimiter + "8" + delimiter + "9" + delimiter + "10");

                sb.Append(newline);

                sb.Append("11" + delimiter + "12" + delimiter + "13" + delimiter + "14" + delimiter + "15");

                sb.Append(newline);

                sb.Append("16" + delimiter + "17" + delimiter + "18" + delimiter + "19" + delimiter + "20");


                // Create a new file     

                using (FileStream fs = File.Create(fileName))

                {

                    //// Add some text to file    

                    Byte[] title = new UTF8Encoding(true).GetBytes(sb.ToString());

                    fs.Write(title, 0, title.Length);

                }


                // Open the stream and read it back.    

                using (StreamReader sr = File.OpenText(fileName))

                {

                    string s = "";

                    while ((s = sr.ReadLine()) != null)

                    {

                        Console.WriteLine(s);

                    }

                }


                Console.ReadLine();

            }

            catch (Exception Ex)

            {

                Console.WriteLine(Ex.ToString());

            }

        }

    }

}


Output:


5 March 2021

Cool Phrasal Verbs

 

 Hit me up

 Contact me 

 Catch up 

 To meet

 Chill out

 To relax

 Hang out

 Spend time 

 Stand by 

 Do nothing

 Look around 

 Search 

Drop in 

 To Visit

Fed up 

Frustrated

To be up to

 Doing something

Call off 

 To cancel 

Figure out

 Understand

Give up 

 Stop trying

Put off 

 Postpone 

Turn up 

 Appear 

Mess around

 Being silly

Cool off 

 To become cooler