Monday, August 10, 2020

Check a String Contains a Substring in JavaScript

 



Options : Use the indexOf() Method

The simplest and fastest way to check whether a string contains a substring or not in JavaScript is the indexOf() method. This method returns the index or position of the first occurrence of substring within the string, otherwise, it returns -1 if no match found. Here is an example:



  • <script>
  •     // Sample string
  •     var str = "The quick brown fox jumps over the lazy dog."
  •     
  •     // Check if the substring exists inside the string
  •     var index = str.indexOf("fox");    
  •     if(index !== -1){
  •         alert("Substring found!");
  •     } else{
  •         alert("Substring not found!");
  •     }
  • </script>




In ES6 you can use the includes() method to check if a contains a substring. This method simply returns true or false instead of the index. Let's check out an example:



  • <script>
  •     // Sample string
  •     var str = "The quick brown fox jumps over the lazy dog."
  •     
  •     // Check if string contains substring
  •     if(str.includes("fox")){
  •         alert("Substring found!");
  •     } else{
  •         alert("Substring not found!");
  •     }
  • </script>


Check out the tutorial on JavaScript ES6 features to learn about new features introduced in ES6.

Further, you can use the search() method to search a particular piece of text or pattern (using regular expression) inside a string. Like indexOf() method the search() method also returns the index of the first match, and returns -1 if no matches were found.




  • <script>
  •     // Sample string
  •     var str = "Color red looks brighter than color blue."
  •     
  •     // Search the string for a match
  •     var index = str.search(/color/i);  
  •     if(index !== -1){
  •         alert("Substring found!");
  •     } else{
  •         alert("Substring not found!");
  •     }
  • </script>

Friday, August 7, 2020

Online tool for Base64 Decode and Encode

 


https://www.base64decode.org/



How that works ---


https://www.base64decode.org/

IIS Reset using Command Prompt

 


1) Open the Command Prompt. Click on Start > All Programs > Accessories > Command Prompt
Note: It may be necessary to right click on the Command Prompt icon and select "Run as Administrator", if the following steps fail with a warning stating the task requires elevation. 

2) Once the Command Prompt window opens, type 'iisreset' (without quotes) and then press Enter.

3) Or - 

To start IIS on command line, Open terminal and type:

c:/> iisreset /start
 Stop IIS via Command Line:

Use following command to stop IIS service on Windows operating systems. Either use Windows command prompt to run this command or execute it from run window.

c:/> iisreset /stop
ReStart IIS via Command Line:

Use the following command to restart IIS service on Windows operating systems. Either use the Windows command prompt to run this command or execute it from the run window.

c:/> iisreset /restart

[or]

c:/> iisreset
Default iisreset command restarts the IIS service. So you don’t need to provide /restart parameter option to iisreset command to restart IIS service
To restart IIS using the IISReset command-line utility
  1. From the Start menu, click Run.
  2. In the Open box, type cmd, and click OK.
  3. At the command prompt, type
    iisreset /noforce
    .
  4. IIS attempts to stop all services before restarting. The IISReset command-line utility waits up to one minute for all services to stop. If the services cannot be stopped within one minute, all IIS services are terminated, and IIS restarts.

Failed to start build #21.x.x.xx in branch feature/Branch

 

Failed to start build #2.10.0.36 in branch feature/Branch at xx Oct 20 12:18 on teamcity--winagentxx



Failed to perform checkout on agent: '"C:\Program Files\Git\bin\git.exe" -c core.askpass=C:\BuildAgent\temp\buildTmp\pass4179502314375956300.bat -c credential.helper= -c credential.helper=C:\BuildAgent\temp\buildTmp\credHelper8372936110454433838.bat reset --hard 12845f9e01e475ec5d9ab6bc6da0c98c4abceb0b' command failed.

exit code: 128
stderr: fatal: Unable to create 'C:/BuildAgent/work/b512b387ffdf2f48/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.


One of the solution is GO TO AGENTS In team city --- And reboot the Agent. 



Visual Studio 2015 doesn't discover unit tests

 

Some things I've noticed I have to do from time to time to get tests to show up properly.

  1. If your solution is in a protected drive that you need administrator access to read/write, sometimes only a portion of the tests come up. Definitely run VS as administrator in that case.

  2. If your solution is 64 bit, make sure that Test > Test Settings > Default Processor Architecture is set to x64. Sometimes it gets set to x86. Set it to x64, then rebuild.

  3. Sometimes just restarting Visual Studio does the trick because the test explorer will start up again.

  4. Don't forget to actually build the test project/solution. (If you want it to get built with the rest of the projects, right-click on your solution > Properties > Configuration Properties > Configuration > check the "Build" box for your test project)

  5. Ensure the tests are in a public section of your test class


https://stackoverflow.com/questions/25304425/visual-studio-2013-doesnt-discover-unit-tests



How to install   NUnit Test Adapter 


http://nunit.org/nunitv2/docs/2.6.4/vsTestAdapter.html



NUnit Test Adapter for Visual Studio

Installation

Beginning with version 0.95 there are two ways of installing the adapter within Visual Studio. See Note 1 below for info on how to choose.

  1. Use the Extension Manager
  2. Add it as a Nuget package to your solution. (New in 0.95, requires VS 2012 Update 1 or higher)

Installing With the Extension Manager

To install the NUnit Test Adapter using the Extension Manager, follow these steps:

  1. From within Visual Studio 2012, 2013 or 2015, select Tools | Extension Manager.
  2. In the left panel of the Extension Manager, select Online Extensions.
  3. Locate (search for) the NUnit Test Adapter in the center panel and highlight it.
  4. Click 'Download' and follow the instructions.

Use the Extension Manager to ensure that the NUnit Test Adapter is enabled.

Installing the Nuget Package

To add it is a Nuget package, you must have an active solution, then follow these steps:

  1. From Tools menu, use Library Package Manager, select Manage NuGet packages for solution
  2. In the left panel, select Online
  3. Locate (search for) NUnit Test Adapter in the center panel and highlight it
  4. You will find two packages, one without framework and one with framework. See note 2 below for which to choose.
  5. Click 'Install'
  6. In the "Select Projects" dialog, you need to select at least one project to add the adapter to, see notes below.




Thursday, August 6, 2020

Visual Studio 2015 doesn't discover unit tests



If you using NUnit, make sure to download NUnit Adapter first.

Go to Tools → Extensions and Updates… → Online → search for "NUnit Test Adapter".


Refer:


https://stackoverflow.com/questions/25304425/visual-studio-2013-doesnt-discover-unit-tests



Health Benefits of Cashews

  Benefits of Cashews. Healthy food is an integral part of healthy body. Regular exercises such as Yoga and healthy diet is important to...