A Short Introduction to TensorFlow.JS

So this is a quick introduction for machine learning with JavaScript.

Above is a series of numbers. You can work out pretty easily that Y = 2X – 1. How you worked this out in your head is exactly how machine learning works.

This is all the code you need to predict the pattern with machine learning and TensorFlow JS. Read on to learn what is happening here.

First up you will need to create a model. A model is a trained neural network. This is a basic model with a single layer. Our layer here is the method `tf.layers.dense`

This layer has a single neuron which is represented by the property `units`. We are also feeding in a single value into the neural network represented by the property `inputShape`, which is our X value. Our neural network will try to predict the Y value.

We need to compile our model. There are two main functions here. Loss and Optimizer. This is how our model learns. It will predict a number and the loss function will calculate how close it was. The Optimizer will predict the next guess and try to get closer to the right formula.

This will happen many times increasing our accuracy. In our example it will happen 1000 times, represented by the `epochs` property. Each time it will enhance its guess, getting us closer to the correct formula.

We have our two data sets represented as two arrays, `xs` and `xy`. We need to convert our data to tensors first using `tf.tensor`. This is just a holder for our data with type information.

We match our two datasets to each other using the `model.fit` and passing in our two tensors (data). This method will take a while to complete, so we use `await` here.

Once the model is trained. We can now predict with our model using `model.predict`.

So we are predicting the Y value for 10. We already know it will be 19 (Y = 2X – 1). When we run the following code our model gives us 18.999. Success!

You are probably wondering about the .999, this is because we are only giving it a small dataset and it is accounting for that in its prediction.

Hoped you like this article.

Below is the complete code.

Desktop Keyboard Input for Android Chrome via Chrome Developer Tools(OSX)

As a web developer or a QA Tester there will come a time when you need to run a web form on mobile multiple times. This becomes quite laborious as mobile keyboards are not the most efficient bits of software.

Below i’ll show you the steps to use your desktop keyboard via Chrome Developer Tools on your mobile/tablet while also having full developer access to the webpage on the Android device.


  • A usb cable
  • Chrome 32 or later
  • An android device with Android 4.0+

Note: A small note. Remote debugging requires your desktop Version of Chrome to be a newer version Android Chrome. To resolve this just ensure you run Chrome Canary.

Step 1. Enable remote debugging on your Android Device.

On your Android phone goto: Settings > Developer Options and Tap the “Build Number” Seven times. Then check the “USB debugging” option in the menu (Developer Options).
(An in depth guide from Google)

Step 2. Connect your Android Device to your computer via USB cable.

Step 3. Open “Inspect devices” in Chrome Canary.

Screenshot 2015-01-13 10.13.34

Step 3. Open Chrome on your Android device

A notification will appear on your Android device asking to “Allow USB debugging?” Tap OK. If this is your Developer machine check “Always allow from this computer”

Step 4. Inspect a website.

In the below image you will see that I am opening a web page on the android device without needing to use the Android Keyboard.

You can simply enter your ultra long developer url in here. Some developer urls are by no means nice urls so this is a extremely handy feature.

After that Click “Inspect”


Tip: If you have a single server that you hit quite a bit maybe you should place a NFC tag on your screen so you can open the url on any number of NFC enabled android devices.

Step 5. hit the Screencast Icon.

Once in Developer tools, click the screencast Icon. This will mirror the Android website to your desktop. Kinda like Remote Desktop. The transparent sections are the Android user interface.

You will now be able to fill in forms with your desktop keyboard hopefully saving you many hours in development.


The Back, Forward and Refresh icons are now available on your desktop as well as a url box. This will hopefully allow you to perform hands free mobile development.

This will also allow you to test situations where the devices keyboard will cover half your web page, something that cannot be emulated right now with desktop chrome.

Screenshot 2015-01-13 10.10.22


Tip: Instead of selling your old phones or giving them away, create your own personal device testing station. You can build your own or buy one. I use the Vanamco Device Lab which is pretty neat. I bought an 8 port USB dongle and connect that to my computer.

I also have a few NFC tags for websites I am currently developing.

Screenshot 2015-01-13 14.18.33

So what do we do with Opera?

So what do we do with Opera? In this world of the ever evolving browser wars. Here we have a browser that is always out smarting the popular browsers with its cutting edge developments. Normally it serves as an inspiration of what we can expect in the popular browsers, however it lacks major browser share. At 2.2% (August 2012) you would think it was a lost cause. Wrong! It actually has over 270 million users world wide [1].

So one use I find perfect for Opera is using it as a finely tuned work tool. When you think of browsing the web, it normally entails checking out a local news site, Watching some pelvic thrusting cats and seeing what your eccentric Aunt is up to on Facederp. But some people actually do work inside a web browser. Really! For those of you who use a browser for work, you  will want something fast, very fast. Also you will want something separate from the browser you normally use Facederp on. Opera is the perfect work browser. Its fast, it hardly breaks and it’s completely separate to your personal browser. So you don’t need to worry about Bookmarks syncing to your home computer or what not. Even having a different icon is beneficial as this allows faster program switching. So give Opera a try as your work browser.

Blood Red Shoes – In Time to Voices

Play “Two Dead Minutes”

Two Dead Minutes

Renowned for their simmering on-stage tension, Brighton duo Blood Red Shoes have always felt like the kind of band who could implode at any minute. So it comes as something of a surprise how harmonious their third studio album, In Time to Voices, sounds. Indeed, other than the quick burst of abrasive scream-punk on “Je Me Perds,” there’s little here that reflects Laura-Mary Carter and Steven Ansell’s recent confessions of in-fighting during its recording. “Night Light” is the kind of winsome acoustic fare you’d expect to hear around a campfire; the enchanting harmonies on the lo-fi grunge of “Two Dead Minutes” could be mistaken for the Magic Numbers, while the Yeah Yeah Yeahs-esque lead single “Cold” is arguably the most danceable song they’ve ever had. Foals producer Mike Crossey may remain the only real constant from their more ferocious first two albums, but that’s not to say they’ve lost their edge. The title track lives up to their “most ambitious record” claims as it ventures into brooding Americana before slowly building into an unsettling garage-rock crescendo: “Lost Kids” is a stinging slice of scuzz-rock inspired by the London riots; while “Stop Kicking” appears to take its cue from the early-’90s shoegaze scene with its slightly disorienting layers of distortion and shimmering riffs. The sluggish alt rock of “Down Here in the Dark” and the forgettable new wave of “7 Years” means In Time to Voices finishes with a whimper rather than the bang it deserves. But if such an otherwise emphatic and melodic record is the result of such constant squabbling, then Blood Red Shoes should perhaps start planning their arguments in advance for album number four. ~ Jon O’Brien

Album on iTunes