How To Batch commands in .bat file on Windows

Using the && ^ operators we can batch different commands to be executed in windows command prompt.

// example file – test.bat

mkdir newdir && ^
rd /s /q somefolder/otherfolder && ^
rd /s /q difffolder/otherfolder

Using only a single & symbol will make the following command execute even if the current one fails.
Also this is a good example of how to delete folders in a quick efficient way.

Google Android Play Store Target API Requirement Change

From Google:

Hello Google Play Developer,

This is a reminder that starting November 1, 2019, updates to apps and games on Google Play will be required to target Android 9 (API level 28) or higher. After this date, the Play Console will prevent you from submitting new APKs with a targetSdkVersion less than 28.

Configuring your app to target a recent API level ensures that users benefit from significant security and performance improvements, while still allowing your app to run on older Android versions (down to the minSdkVersion).

Android 9 (API level 28) introduces a number of changes to the Android system. The following behavior changes apply exclusively to apps that are targeting API level 28 or higher. Apps that set targetSdkVersion to API level 28 or higher must modify their apps to support these behaviors properly, where applicable to the app.

To target the api in your Cordova app set these min and target version in config.xml

    <preference name="android-minSdkVersion" value="23" />
    <preference name="android-targetSdkVersion" value="28" />

How to Set proper Rules on Google Firebase DB

How to Set proper Rules on Google Firebase DB:

Here is an example of a pretty simple rules setting. We don’t want just anyone to access user information. The users sub directory is restricted to the user logged in. The rest is fully restricted and is only accessible via admin api.

service cloud.firestore {
  match /databases/{database}/documents {
    // Make sure the uid of the requesting user matches name of the user
    // document. The wildcard expression {userId} makes the userId variable
    // available in rules.
    match /someusercollection/{userID}/{document=**} {
      allow read, update, delete: if request.auth.uid == userId;
      allow create: if request.auth.uid != null;
    }
    match /somecollection/{document=**} {
      allow read, update, delete, create: if false;
    }
  }
}

Read more on the Firebase Docs.

How to Implement Binary Search in JavaScript


function binarySearch (list, value) {
  // initial values for start, middle and end
  let start = 0
  let stop = list.length - 1
  let middle = Math.floor((start + stop) / 2)

  // While the middle is not what we're looking for and the list does not have a single item
  while (list[middle] !== value && start < stop) {
    if (value < list[middle]) {
      stop = middle - 1
    } else {
      start = middle + 1
    }

    // recalculate middle on every iteration
    middle = Math.floor((start + stop) / 2)
  }

  // if the current middle item is what we're looking for return it's index, else return -1
  return (list[middle] !== value) ? -1 : middle
}

const list = [2, 5, 8, 9, 13, 45, 67, 99]
console.log(binarySearch(list, 99)) // 7 -> returns the index of the item

How to Implement Merge Sort in JavaScript


// Split the array into halves and merge them recursively 
function mergeSort (arr) {
  if (arr.length === 1) {
    // return once we hit an array with a single item
    return arr
  }

  const middle = Math.floor(arr.length / 2) // get the middle item of the array rounded down
  const left = arr.slice(0, middle) // items on the left side
  const right = arr.slice(middle) // items on the right side

  return merge(
    mergeSort(left),
    mergeSort(right)
  )
}

// compare the arrays item by item and return the concatenated result
function merge (left, right) {
  let result = []
  let indexLeft = 0
  let indexRight = 0

  while (indexLeft < left.length && indexRight < right.length) {
    if (left[indexLeft] < right[indexRight]) {
      result.push(left[indexLeft])
      indexLeft++
    } else {
      result.push(right[indexRight])
      indexRight++
    }
  }

  return result.concat(left.slice(indexLeft)).concat(right.slice(indexRight))
}

const list = [2, 5, 1, 3, 7, 2, 3, 8, 6, 3];
console.log(mergeSort(list)) // [ 1, 2, 2, 3, 3, 3, 5, 6, 7, 8 ];

Calculate time difference between two times in JS

function CountingMinutes(str) { 

  let arr = str.split("-");
  // console.log(arr[0]);
  // code goes here  
  let day = 24 * 60;
  
  let end = getMinutes(arr[1]);
  let start = getMinutes(arr[0]);
  
 // console.log('end is ' + end);
 // console.log('start is ' + start);
  if (end < start){
    end += day;
  }
  return (end-start) ; 
         
}

function getMinutes(time){
  
  let hr = parseInt(time.split(':')[0]);
  let min = parseInt(time.split(':')[1].match(/[0-9]/g).join(""));
  
  let morning = time.match(/am/g);
  let pm = time.match(/pm/g);
 // console.log(pm);
  if (pm && hr < 12){
    hr += 12;
  }
  else if (morning && hr === 12){ // convert midnight to zero
    hr += 12;
  }
  
  let totalMin = parseInt((hr*60) + min);
  
  return totalMin ;
}                       

iOS Deprecated API Usage Warning Ionic using UIWebView

Apple will no longer support web apps that use UIWebView. The apps and libraries need to be migrated to use WkWebView.

The latest Ionic already uses WkWebView, but several Cordova plugins still rely on UIWebView which is a problem.

https://ionicframework.com/docs/v3/wkwebview/

If you’re using Ionic you need to upgrade to iOS Cordova 5

cordova platform remove ios
cordova platform add ios@5.0.0

Also you might need to remove additional plugins that use UIWebView such as inappbrowser.

cordova plugin rm cordova-plugin-inappbrowser

More information about the breaking changes can be found here:

https://cordova.apache.org/news/2018/08/01/future-cordova-ios-webview.html

Raspberry PI used to hack NASA Secrets

Engadget reporting:

NASA’s Jet Propulsion Laboratory (JPL) suffers from multiple cybersecurity weaknesses despite the advances it has achieved in space technology, according to the agency’s Office of Inspector General (PDF). Investigators looked into the research center’s network security controls after an April 2018 security breach, wherein a Raspberry Pi that was not authorized to be linked to the JPL network was targeted by hackers. The attackers were able to steal 500 megabytes of data from one of its major mission systems, and they also used that chance to find a gateway that allowed them to go deeper into JPL’s network.

Probably happens all the time.