Sunday, 30 August 2015

VS Code 2015 - Grunt, mocha, mysql, unit test with chai

VS Code 2015 is a simple, no-nonsense editor.

This means that there will be lots of post-coding tasks that need to be performed using some other tools. For instance, automating builds, tests, deployment and execution apart from numerous other tasks like clean, copy, coverage, log, database read/write etc.

Although the task of maintaining all these software development and team activities may look daunting outside of the magical environment of a full fledged IDE like Visual Studio usually is, it is rather simple because of the packages that integrate with Node.js framework.

grunt is one such package that is similar to NAnt and Ant but has one additional advantage - it can perform, continue and wait on tasks asynchronously!

To use grunt, install it with,

> npm install grunt (-watch, contrib-execute etc)

To use mocha, use the same install method with npm.

Mocha is another simple 'describe-it' unit testing tool for testing JavaScript, Backbone and other client side scripting languages, similar to Jasmine.

And 'chai' adds flavor to the unit tests with the expectations and even 'promise'-s of a BDD.

Chai, too, can be installed using the npm tool.

>npm install chai

The story - watch changes to a file.

Simple steps - add the 'watch' task to the GruntFile.js as below:

Run 'grunt watch'

And every time a change is made to the source file that is being watched, the watch target will get triggered as above:

Change made to the the SQL query causes the watch target to get triggered again:

The actual rows in the DB:

and the package.json:

There are the usual caveats that you may need to reckon with like where to install the packages.

Tip: Always check the node-modules folder of your application. It should look like in the below figure:

The unit test using chai and mocha are as simple.

Execute the test using 'mocha' as:

Uncomment the 'done' lines for async callback to work seamlessly without any timeout issues related to the network or when connecting or retrieving data.

Needless to say, the unit tests wired into grunt tasks and coverage ruling the outcome of the tests and the build is ideal and this, too, is simplified now with grunt, node, mocha and blanket. 

Absolutely delightful tools for Agile!

Saturday, 29 August 2015

Visual Studio Code (Code) 2015 - OmniSharp and some tips

The lightweight VS Code has its pitfalls.

