Monday, January 24, 2022

Change default Port on Next.js app

 If any other app or process is running on port 3000, you will get this error in your terminal


Port 3000 is already in use.

error Command failed with exit code 1.


Solutions

To set it inside your package.json's script section.

"scripts": {

    "dev": "next -p 3040", // This will change it for dev environment

    "build": "next build",

    "start": "next start -p 3040" // This will change it for the production

}

Friday, September 3, 2021

Battery icon is not showing on taskbar


Windows 10, try this fix:

Open Device Manager (accessible by right clicking your Start Button)

Expand the Batteries section

For each device in that section:

Right click and choose Disable

Then right click and choose Enable

Close Device Manager

screen shot shown as below




Wednesday, July 22, 2020

How to check if a set of key and value already exists in a dictionary

Dictionary<int, string> dict = new Dictionary<int, string>();
// initial value for demonstration
dict.Add(1, "Test");
dict.Add(2, "Test2");

use below method to check whether a key is exist or not

  if (!dict.ContainsKey(1))
        dict.Add(1, "Test");

 if (!dict.ContainsValue("Test"))
        dict.Add(1, "Test");

Monday, June 29, 2020

Error when pasting text in IE

The code for the event handler that is called when pasting some text into the input control throws an error because 'e.originalEvent.clipboardData' or  "Invalid argument" is undefined in Internet Explorer.


This code applies the fix and works fine

_searchInput.on('paste', function (e) {
var data;
if (window.clipboardData && window.clipboardData.getData) { // IE
data = window.clipboardData.getData('Text');
}
else if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) { // other browsers
data = e.originalEvent.clipboardData.getData('text/plain');
}

Tuesday, February 25, 2020

disable Parameter_Sniffing at the database level

The Parameter_Sniffing option can be disabled using the below ALTER DATABASE statement:

ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;



from the Options tab of the Database Properties window, by changing the Parameter_Sniffing value to OFF as follows:



Monday, February 24, 2020

search text file using c# and display the line number and the complete line that contains the search keyword


Sample Input:

just a sample line
another sample line
first matching Order line
not a match
...here's a Order  match
Order 123

foreach (var match in File.ReadLines(@"c:\LogFile.txt")
                          .Select((text, index) => new { text, lineNumber = index+ 1 })
                          .Where(x => x.text.Contains("Order ")))
{
    Console.WriteLine("{0}: {1}", match.lineNumber, match.text);
}



Output:

3: first matching Order line
5: ...here's a Order  match
6: Order 123

Sunday, February 23, 2020

How can i call a server side button click function from client side?

option is to simulate Click of a button using javascript.
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" style="display:none" />
HTML markup will look like this:

<button id="btnsave" onclick="fncsave()">Save</button>
now simulate a Click using JS

<script type="text/javascript">
     function fncsave()
     {
        document.getElementById('<%= savebtn.ClientID %>').click();
     }
</script>

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...