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

      


Other ways to Say "FOR EXAMPLE"

 

  • For instance...
  • To give you an idea...
  • As proof...
  • Suppose that...
  • To illustrate...
  • Imagine...
  • Pretend that...
  • To show you what I mean
  • Let's say...
  • Case in point...
  • e.g.
  • Such as...
  • In particular... 


Ways to Offer Help

  • Do you need any help? 
  • What can I do for you? 
  • Would you like  me to help? 
  • Let me help you. 
  • Do you want me to help? 
  • May I ..?
  • Do you need some assistance? 
  • Can I give you a hand? 
  • Is there anything I can do for you? 
  • Can I help you?
  • Need any help?
  • If you need anything let me know

 

WAYS TO SAY "CALM DOWN"

   

  • Relax
  • Take it easy
  • Give it a rest
  • Go easy
  • Take a deep breath. 
  • Slow down. 
  • Control yourself
  • Chill out
  • Loosen up
  • Simmer down 
  • Just drop it. 
  • Just let it go. 
  • Just take a breath
  • Count to 10
  • Steady on 
  • Take a chill pill! 
  • How about a big hug. 
  • Want to squeeze my hand? 

Ways to Say GOOD JOB

  • Tremendous!.
  • Fantastic!
  • Excellent!
  • Super-Duper!
  • out of sight.
  • You certainly did well today.
  • That kind of work makes me happy.
  • One more time and you'll have it.
  • Couldn't have done it better myself.
  • You really make my job fun.
  • That's the right way to do it.
  • Keep working on it; you're improving.
  • You're getting better every day.
  • You must have been a  practicing. 
  • Tremendous 
  • That's how to handle that.
  •  That's better than ever. 
  • That was first class work. 
  • Incredible
  • Hats off
  • Unbelievable
  • Remarkable
  • Superb
  • Astonishing
  • Splinted
  • Awesome
  • Marvelous
  • Wow
  • Unbelievable
  •  Now that's what I call fine job.