For instance, as I made some rapid calculations on the disk space available for VS 2015 Community Edition to download and install (as it says that a minimum of 6 or 4 GB of hard disk space is required across all available drives, I had made a decision - VS Code is what I would use instead.

VS Code requires only 58 MB of space. Not even in our wildest imagination could we ever have thought of downloading a fully functional Visual Studio without having to calculate the internet speed, the disk space and whether any additional service packs and third-party libraries or add-on components had to be additionally installed.

But, as I said at the beginning, VS Code 2015 has its hidden pain areas. It requires node.js and DNX and DNVM (Dot Net Execution and Dot Net Version Manager), though why you required the additional manager is quite a valid question because 'version redirect' and the config changes were doing the same but the new vision to accommodate Mac and make Visual Studio accessible across multiple platforms is possibly the reason.

What this means is that you can switch the 'use' of the current runtime, view or create aliases and manage all the installed versions of the CLR in your machine.

The Execution Engine(DNX)

DNX is the execution environment as Code does not have any executing environment of its own but relies on Node.js or Mono. There is a misconception that I read in one of those 'code...' dot com that ASP.Net 5 now allows you to develop ASP.Net apps using Notepad without having to open Visual Studio - not so. The article probably missed out in mentioning that Roslyn needs to be installed for Ctrl-F5 to work from Notepad.

The hidden problem is because Code is lightweight, it relies on intellisense to be provided as a plugin from OmniSharp

and OmniSharp makes a big deal about being in the same drive as the Node.js installed and this is not documented anywhere! Despite a fix to the omnisharp.cmd file that has been updated in the Git !

To start off, once you have downloaded VS Code, download Yeoman, a scaffolding tool (since Code does not come with templates as in regular Visual Studio versions) to generate complete project related works ! Download the .zip file and extract the downloaded "yo.master".

Next step is to download Node.js, make sure to download the latest version from here. Once downloaded and installed (make sure in the same drive as Yeoman and Code), open a command prompt and type 'npm install -g generator-aspnet'.

This will install the generator that will allow you to use the 'Yo' tool to generate specific projects, for instance,

'yo aspnet'


and you are ready to create your first project with Code.

Select the type of application, give it a name and wait for the project directory etc to be created. Once done, navigate to the newly created folder.

execute the command, as shown in the yo command screen, "dnu restore". 

This will download all nuget packages and set the project.json for the newly created app.

Once done, just type "code ." to open the application !

The new 'References' shows how many references to an object, variable or member exists in code plus a new "Unnecessary using directive" helps.

To run, simply type "dnx . web" to start the server in Windows at the command prompt: 

or navigate to 'hosting.ini' (this file may vary as per the type of application) and click the link to open the web app in your default browser. For Mac, you may need to use "dnx . kestrel".

Any changes to code means restart the server.

and the web site is up at localhost.

Awesome, isn't it? :)

The amazing 'new' VS Code 2015 - a dream !

It - Visual Studio Code - is a new dream for 'old' fashioned devs, who get tired of watching the new gen take a power nap or go for a refill of their water bottle or simply hang their feet (around) while waiting for Visual Studio open, load a solution or check the source control or at times, quite simply hang!

VS Code is totally no-nonsense - no useless, overloaded features that a developer may never use. Instead, you get a feel of using a Notepad!


1. No solution/project.

Either open a file/folder (and if contains a valid VS project, it will open) or use a .json file.

This is it. The ultimate version of the Visual Studio that I have been using for over a decade!

The whole solution and the projects are ready to use in a jiffy and the folder structure is as is. And opening files of other types does not cause a minute lag to open - it is there as soon as you click the file!

2. You can git the file with the changes with just one click.

You have changes to the code? You don't need to to go to the Team Explorer, check the pending changes and spend 10-15 minutes to stage  a one line code change - simply click the 'Stage' button!

3. Commands at your finger tip to modify any editor/environment/package usage.

but you can go overboard with it, if you do not have your senses right ! :D

4. Debug - done with a .json launch configuration file. You will now need node.js if you wish to use VS Code! Debug using the config file or Attach to a port already running the app.

5. Working files - shows the most recently worked files and the unsaved ones!

An absolutely brilliant product !

Thursday, 27 August 2015

The man from U.n.c.l.e - the movie!

It looks to be a new trend in Hollywood movies to have a mind boggling stunt within the first few minutes of the beginning. First, The Expendables (3, that is) then MI-the Rogue Nation, with Cruise on an Airplane (pun intended ? not sure ! :D) and now, this one - The man from U.n.c.l.e.

What a weird acronym, you would say, especially if you have watched Bajrangi Bhaijaan, the Hindi movie (not sure why I had to mention this...I mean, how could an English movie have such a name ?), where the end of the movie has a little girl shouting "UNCLE!!!" for a long time but the Hollywood chappies are smart - they explain what the acronym actually stands for - it starts with 'Universal'...but let me not reveal the suspense by telling you what happens after the movie ends!

This one, though, does not end with a fantastic stunt but takes off with pure, ham-away-actors and with Hugh (whats-his-name ...not Laurie...not Jackman but...granted this is getting condescending...) ah, Grant, pitching in, there is some great stuff for the Maclean-esque thrill (maybe somebody from Hollywood picked up a few hints from my blog (Read my review of San Andreas to make this dense reference clear up any doubts in your mind))

that make action movies a real delight - of course, the usual creeps were there who seemed to have come just to spoil somebody's day at the movies - but then, I could move to anther seat after the intermission as the theater was near empty - but again then, another creep seemed to find it too much and so came specially to sit in the seat behind to make sure that somebody spoiled someone's day at the movies else the world may get hit by an asteroid ! Ah, well!

Why I chose to blog about the movie is that a Bond flick is scheduled to appear in theaters and this one, The man from U.n.c.l.e, seems to have been made so that people are ready for the real James Bond ! The setting, the car chases, the speed boat thrills - what is different though is that it has a gay-like rescue scene, unlike in Bond, where it is usually 'straight' rescues - either the female rescues Bond or Bond rescues females - and unlike in Bond movies, there are only two females, who do not fight each other!

Maybe, this is a 'parallel' Bond-like movie for the 'weird' types, the those who enjoy kinky, non-straight innuendos !

The weird port - '443' and SSL certificates

It is not a joke to have a whole community crapping over how their gem does not get downloaded or installed because of a 'https' issue at the server ! :)

