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.

How to Use iOS GameCenter Leaderboards in Unity3d

You need to setup your app on the appstore connect first with the appropriate leaderboard. And you can only test this code on the iOS device and not in the unity3d player.

using UnityEngine.SocialPlatforms;

  private ILeaderboard leaderboard;
  private string leaderboard_id = "yourleaderboardid"; // setup on appstore connect

 void Start()

    // Authenticate user first
        Social.localUser.Authenticate(success => {
            if (success)
                Debug.Log("Authentication successful");
                string userInfo = "Username: " + Social.localUser.userName +
                    "\nUser ID: " + +
                    "\nIsUnderage: " + Social.localUser.underage;
                Debug.Log("Authentication failed");

  // create social leaderboard
        leaderboard  = Social.CreateLeaderboard(); = leaderboard_id;
        leaderboard.LoadScores(result =>
            Debug.Log("Received " + leaderboard.scores.Length + " scores");
            foreach (IScore score in leaderboard.scores)

  void ReportScore(long score, string leaderboardID)
        Debug.Log("Reporting score " + score + " on leaderboard " + leaderboardID);
        Social.ReportScore(score, leaderboardID, success => {
            Debug.Log(success ? "Reported score successfully" : "Failed to report score");

 void OpenLeaderboard()

What is SoftBank, and who is behind the Silicon Valley’s largest VC fund?


SoftBank is a Tokyo-based company founded almost four decades ago by Masayoshi Son at the age of 24. What started as a store for computer parts has become one of Japan’s most important public companies, valued at over $115 billion. It now is essentially a tech, media, and telecom conglomerate — it owns more than 80 percent of Sprint, more than one-quarter of Alibaba, and 100 percent of the robotics company Boston Dynamics, whose nightmare-inducing animatronics might be familiar to you.

But SoftBank in recent years has been transitioning from a Verizon or AT&T of Japan to something like more of a Blackstone of the world, intentionally moving from a telecom-based giant to a global investing vehicle — thanks, largely, to the Vision Fund.

To understand SoftBank is to understand Son, an eccentric, Star Wars-quoting, diminutive man who is known in the world of high finance solely as “Masa.” To his fans, Son is a daring savant, whose early investment in Alibaba has become part of venture capital lore and at one point made him one of the richest men in the world. To his detractors, Son is an arrogant fool who got lucky once but has since run roughshod over a venture capital system that was already working.

Scary & interesting read.

Uber Stock is a Disaster

Gizmodo reporting:

According to one analyst, the company may be profitable by 2024, though its only real plan so far is to continue to screw workers and eventually replace them with unproven technology. As former CEO Travis Kalanick said in 2014, “the reason that Uber could be expensive is you’re not just paying for the car, you’re paying for the other dude in the car who’s driving.”

Presently, investors are probably realizing that what they’re paying for is an unsustainable company so huge that its main justification for existing is sunk cost.