‘use strict’ in JavaScript

tl;dr

  • Runs the JS interpreter in a strict mode, meaning it fails loudly for bad practices in JS
  • Strict mode also eliminates silent errors. When something pretty major is going wrong, you won’t have to hunt for it.
  • If you’re writing good code, 'use strict' shouldn’t cause you any problems
  • Part of ES5/ES2015, official JS standard
  • Goes on top your code, must be the first line in your file. Must be a string 'use strict'
  • Keep in mind concatenation. It must be the first line and not concatenated somewhere in the middle, or it won’t work.
  • It can also be used inside your functions
  • If you get an error, it’ll stop executing the rest of the file
  • does webpack-dev-server run/compile in strict mode?

Examples

  • if you define variable without using the var (or let or const) keyword, it’ll throw an error (because you didn’t define a scope, var/let/constdefine the scope of the variable)

this is bad

it’s bad because you didn’t use the var (or let or const) keyword, which are needed to define the scope of the variable. You have cluttered the global name space by creating a global variable.

Now this bad code will still run normally, but if you use strict, it’ll fail and give you an error

  • If you write to an object that is non-writable, it’ll throw an error in strict mode

NaN is just an object used as example here, you wouldn’t actually write the above code.

  • if you try to delete (Object) properties that can’t be deleted

  • it used to throw an error for duplicate keys in an object but it doesn’t anymore in ES6.
  • Octal number syntax (leading zeros with numbers, like 020) will throw a syntax error

  • delete can not be used to delete variables or plain objects (you can only Object properties)

Links

wtf is a thunk?

https://github.com/thunks/thunks#what-is-a-thunk

What is a thunk?

  1. ALGOL thunks in 1961

  2. thunk is a function that encapsulates synchronous or asynchronous code inside.

  3. thunk accepts only one callback function as an arguments, which is a CPS function.

  4. thunk returns another thunk function after being called, for chaining operations.

  5. thunk passes the results into a callback function after being excuted.

  6. If the return value of callback is a thunk function, then it will be executed first and its result will be send to another thunk for excution,
    or it will be sent to another new thunk function as the value of the computation.

React Router

history is required.

What we did above is we mounted a Router to the DOM, it is now going to take Routes. A route takes a path (URL) and shows a component on that path.

Link

If you want to navigate anywhere within the site, you use Link. You’ll only use actual href when you want to move away from the site. A link looks like this:

You will not be making any server requests to go to any of these different links/pages.

Nested Routes

You can have nested routes just like you can have nested components

What the could above will do is that it’ll load the Users route/component inside the Main route/component.

IndexRoute

IndexRoute let’s you render props.children. It’s aimed at setting a default UI that opens when you are at the route.

Props

You can also pass props, like so:

iOS, Bluetooth Low Energy (BLE), CoreBluetooth and Swift – for noobs

This talk by Yoav Shwartz on the Realm.io site and this post by Ryan Jones on Medium are the best starting points I have come across.

The official documentation by Apple on CoreBluetooth is in Objective-C, which sucks because Objective-C looks like gibberish to me and i want to write Swift code. You can still read the docs though, they have listed best practices to work with BLE and CoreBluettoth.

You do need to have an iOS device in order to use CoreBlueooth, it is not supported in the Simulator. It was, originally, but they removed it after a year because BLE got more advanced and it was difficult to remove inconsistencies between Mac and iPhone implementations, or sumthin’ like that..

Look at other people’s Swift code dealing with CoreBluetooth on Github.

Install/Upgrade Node.js on Raspberry Pi (Raspbian Jessie)

tl;dr

Run this one command in Terminal:

This will automatically run a script i wrote that takes care of removing existing Node.js stuff, downloading and installing the latest version, and cleaning up afterwards. It also confirms the Node.js version once the installation is done.


The Node.js version that comes pre-installed with Raspbian Jessie is old. If you check the version using node -v, it’ll give you v0.10.29. The latest ARM-version of Node.js as of this writing is v4.2.1. Let’s remove the old and install the latest version available on our Raspberry Pi.

Remove existing Node.js

Run the following commands one by one:

Install latest Node.js ARM-release

Download:

Install:

That’s it, you now have the latest Node.js version available for the Raspberry Pi. You can confirm the version using node -v.

Re-install Node-RED

We uninstalled Node-RED as part of removing Node. If you want to re-install it, you can do so by running the following command:

source

Linux is 20 years old. The web is less than 7000 days old. Together they have changed human civilization more rapidly than any pair of invention in the history of the world.

Eben Moglen