ECMAScript 2015 Destructuring and Spread


Destructuring is a way to unpack values from arrays, or properties from objects, into its own variables.

var o = {p: 42, q: true};
var {p: foo, q: bar} = o;

console.log(foo); // 42
console.log(bar); // true


Spread allows collection to be expanded in places where zero or more arguments are expected (in function), or elements are expected (in array literals), or key-value pairs are expected (in object literals).

function sum(x, y, z) {
  return x + y + z;

const numbers = [1, 2, 3];

// expected output: 6

console.log(sum.apply(null, numbers));
// expected output: 6


NgRx Entity

NgRx Entity

NgRx Entity is a library to handle entity within NgRx framework. The entity in the context is defined as the application’s domain objects, like User, Employee, etc.

The purposes of NgRx Entity are basically:

  • Reduce boilerplate code.
  • Search and sort entities quickly.

The first thing we need to use NgRx Entity is to create an entity adapter, like so:

const adapter = createEntityAdapter();

NgRx Entity also defines `EntityState<>` interface. The interface is also extensible should the additional properties in the application state are needed,

The shape of EntityState is something like this:

interface EntityState {
  ids: string[];
  entities: { [id: string]: V };

What this allows us to do is:

  • Find entity quickly using `entities` dictionary.
  • Maintain order of the list, good for use in sorting.

Some boilerplate codes that are reduced when using NgRx Entity:

  • No need to specify properties of the state interface.
  • Add, remove, update of entities in the state are handled by entity adapter.
  • Entity adapter has most commonly used selectors.


What is Event Sourcing?

Event Sourcing

Every application has a state, representing current snapshot at the moment. Event sourcing is the idea of persisting all of these states as it changes from one to another.

Imagine a workflow for an invoice goes something like: invoice is created which set the status to pending. Pending invoice then gets approved which sets it approved. Approved invoice can be denied or collected. When invoice is denied, it goes back to pending, but when it’s collected, it becomes closed. The state of an invoice is where it’s at a particular time. However, when event sourcing pattern is implemented, we will be able to see a historical timeline of an invoice, from when it’s created to the current state.

What this allows us to do is, we are able to:

  • Complete rebuild: getting rid of the current state and use events to rebuild the invoice to its current state.
  • Temporal query: we can tell what state an invoice is at particular point in time.
  • Event replay: when the past event is incorrect, we can make the change and compute it from the beginning, thus, replaying the whole series of events.

Some applications of event sourcing are:

  • Source control. Every source control uses time series where commits made change the code. By storing events for every commit, we are able to state of the code at particular point in time.
  • Redo / undo. Applications that utilize undo / redo, such as word processor, will benefit from event sourcing pattern.
  • Document history. Word processor application will also benefit from event sourcing by storing event every time changes are made.

I hope this simple explanation of event sourcing helps you to understand what it is and how we can use it. There’s definitely a lot more to it that I don’t cover here, but there are lots of resources online you can learn from.


GAC and GACUTIL in a Nutshell

What’s GAC?

Global Assembly Cache.

What’s in the GAC?

See GAC content:

C:\> gacutil -l
C:\> gacutil /l
or a specific assembly:
C:\> gacutil -l msshrtmi

Or alternatively, look into the following folders:

.NET Framework 4 and newer: %windir%\Microsoft.NET\assembly.
Earlier versions of the .NET Framework: %windir%\assembly.

Accessing GACUTIL

If you have Visual Studio installed, GACUTIL should be accessible in Visual Studio Developer Command Prompt:

C:\Users\JohnDoe\Source> gacutil

Where’s GACUTIL?

If you don’t have Visual Studio, chances are GACUTIL is not recognized in the command prompt. But it doesn’t mean you don’t have it.

Try look in the following folders:

C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\bin
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools

Or any other version available.

GACUTIL comes with Windows SDK. If you still can’t find, download Windows SDK.

Installing New GAC

C:\> gacutil /i MyLibrary.dll

GACUTIL will place the assembly in the GAC directory based on the version of .NET Framework used to compile the assembly.

You don’t need to restart your computer for the installation to take effect.


Global Assembly Cache GAC
View GAC Content

Android Application Lifecycle


A simplified illustration of the Activity lifecycle, expressed as a step pyramid. This shows how, for every callback used to take the activity a step toward the Resumed state at the top, there’s a callback method that takes the activity a step down. The activity can also return to the resumed state from the Paused and Stopped state.

Source: Android Developer

Android Fragment Lifecycle

The lifecycle of a fragment (while its activity is running).

The effect of the activity lifecycle on the fragment lifecycle.

Source: Android Developer

Basic Grunt Commands

Following are some useful commands for Grunt JS, a task runner for JavaScript.

Display Grunt version.

$ grunt --version

Run grunt file (gruntfile.js).

$ grunt

Basic Node JS and NPM Commands

Following are some useful commands for Node.js and NPM.


Display Node.js version.

$ node --version

Run local NPM package. If the package is installed globally, don’t need to use ‘node’ command.

$ node run <npm_package_command>


Display NPM version.

$ npm --version

Interactively create a package.json file.

$ npm init

Install package globally.

$ npm install -g <module(s)>;

Install package locally and save the dependency to package.json.

$ npm install <module(s)> --save-dev

Install package(s) based on package.json file in the current folder.

$ npm install

List global packages with depth = 0.

$ npm ls -g -depth=0

List global packages detail with depth = 0.

$ npm ls -gl -depth=0

List local packages with depth = 0.

$ npm ls -depth=0

List local packages detail with depth = 0.

$ npm ls -l -depth=0

Search the registry for packages matching the search terms.

$ npm search <module>

Update global packages.

$ npm update -g

Update local packages.

$ npm update

Uninstall global package.

$ npm uninstall -g &amp;lt;module(s)&amp;gt;

Uninstall local package.

$ npm uninstall &amp;lt;module(s)&amp;gt;

Run NPM tasks defined in ‘scripts’ section of ‘package.json’ file. ‘start’ and ‘test’ scripts don’t need ‘run’ command.

$ npm run <script_task>
$ npm start

NPM run scripts boilerplate:

Basic Karma Commands

Following are some useful commands for Karma testing framework.

Display Karma version.

$ karma --version

Interactively create a karma config file (karma.conf.js).

$ karma init

Entity Framework Code First Migrations Commands

To enable migrations in your Entity Framework Code First project, the following commands guide you thru installation, enabling the migration, adding a migration and updating the database. All the commands are run on Package Manager Console.

Install EntityFramework package

PM> install-package EntityFramework

Enable Code First Migrations

PM> Enable-Migrations

Add a migration

PM> Add-Migration <migration_name>

Update the database

PM> Update-Database