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

How to Implement Merge Sort in JavaScript the easy way.

// 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(

// 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]) {
    } else {

  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.

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:

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.

All The Things Game of Thrones Left Hanging in the Air

The Verge has the full list:

A few of my favorites:

Where did the Dothraki go?

Unclear. There’s a clear shot of some Dothraki just chilling by the docks in King’s Landing while Jon makes his sad walk to his boat, but while there’s some clear information about why the Unsullied didn’t riot, kill Jon Snow, and take the city themselves, the same courtesy isn’t given the Dothraki, who were apparently pretty chill about their queen being murdered.

Given that they only came to Westeros to serve Dany and help her kill the men in metal suits and break their stone houses, it’s not clear what they have to do now, especially with their Khaleesi dead. Still, for a Dothraki fighter, the whole Westeros trip was probably a pretty successful vacation, given those goals.

What about the Unsullied?

While Tyrion does offer them land in the Reach and the chance to become a house of Westeros, we see Grey Worm captaining a ship of Unsullied later in the episode, alongside a fleet of similarly black-sailed ships. It’s not entirely clear whether the entire band of Unsullied is joining Grey Worm as he sails to Naath, presumably to liberate Missandei’s people. But it does seem likely that they’re going collectively.

It seems that with or without Daenerys to lead them, the Unsullied will continue to fight to liberate people — a fitting ending for the freed slaves.

Why does the North just get to stay independent?

It’s a little strange that Sansa casually breaks the North away from the rest of the Seven (now Six) Kingdoms in accordance with the North’s well-established independent streak, and the lords of the Vale, the Riverlands, Casterly Rock, Storm’s End, the Reach, and Dorne don’t have the faintest word to say about their own status.

Honestly, there’s no real reason why the North should get its independence — especially since, say, Dorne is a far more independent kingdom, which joined the Seven Kingdoms two centuries after Aegon conquered the others. Dorne has historically been far more independently minded than the North, even though the North’s rebellion against the Iron Throne got a lot more air time on the show.

What’s Daario up to?

Daario Naharis was part of the Mereen subplot on the show. He eventually led the Second Sons, a mercenary company, and was one of Daenerys’ paramours, as well as part of her inner circle when she led the city. But when Daenerys leaves for Westeros at the end of the sixth season, she leaves Daario behind in Meereen alongside the Second Sons, and we haven’t seen him since.

Given his importance to Daenerys and the large military force he commands, it’s possible that the show could have brought him back for the war against Cersei, but it seems like Daario is still stuck in Mereen.

A Retro Adventure Game Creator for Your Favorite Handheld Video Game System

John Gruber via Daring Fireball:

GB Studio is “A free and easy to use retro adventure game creator for your favourite handheld video game system”, by which they mean, but don’t want to name specifically, Nintendo’s GameBoy.

What a fun idea from developer Chris Maltby. You can output ROMs for emulators, play them on actual GameBoy hardware with a flash cartridge, or even export them for the web (which will even work on phones). It’s a remarkably polished IDE.

Get it here.