And it is certainly not funny to have some other weirdos quickly pouncing on how Windows 10 installs flawlessly so that anti-Microsoft sentiments could be provoked, on Facebook (not on LinkedIn or in any professional forum) but singularly amiss in reporting their own issue of a port not being allowed access because they want to make money from websites which also make use of the same server ! Does the word 'hypocrisy' come to your mind?

And it is most certainly not funny, when you find the word 'hypocrite' hitting the news in the social media in a totally different context.

Such is how 'mass moronic' mentality is frequently manipulated to propagate moronity that makes no sense when seen in the 'correct' context but due to the 'symbolic' nutcases (the types that go 'it is like saying...' comparison makers) that create 'smoke' with their ignorant shouting of 'unrelated' issues, which is then taken by the 'inexperienced' nutcases as public opinion, interpolation of context happens and gets blown out of proportions for 'mass misrepresentation and misinterpretation'.

Anyway, to get to the SSL issue when installing rails - all you need to do is provide a fresh new certificate file because Rails it seems has its own mind when it comes to certificate issuing authority (CA) so simply obtain a .pem file and put it into your ruby installation folder that has the path -
~ rubygems\ssl_certs folder. To do this, follow these steps:

1. type 'gem which rubygems' in the command prompt to find the path of 'rubygems.rg'

once you obtain the path to the rg,

2. type 'start ... (... is the path to the rg file location)' and put your newly obtained .pem (certificate file) in the location.

Re-start rails and the SSL connection will be successful for Rails to download any new gems from the ruby server!

Another common error could be in the mySql installation - all these issues are specific to Windows and open source softwares not because of any problem with Windows (which could be hugely contested) but because of how the primary framework on Windows, the .Net framework, consumes third-party or open source software

This means that if you already have a .net connector for MySql then using the -d option with 'rails' will cause a problem because the service running MySql somehow 'expects' the old password associated with the connector, even if a new MySql instance has been configured! Best is to uninstall the connector and re-configure MySql before using it with rails.

Another common problem in Windows is that because the 'localhost' is usually configured with the default ip address set to some ASP.Net or Windows Web App Server, 'rails server' may return n ip address for a newly created website.

It becomes useful to know that the --binding option set to the default localhost address will allow the website access.

Ps: On re-check, without running any Windows local web app (which means no app server listening in on any ports), the default localhost IP gets used without the --binding option !

Almost like how Mozilla says "This is embarrassing!" for its own errors as if expecting me to think that I should be embarrassed and Moz is announcing it on my behalf ! :D Seriously !!

Tuesday, 25 August 2015

Dogmas and conventions

Conventions, when misinterpreted or driven by fear, vested interests or agendas as quick fixes, become dogmas celebrated by stereotyp-ism, politico and the disoriented.

Habits, too, get confused with conventions, often. For instance, many in India visit temples out of a habit while the generally stereotyped believe it to be a convention of the religiously inclined devotees.

It is a morning or an evening walk to the temple or a simple activity that conforms to stay in sync with the tradition as believed by the family or friends rather than be on the wrong side.

Next to religion, where dogmas persist as conventions in India, is in jobs.

One such dogma is to persist with the notion that "Quitting a job without a safe offer or Updating it as your status in social media is an act of stupidity that is not professional and it will be used to manipulate" is almost a protocol and is followed as a convention!!

Convention is "Update your status"; taking the updated status as a submission to slavery and therefore, welcoming jackass trading of pay packages is quite simply sheer lack of belief in one's own capabilities of judgement.

Another interesting dogma is an 'article of faith' (to use an expression used in a similar context in LinkedIn) that becomes dormant in practice due to extensive exposure to what is prevalent and popular and a "therefore, must be right" principle that 'attains' the status of a 'belief' due to irrational acceptance of distorted practices, attitudes, techniques and believing them to be conventions.

Conventions are usually that which conforms to universal acceptance, yes, but when followed impractically and based on irrational reliance on others as beacons to propel the self, result in dogmas, with the effect that irrational minds will most likely begin to become the influential agents in future outcomes because dogmas erode common sense.