find any/all element with custom attribute + jquery

$('*[data-test-id]')

$('*[attr-name]') - result is an array, we can get length of it.

Find overlap between two strings + Java Script

function findOverlap(a, b) {
  if (b.length === 0) {
    return "";
  }
 
  if (a.endsWith(b)) {
    return b;
  }
 
  if (a.indexOf(b) >= 0) {
    return b;
  }
 
  return findOverlap(a, b.substring(0, b.length - 1));
}
Some test cases:
findOverlap("12345", "aaa")
""
findOverlap("12345", "12")
"12"
findOverlap("12345", "345")
"345"
findOverlap("12345", "3456")
"345"
findOverlap("12345", "111")
"1"

error: src refspec master does not match any + git push origin -u master

Did you try -> git push origin -u master


After git init, your git repository do not have any commits yet. Try adding a file, commit and then push.


Try this:


>> git add <file_name>
>> git commit -m "fitst commit"
>> git push -u origin master

Works.

fatal: Not a git repository (or any of the parent directories): .git

Try -> git init

After cd to the target folder, try git init. It will inititalize the git respository.

How to use a custom data strucutre or data type defined in java script

// From a length
var uint16 = new Uint16Array(2);
uint16[0] = 42;
console.log(uint16[0]); // 42
console.log(uint16.length); // 2
console.log(uint16.BYTES_PER_ELEMENT); // 2
Uint16Array is defined as data structure or data type, then we can use it as 

var uint16 = new Uint16Array();

How to change tomcat port number from 8080

  • Goto tomcat>conf folder
  • Edit server.xml
  • Search "Connector port"
  • Replace "8080" (Default) by your new port number
  • Restart tomcat server.
Similarly you can also change port number for HTTPS as well.

Java FileOutputStream Create File or Parent Folders if not exists

FileUtils from apache commons is a pretty good way to achieve this in a single line.
FileOutputStream s = FileUtils.openOutputStream("/home/nikhil/somedir/file.txt")
This will create parent folders if do not exist and create a file if not exists and throw a exception if file object is a directory or cannot be written to. This is equivalent to:
File file = new File("/home/nikhil/somedir/file.txt");
file.getParentFile().mkdirs(); // Will create parent directories if not exists
file.createNewFile();
FileOutputStream s = new FileOutputStream(file,false);
All the above operations will throw an exception if the current user is not permitted to do the operation.