free html hit counter
Posted on: Tuesday, 10 January 2017 by Rajiv Popat

I’m obviously late to the party but I’ve been hooked on to Visual Studio Code both as an editor and a complete IDE for developing .NET Core Applications and all I can say about Visual Studio Code and .NET core is that I am loving everything I see.

Getting up and running with .NET Console applications is really easy with Visual Studio Code and something I'll probably cover in a different post. This post is focused more around building and debugging ASP.NET Core applications using Visual Studio Code. In the posts to come we will build a simple real life application using .NET core and Visual Studio code.

I recently needed a simple application where I can store excerpts from various books and research papers I read for future reference and so that's the project I'm going to work on for the purposes of these posts. The code that we build during this series will eventually be open sourced and posted on GitHub.

In this post we get started with a simple ASP.NET Core project using Yeoman and the .NET Core CLI and we will then debug it using Visual Studio Code. Why do all this when we can build the same application using Visual Studio 2015? Even though we will build this application in Windows we want the toolset and code to be portable so that we can easily move to Linux or Mac and start developing there whenever we feel the need to do so; which is why we won’t use anything that we cannot use in a Linux or a Mac environment.

In fact, once we get through a couple of posts, we will actually move to a Linux machine and start developing there.

Let’s start by creating an ASP.NET Core app and setting up the debugging using Visual Studio Code. You can of course do this using two ways:

Approach #1: The .Net Core CLI:

This is probably the simplest and provides you with a nice clean ASP.NET Core application. Pretty similar to doing “File / New / Web Application” in Visual Studio if you happen to be a Visual Studio developer in the past. Some folks may love this because it’s straight forward. Others may not like it because it bundles a bunch of things (like the Entity Framework, Membership and stuff you may not even be interested in using). Plus as of now, it doesn’t seem to integrate things like bower out of the box (more on this later).  However, if you are looking to get up and running with a simple ASP.NET Core app up and running quickly you can start a command prompt window, go to the folder you want to create the project in and do:

dotnet new -t Web

This creates a simple Web Application project. To fetch all the dependencies the project needs you would have to do a:

dotnet restore

And to run the project (which also builds it automatically) you would do:

dotnet run

This would start the development web server and host the application which means you can now access it using http://localhost:5000:

And if you open your browser and hit the URL you have the application running:

We’ll come to the debugging part in a minute. Of course if you are not happy with a bunch of extra things that were added to your environment you can of course get more control over the templates that you use for stubbing out your application using Yeoman, which of course brings us to the second way of stubbing out your ASP.NET core applications.

Apporach #2: Yeoman Templates:

You will have to install Yeoman before you begin with this, which of course would mean installing NPM (and the simplest way of doing that is installing Node JS). Yeoman also fetches your Javascript files and files like the bootstrap.css from the right locations using Bower. So you are better off installing bower up front before you proceed.

Once you have Yeoman installed you can do a:

yo aspnet

From your command prompt once you are in the folder where you would like to create the project. Yeoman of course gives you larger control over the project you stub out by letting you pick from a host of templates that you can use (which would in turn decide which dependencies get installed):

In the above sample / screenshot we have an option of picking from different templates. We can pick a basic web application without Membership and Authorization OR just “Web application” which has everything (including membership and authorization pre-configured).  Of course with this I also get to pick between the UI framework that I would like to use for my project:

In the above example I’m going Bootstrap. Once done you would specify the name of the project and once that is done you can go ahead with::

cd research
dotnet restore
dotnet run

In the above command we switched to research folder because yo command creates a folder with your project name. Once you run the code with ‘dotnet run’ You get a similar application this time as you did with .NET CLI only this time around you don’t see the Login link on the top right corner of application:

Now that we have the application up and running (with both .NET CLI / Yeoman, depending on what you pick), let’s get to debugging it using Visual Studio Code.

Debugging Using Visual Studio Code:

The more I use Visual Studio Code the more I seem to like it. It’s light. It’s elegant. Works on multiple platforms and what I love about it is the ecosystem of plugins that turn a lighting fast editor into a full blown IDE! If you don’t have the IDE, grab a copy from here and install it on your machine. Now from the command prompt you can navigate to your project folder and type a “code .” (without the quotes) and you should see your project open. The “.” of course, stands for the current folder and in Visual Studio Code you don’t work with projects / solutions, you open specific folders. Which means if opening the project from command prompt doesn’t make sense to you, you can open Visual Studio Code and Open a Folder from File / Open menu. The moment you open the codebase in Visual Studio Code, it looks for required assets and asks you if it should import those. Click on Yes.

Like I said before, it’s the plugins that turn this code editor into a powerful IDE. I’ve jumped to the plugins tab, searched for and have grabbed the the following plugins I need to get started:

At this time if you were using Yeoman and had bower properly installed Your Launch.json should have the following value correctly set and you should be able to debug your application using debug tab and selecting “.NET Core Launch (Web)” from the debug type drop down and hitting the play button of the familiar F5 key:

If you started with .NET CLI tools (instead of Yeoman), you may not automatically get all bower dependencies configured in your bower.json file like Bootstrap and JQuery. So when you run the project with “dotnet run” it runs fine but when you Debug using Visual Studio Code so see things like Bootstrap and JQuery aren’t properly imported and you see your application looks like this (and the Javascript functions inside the application don’t work either):

This is where is pays to understand how Bower really works and how these templates are generated. The reason why your application runs fine when you execute it using “Dotnet Run” and doesn’t when you execute it using Visual Studio Code is that both (Dotnet Run / Visual Studio Code debugging) execute the applications in different modes. While “DotNet Run” executes the application in production mode, Visual Studio Code runs it in debug / development mode.

If you open your _layout.cshtml file you would notice that the template has generated a layout file that picks up bootstrap, Jquery and other dependencies from “~/lib” folder for Development environment and directly from ASP Net live CDN in case of production and staging environments. Since we are running in Development environment when debugging from Visual Studio Code we need the dependencies to be present in the “~/lib” folder.

If you check the wwwroot folder however you’ll see that the lib folder is missing:

To get the dependencies in the right folder we’ll use Bower to download the dependencies in the right folder. Where bower downloads the dependencies is defined in “.bowerrc” file:

And as the above picture shows our .bowerrc file does have the right location. We also have the bower plugin installed. So Let’s hit CTRL + P and Type “> Bower” in the search bar  that pops up:

Now you get a list of bower commands from which you can select Bower Install and hit enter:

The moment you do bower should grab all required dependencies for you and you should now see a new lib folder with the right dependencies:

And you are also able to debug the application properly now with Bootstrap, Javascript and other dependencies working fine:

Personally, I like Yeoman primarily because it provides a larger choice of templates and runs the “bower install” command pretty much automatically (assuming you have bower installed) but both .NET Core CLI and Yeoman should help you get started quickly with your first ASP.NET Core application. Both work across platforms and which one (Dotnet CLI / Yeoman) you use is just a matter of which templates you prefer.

As far a Visual Studio Code is concerned I love it. While Visual Studio 2015 Professional versions manage some of these tasks out of the box, Visual Studio Code is really nice because for me it hits the fine spot between showing me what’s happening under the hood at the same time keeping me sufficiently productive. This post covers two ways of getting up and running with an ASP.NET core project and you can use either of the two and all it takes us is a minute to get started with the setup and debugging on a new ASP.NET core project using Visual Studio Code.

In the next post we’ll get started with the actual application using ASP.NET Core where we will be creating a simple application where you can store experts from various books and research papers that you might be reading for future reference. As the series of posts proceeds I’ll dump the code on GitHub and also try and host it using the cheapest most scalable cloud options.

posted on Tuesday, 10 January 2017 13:52:02 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Saturday, 07 January 2017 by Rajiv Popat

Lately, there is a fad that’s been going around about the whole idea of ‘work life balance’.

Anyone you talk to claims that they are overworked and are finding it difficult to strike a ‘work life balance’.

But a question really worth reflecting on is, are we really overworked? Or are we becoming downright lazy (not because we don’t love hard work but) because we are unable to find any creative outlets in the work that we do?

There is this myth of folks working 80 / 90 hour work weeks and feeling the urge to strike a healthy work-life-balance. Laura Vanderkam decided to question the validity of the claims of people who say they are working 80-hour work-weeks and came out with some striking revelations in her book, 168 Hours - You have More Time Than You Think. For her book, Laura reached out to University of Maryland sociologist John Robinson about his research on the reality of work hours and the figures she found were astounding:

University of Maryland sociologist John Robinson and his colleagues analyzed people’s estimates of how much they worked, and compared those to the time diaries, they found that the more hours people claimed to work, the more inaccurate they were. You can guess in which direction.

Almost no one who claimed a 70-hour workweek was underestimating. Indeed, the average person who claimed to work more than 75 hours per week generally logged about 55. When I contacted Robinson recently, he sent me a working paper he was drafting using more recent numbers, from 2006-2007. The time spent working had come up a little for people whose estimated hours showed workaholic tendencies, but even so, the average person who claimed to be working 60-69 hours per week was actually logging 52.6, and the average person claiming to work 70, 80, 90, or more hours was logging less than 60.

Laura’s hypothesis is that people overestimate their workweeks. After all, we tend to overestimate the time we spend in things we don’t enjoy and underestimate the time we spend in things we love doing. Which is why most people underestimate their television watching time and overestimate their workweeks. Remember how, in your childhood, your study time never used to end but the study breaks used to run out in no time? It’s the same concept of relative speed of time when it comes to most people feeling that they are overworked. Bottom line, we aren’t spending 80-hour workweeks. We just feel we are spending 80 hour workweeks because we don’t love our work as much as we love watching television. And we don’t connect to the work that we do either. No amount of work life balance can fix that.

While Laura’s writing style is professional, this article is a bit more unforgiving and hits the hammer right on the nail:

Are you feeling drained and listless at work? One of the biggest reasons we find ourselves frustrated from our jobs is because we don’t have an outlet for things that are important to us but we need to keep at it because of bills and general adult responsibilities.

Us millennials have two major problems hanging over us: crushing debt and the desire (with no outlet) to do something meaningful. Some of us went to college with the hopes of a guaranteed job when we graduated. It’s now a hilarious thought on hindsight.

Unless you graduated with a degree in one of the STEM disciplines, you probably didn’t land your ideal job right out of college. And that’s likely the reason why you’re stuck in a job you feel has no real purpose, and why your student debt is still hanging over your head.

If you feel Laura’s claim and the article above isn’t scientific enough, Dan Ariely, Emir Kamenic and Drazen Prelec have a scientific paper where they try to decipher man’s search for meaning using Lego pieces. In this social experiment they paid college students money for making Lego Bionicles. There were two conditions in the experiment, the meaningful condition, where the Bionicles built by students would be kept on a table while they made new ones and the meaningless condition (i.e. the Sisyphus condition) where the experimenter would dismantle the Bionicles in front of the student, making it very clear to the students that their work served no purpose, before giving them new Lego pieces. Here is how the paper describes the two conditions:

In the Meaningful condition, after the subject would build each Bionicle, he would place it on the desk in front of him, and the experimenter would give him a new box with new Bionicle pieces. Hence, as the session progressed, the completed Bionicles would accumulate on the desk.

In the Sisyphus condition, there were only two boxes. After the subject completed the first Bionicle and began working on the second, the experimenter would disassemble the first Bionicle into pieces and place the pieces back into the box. Hence, the Bionicles could not accumulate; after the second Bionicle, the subject was always rebuilding previously assembled pieces that had been taken apart by the experimenter. This was the only difference between the two conditions.8 Furthermore, all the Bionicles were identical, so the Meaningful condition did not provide more variety than the Sisyphus one.

The results of the test are astounding. Here is what they found:

Despite the fact that the physical task requirements and the wage schedule were identical in the two conditions, the subjects in the Meaningful condition built significantly more Bionicles than those in the Sisyphus condition. In the Meaningful condition, subjects built an average of 10.6 Bionicles and received an average of $14.40, while those in the Sisyphus condition built an average of 7.2 Bionicles and earned an average of $11.52.

The Wilcoxon rank-order test reveals that the reservation wage was significantly greater in the Sisyphus than in the Meaningful condition (exact one-sided p-value = 0.005). The median subject in the Sisyphus condition stopped working at $1.40, while the median subject in the Meaningful condition stopped at $1.01. Hence, the difference is a visible count in both conditions economically as well as statistically significant, as the Sisyphus manipulation increased the median reservation wage by about 40 percent.

Put simply, remove meaning out of a person’s work and they will work less even at a 40% higher payout. Not to mention the fact that the person would end up being much less productive, feel tired much quicker, would burn out and would give up much faster.

So the next time you get this urge to establish a stronger work life balance and you feel that we are overworked, it might be a good idea to sit down and reflect on if you are really doing 80 hour work weeks or are you just overestimating how overworked we are? Are you in a job that makes you excited or do you need to find additional work that we love doing on the side? Are you relying on your jobs to provide you meaning when your organization expects you to be toiling like Sisyphus?

There was a time in my life when I would have said that you can find meaning outside your work life – for example – working on open source projects, participating in community efforts, contributing in online discussions, but as I grow I am starting to realize that 8 hours a day (and 40 hours a week) of prime productive time, is considerable enough for you to start looking for ways to change your organization (or change your organization); particularly if your work isn’t providing you sufficient excitement, challenge, flow and meaning.

Of course, till the time you can change (or change) your organization meaningful work outside your paid job can provide the much needed boost to keep your creative sprits alive.

Either ways, if you feel you are overworked, constantly tired and don’t like the idea of waking up in the morning to go to work, it’s time to stop blaming yourself and take a long hard look at the work you are doing and ask yourself one basic question – are you enjoying yourself? And if the answer is no, what are you actively doing to change that?

posted on Saturday, 07 January 2017 18:58:11 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Tuesday, 27 December 2016 by Rajiv Popat

This happened to all of us way back in our school days. The teachers would label the hard working, high scoring, intelligent students from the ones who were ruckus creators; and then they would treat those two groups differently.

You knew the ruckus creator back in nursery, the guy usually remained a ruckus creator all the way through high school while the hard working scholar, would top almost every class growing up. Information about who was a star student and who was a ruckus creator flowed from teacher to teacher as you moved from one class to another. If you were the ruckus creator who wanted to genuinely change you were screwed and you virtually couldn’t!

“Is he good?”---  that’s a question often discussed between managers when onboarding a person on a project. The idea and the central premise being, if the guy has worked with a different manager in the past and you happen to know the person he worked under, why not take a quick input from that manager before onboarding the person on your project?

Adam M. Grant, shatters this myth and methodology of ‘searching for star performers’ in his book ‘Give and Take’ where he takes the relationship between ‘performance’ and ‘reputation through word of mouth’ and turns the causation between these two upside down. He explains:

Harvard psychologist Robert Rosenthal, who teamed up with Lenore Jacobson, the principal of an elementary school in San Francisco. In eighteen different classrooms, students from kindergarten through fifth grade took a Harvard cognitive ability test.

The test objectively measured students' verbal and reasoning skills, which are known to be critical to learning and problem solving. Rosenthal and Jacobson shared the test results with the teachers: approximately 20 percent of the students had shown the potential for intellectual blooming, or spurting. Although they might not look different today, their test results suggested that these bloomers would show "unusual intellectual gains" over the course of the school year.

The Harvard test was discerning: when the students took the cognitive ability test a year later, the bloomers improved more than the rest of the students. The bloomers gained an average of twelve IQ points, compared with average gains of only eight points for their classmates. The bloomers outgained their peers by roughly fifteen IQ points in first grade and ten IQ points in second grade.

Two years later, the bloomers were still outgaining their classmates. The intelligence test was successful in identifying high-potential students: the bloomers got smarter—and at a faster rate—than their classmates.

Based on these results, intelligence seems like a strong contender as the key differentiating factor for the high-potential students.

But the Harvard cognitive ability test, was not a way to identify students who were going to be bloomers in the coming years! It was nothing more than a trick experiment designed by the psychologist to prove his hypothesis. Adam explains:

The students labeled as bloomers didn’t actually score higher on the Harvard intelligence test. Rosenthal chose them at random.

The study was designed to find out what happened to students when teachers believed they had high potential. Rosenthal randomly selected 20 percent of the students in each classroom to be labeled as bloomers, and the other 80 percent were a control group. The bloomers weren’t any smarter than their peers. The difference “was in the mind of the teacher.”

Yet the bloomers became smarter than their peers, in both verbal and reasoning ability. Some students who were randomly labeled as bloomers achieved more than 50 percent intelligence gains in a single year. The ability advantage to the bloomers held up when the students had their intelligence tested at the end of the year by separate examiners who weren’t aware that the experiment had occurred, let alone which students were identified as bloomers. And the students labeled as bloomers continued to show gains after two years, even when they were being taught by entirely different teachers who didn’t know which students had been labeled as bloomers. Why?

Teachers’ beliefs created self-fulfilling prophecies. When teachers believed their students were bloomers, they set high expectations for their success. As a result, the teachers engaged in more supportive behaviors that boosted the students’ confidence and enhanced their learning and development. Teachers communicated more warmly to the bloomers, gave them more challenging assignments, called on them more often, and provided them with more feedback.

In the book, Adam describes how the same experiment was repeated again and again, in fields like sports, workplace and even the armed forces and how the same results stood true each time.

As a person who manages teams of capable developers, I have always intuitively believed in the idea of self-fulfilling prophecies, but seeing a quantification of how strong our biases and influences are and how they end up effecting the people who work with us, is a little… scary, to say the least.

So, the next time you ask another manager about the efficiency and capability of an individual that you are onboarding without even evaluating the person on his / her own merit, be aware that you might be unknowingly setting up the stage to create and then support a self-fulfilling prophecy.

What’s even more scary is the idea that a lot of new budding managers find it hard to delegate work to their team members because they believe the team members would not be able to do those tasks as well as they do the tasks themselves. Put simply, these managers start out with the assumption that their team is not as effective or productive as they themselves are. When you put that in perspective with the idea of self-fulfilling prophecies and the real power these prophecies have, where does this leave you as a manager? Where does this leave your team? Just a little something to think about.

posted on Tuesday, 27 December 2016 13:19:17 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Tuesday, 22 November 2016 by Rajiv Popat

Productivity as a topic has been very near and dear to my heart. Unlike most people my obsession with productivity tools, tips and techniques doesn’t revolve around the fact that my productivity allows me to squeeze a couple of hours worth of extra work into my regular workday. For me productivity is a way of life, and a way of doing more of what you want to do (or what you were meant to do) and less of what others want you to do.

Chris Bailey, as an author caught my attention because he had the courage and conviction to take an entire year off from his prime years and study productivity. The Productivity Project chronicles his learnings in that one year. The book is filled with experiments (some scientific, but most others self-applied) where  the author makes himself a guinea pig and tries out some sane and some insane productivity tips and tricks.

The book begins with practical advice and claims to be able to take you from here:


To here:


<stupid_grin>The book was a validation that I’m not the only one who is crazy enough to try and measure every single waking hour of their life! Other, sane authors have done it too. </stupid_grin>.

Where the book started grabbing my attention was the moment Chris laid out his definition of being productive. Chris describes productivity using a simple idea of living with deliberateness and intention. He explains:

I think the best way to measure productivity is to ask yourself a very simple question at the end of every day: Did I get done what I intended to? When you accomplish what you intend to, and you’re realistic and deliberate about the productivity goals you set, in my opinion you are productive.

If at the beginning of the day you intend to write a thousand great words, and you do, you were productive.

If you intend to finish a report at work, ace a job interview, and spend quality time with your family, and you do, again, you are perfectly productive.

If you intend to relax for a day, and you have the most relaxing day you’ve had all year, you were perfectly productive.

An idea the likes of David Allen have been trying to propagate for years. The book is also full of real world practical advice ranging from simple advice like Emptying your brain, using the Pomodoro, the importance of exercise, the importance of food and the perils of Attention Hijackers like mindless surfing, but the real power of the book lies in how simplistically Chris describes some of the complex things that end up affecting your productivity. Take for instance this passage on how Sugar effects your productivity:

On a neurological level, you have mental energy when you have glucose in your brain. When you feel tired or fatigued, more often than not it’s either because your brain has too much or not enough glucose to convert into mental energy. Research has shown that the optimal amount of glucose to have in your bloodstream is around 25 grams—about the amount of glucose in a banana. This exact number isn’t all that important, but what is important is that your glucose levels can be either too high or too low.

Since unprocessed foods (in general) take longer to digest, your body converts them into glucose at a slower rate, which provides you with a steady drip of glucose (and energy) over the day—instead of a big hit of energy followed by a crash. In a way, processed foods are predigested for you by machines. This is why your body converts them into glucose so fast, and why a donut doesn’t provide you with nearly as much lasting energy as an apple.

We all know processed foods harm and effect our productivity and health, but simple explanations like these go a long way in understanding what foods to pick and provide the much needed nudge to make the right decisions. The book is also filled with surprising and mind-blowing passages which are fascinating (and somewhat philosophical) to read. Take for instance this passage on the history of time itself:

If you were around before the industrial revolution ended in the early 1800s, you wouldn’t have measured time down to the minute, not only because you didn’t have the technology to do so, but also because you didn’t need to. Before the industrial revolution, measuring time wasn’t as important, and most of us worked on the farm, where we had way fewer deadlines, meetings, and events to sequence than we have today. In fact, until the first mass-market, machine-made watches were produced in the 1850s, timepieces were unobtainable by pretty much anyone except for the super rich, and most of us charted the day’s progression by looking at the sun. Because we didn’t measure time with a clock, we would speak about events relative to other events. In the Malay language, there is even the phrase pisan zapra, which roughly translates to "about the time it takes to eat a banana."

The book of goes on to describe how in merely about 150 years, we went from not caring about time to having a huge industry and pretty much most of our lives run around set timings. The book covers productivity from more aspects than any other productivity book I’ve read thus far does. Even for an avid reader of books on topics like time management, neuroscience and psychology, a lot of the concepts the book explains (e.g. removing triggers to change your habits, exercising your focus mussel etc.) are not new at all but they are explained with a unique personal insight that I enjoyed thoroughly.

After David Allen’s GTD, if you have room for one more book on productivity, this is the book you should definitely pick up. I would give it a 5 on 5!

posted on Tuesday, 22 November 2016 14:13:56 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Tuesday, 01 November 2016 by Rajiv Popat

If you’re interested in and working with Javascript frameworks, you’ve probably heard of Aurelia by now. It’s a compelling competitor to frameworks like Angular and React.  While getting started with Aurelia itself seems pretty straight forward, getting Aurelia working with Type-Script and making it all work Visual Studio 2015 has it’s own share of hiccups.

The aurelia team provides starter projects that they call skeletons that you can download and get up and running really quickly. However when I tried using them, the skeletons seemed to have issues which were both time-consuming and frustrating to resolve. Even the skeleton that was supposed to run with .NET MVC (and had a “.sln” solution file) would not even compile without errors. And these skeletons come with a lot more than what you would like have when you are just trying to get an initial hold of Aurelia and type-script. This left me with no other options but to star fresh and create my own basic skeleton where I can try out different Aurelia features.

If you’ve tried to get started with Aurelia + Typescript and you are a .NET programmer who lives inside Visual Studio, the goal of this post is to get you up and running with Aurelia and Typescript inside Visual Studio 2015.

To being with you’re going to need Typescript working inside your Visual Studio 2015. The simplest way I’ve found to do this is, just un-install older versions of Visual Studio 2015 and install Visual Studio 2015 Update 3 from scratch. You could use that link, but then if you have an MSDN subscription you are better of downloading an offline ISO from there and using that, which is what I did.  Initially, I tried in place update of Visual Studio 2015, and the installer kept crashing for some reason (this of-course could be because of the fact that I was on a weak Wi-Fi).  The MSDN ISO (a 7 GB download) worked smoothly after an uninstall of my existing visual studio; followed by a fresh install.

With Visual Studio 2015 Update 3 (with Core 1) loaded, you’re also going to need Typescript support inside Visual Studio so your Typescript files are compiled and converted to JS files each time you save them. To do that you can grab the Visual Studio Typescript plugin from here and install that. You will also need Node Package Manager (NPM) working on your machine and the simplest way to do that is download and get  Node JS installed on your machine.

With that done we’re ready to start our first hello world project with Typescript + Aurelia.

As I said before, the easiest way to do this would have been to download and use the skeletons, but given that the skeleton’s provided by Aurelia team didn’t work for me;  I was left with no option but to build my Aurelia app from hand and get started. Honestly, building your first app by hand actually works out better because it gets you a fresh new insight into many underlying concepts that you will typically not have to pickup if you use a ready made skeleton instead.

Since we’re going to be working with Visual Studio 2015 as our IDE of choice, let’s go and create a blank ASP.NET Web Development project inside Visual Studio in a folder of your choice. Open the solution file and keep the solution open in Visual Studio as you proceed with the below.

Once the project is created start command prompt and go to the specific location where you created the project. Note: go inside the project folder (not the folder with contains the .sln file – but the one that has your web.config file.):

Once there start by typing in the following commands:

npm install jspm
jspm init

JSPM is the JavaScript Package Manager which let’s you fetch and use various  Javascript modules you will need to get started with Aurelia. In the above diagram we switch to the project folder (shown in the screenshot + code snippet),  do a NPM install of JSPM which fetches JSPM on your machine. Once there we initialize jspm in our project folder (jspm init) where it will create new project asking you basic questions:

We select the default answer by just hitting enter, except for picking the Transpiler, where we will use TypeScript instead of the default Transpiler JSPM uses (babel).

Once that is done we continue with rest of the defaults and finish our “jspm init”.  We then install the required underlying frameworks in our project by doing:

jspm install aurelia-framework aurelia-bootstrapper bootstrap

This should pull all files pertaining to Aurelia framework, the aurelia bootstrapper and the bootstrap framework (which are the very basic things we need to start a simple web application with Aurelia and Typescript). If all goes well your folder structure should look like this inside Visual Studio with “Show All Files” selected in Solution Explorer:

We now need to start writing code for our project. The first thing we do is right click the config.js file in the solution explorer and say “Include in Project”.

Once done we open the file and add the highlighted line :

This tells the Transpiler to look for code in the “src” folder. Of course we don’t have that folder in our solution so we create that by right click solution explorer and clicking create folder and adding the src folder. Now we have a place where we will write our Aurelia code. But any web-server that we will also use to host the code will need a startup file to begin running the application – which usually is index.html. So let’s code the following index.html by hand:

<!DOCTYPE html>
  <body aurelia-app>
    <script src="jspm_packages/system.js"></script>
    <script src="config.js"></script>

This is a simple standard index.html file most Aurelia applications will typically need. We are adding two JS files that aurelia needs. The first is system.js and the second is where our configuration is stored (config.js). We then use System.import (from system.js) to import the aurelia-bootstrapper.

Also note the “aurelia-app” tag in body. A few important pieces are getting connected in the above code and aurelia is using convention to connect the pieces. The index.html tells aurelia to use the config.js file. And as we’ve seen before, the line we added in config.js tells aurelia that the custom aurelia code would be in the “src” folder. The “aurelia-app” tells aurelia to be default look for “app.js” as an entry point. Note: we haven’t specified app.js – but the aureila-app tag itself (by convention) tells aurelia to use app.js by default. You can of-course override the convention but that’s for another post. Right now, let’s just create a app.js in the source folder.

We could drop an app.js file inside source, but remember we are planning on using TypeScript throughout the project, so instead of an app.js, we will use “app.ts”. We will work on the typescript file (app.ts) and let Visual Studio to generate the .js fie each time we save the “.ts” file. So let’s right click “src” folder and add a Typescript file and call it “app.ts”.  Because typescript provides added intelligence and compile time validations, it needs what we call typing files which allow visual studio to validate your TS code. Which is why Visual Studio will ask you this:

Going ahead we will grab out typing files manually so say no to the above for now and let’s proceed. We’re going to talk more about typings later in this post.

In your blank app.ts add the following lines:

export class App
    Message: string;
        this.Message = 'Hello World';

Note in the above code, we have a simple type-script class (this will translate to a JS function) and string Variable called Message. In the constructor we add a default value to the field. This app.ts, will get translated to app.js when we save it and will act as a view-model. Now that we have a “View Model” let’s go ahead and make a View. Aurelia view are simple HTML pages surrounded by a template tag. So inside “src” folder let’s add a new app.html and add the following lines:

    Message received from View-Model: ${Message}

The Message that we set in the View-Model should now flow to the view and when you compile and run the project at it’s root, you should now see:

Congratulations! You have your first Aurelia project with TypeScript running now. Now let’s do something more meaningful and try to create a screen to add customers to a List of Customers. To do that let’s start by making a Customer class by adding a “Customer.ts”. For now let’s modify the blank Customer Class so that it has a CustomerName attribute and looks like this:

export class Customer
    CustomerName: string;
    public constructor()

We will now need to go ahead and use the Customer inside app.ts and then create a function inside app.js that allows us to create a customer to the list of customers. To do that we modify our app.ts:

import { Customer } from './Customer';
export class App
    CurrentCustomer: Customer;
    Customers = new Array<Customer>();

        if (this.CurrentCustomer)
            this.CurrentCustomer = new Customer();

In the above code we use Import to import the Customer class into our App class so that we can use it in our code. Then we create an array of Customers (which will hold a list of customers) and a specific Customer (which the user will add using the UI). The “addCustomer” method adds the current customer to the list. To put sense into all of this let’s create a UI front end which has a textbox, and button called “Add Customer” which adds the customer whose name you type in the textbox to a List of customers which is re-presented by a “UL”. The final view (index.html) looks like this:

    <form submit.trigger="addCustomer()">
        <input type="text" value.bind="CurrentCustomer.CustomerName" />
        <button type="submit">
            Add Customer
            <li repeat.for="Customer of Customers">

Notice that in the code above I have a form whose submit triggers the addCustomer method which we write in our View-Model. There is a textbox which we “bind” to the CustomerName of the Current Customer, which again is defined in our view model. We have a simple submit button and a UL where the LI’s repeat for every Customer in the “Customers” array which is defined in our ViewModel. The UI looks like this:

As we type the name of the customer and click the add button the customers get added to the list:

And we can do this with multiple customers:

The binding of the textbox with the CurrentCustomer.CustomerName ensures that the value passes from the view to the view-model. Each Time addCustomer is called, we create a new Customer object and hence the textbox blanks out after the existing customer is added to “Customers” array which is bound to the UL using a “repeat.for” loop.

So far so good. Everything we’ve done thus far, compiles, builds and runs.

However as you start going into deeper Aurelia, you will realize that you will need to use more complex concepts like Dependency injection (where you would like to inject services into your view-models). The start project we have created works but isn’t fully ready to handle imports because we have the typing files missing. Remember we said we’ll discuss typings later in this post? This is the part where we now need to address typings to move ahead.

To virtually use any advanced feature in aurelia you will have to import the aurelia framework in your code. For example if you want to use the dependency injection of aurelia, your code to do so would look like this:

import { inject } from 'aurelia-framework';

Put that code in your app.ts and you’ll immediately realize that visual studio starts complaining:

And this is because Visual Studio knows nothing about the Aurelia-framework even though we had done a “jspm install aurelia-framework” right when we started. We had done the install with the command prompt using jspm but visual studio (and typescript) still require typing files for aurelia framework before they let you import specific components of the framework inside your TS files.  The simplest way to grab Typing files is to add a “typings.json” file in your project root and add the following lines to it:

  "name": "AureliaHelloWorld",
  "dependencies": {
    "aurelia-binding": "github:aurelia/binding",
    "aurelia-bootstrapper": "github:aurelia/bootstrapper",
    "aurelia-dependency-injection": "github:aurelia/dependency-injection",
    "aurelia-event-aggregator": "github:aurelia/event-aggregator",
    "aurelia-fetch-client": "github:aurelia/fetch-client",
    "aurelia-framework": "github:aurelia/framework",
    "aurelia-history": "github:aurelia/history",
    "aurelia-history-browser": "github:aurelia/history-browser",
    "aurelia-loader": "github:aurelia/loader",
    "aurelia-logging": "github:aurelia/logging",
    "aurelia-logging-console": "github:aurelia/logging-console",
    "aurelia-metadata": "github:aurelia/metadata",
    "aurelia-pal": "github:aurelia/pal",
    "aurelia-pal-browser": "github:aurelia/pal-browser",
    "aurelia-path": "github:aurelia/path",
    "aurelia-polyfills": "github:aurelia/polyfills",
    "aurelia-route-recognizer": "github:aurelia/route-recognizer",
    "aurelia-router": "github:aurelia/router",
    "aurelia-task-queue": "github:aurelia/task-queue",
    "aurelia-templating": "github:aurelia/templating",
    "aurelia-templating-binding": "github:aurelia/templating-binding",
    "aurelia-templating-resources": "github:aurelia/templating-resources",
    "aurelia-templating-router": "github:aurelia/templating-router"
  "globalDevDependencies": {
    "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
    "aurelia-protractor": "github:aurelia/typings/dist/aurelia-protractor.d.ts",
    "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
    "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
  "globalDependencies": {
    "whatwg-fetch": "registry:dt/whatwg-fetch#0.0.0+20160524142046"

This will provide details of practically all aurelia typing files we are going to need for now and future. Once you have created this file and saved it go to command prompt, navigate to the folder that has the typings.json file (i.e. same folder as the one which holds your web.config) and type:

npm install typings –g

This will install the typings module globally. Now to grab relevant typing files based on your typings.json type:

typings install

Now we’ve fetched typing files but Visual Studio is still blissfully unaware about the fact that we’ve pulled the typings. You should also see the “typings” folder in your source explorer. However To make Visual Studio aware of the typings, we will need to add a typing definition file inside our source folder – the one which our Transpiler is watching. We can call this file anything as long as it has a “d.ts” extension but for now we’ll call “main.d.ts” and will place it inside the src folder. If you notice inside the typings folder you realize that is already has a typing definition file called “index.d.ts” – and it references all the necessary aurelia files;  so if our “main.d.ts” just references that file we should be done. Let’s go to our newly created blank “main.d.ts” (inside the src folder) and add this line:

/// <reference path="../typings/index.d.ts" />

With this done we now have the typings referenced properly and visual studio should stop throwing “cannot find module ‘aurelia-framework’.” error and that specific error should get fixed. However now when you fire a build you should see dozens of these two errors:

Build:Cannot find name 'Promise'.
Build:Cannot find name 'Map'.

This is because Aurelia typings internally use promise and collections. To fix this error we can use the Nuget package manager inside visual studio and install Typescript definition for ES6 promise and collections. The command to do that (inside Visual Studio Nu-get package manager) is:

Install-Package es6-promise.TypeScript.DefinitelyTyped

Install-Package es6-collections.TypeScript.DefinitelyTyped

Once you do that and once typings for promise and collections are installed your build should compile successfully. However, if you start using advanced features like dependency injection you will encounter some more build errors. For example, let’s modify your “app.ts” to use dependency injection:

import { Customer } from './Customer';
import { inject } from 'aurelia-framework';

export class App
    CurrentCustomer: Customer;
    Customers = new Array<Customer>();

        if (this.CurrentCustomer)
            this.CurrentCustomer = new Customer();

Notice the lines in bold which are using out of the box dependency injection of aurelia. In other words, aurelia automatically creates an object of Customer class and pushes it in the constructor. However the moment you actually do this and hit a build you should see compilation error:

Build:Experimental support for decorators is a feature that is subject
to change in a future release.

Set the 'experimentalDecorators' option to remove this warning.

To Overcome this error you will need add a new tsconfig.json in your project root and add the following lines to it:

  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "experimentalDecorators": true
  "exclude": [


The experimentalDecorators value of true ensures decorators like inject are allowed. Exclude on node_modules and jspm_packages ensures that the typescript compiler excludes those when it fires a build. Fire a build now and your build should fire successfully.  Run your code and it should just as before because we aren’t doing anything in particular with dependency injection here. In fact it’s actually a bad example of dependency injection but I included it in this post because the post covers the setup of a starter project that let’s you try out and learn everything that aurelia has to offer while using it with Typescript, inside Visual Studio 2015, so adding a right “tsconfig.json” and getting the typings upfront is a good idea (even if you are not using dependency injection or other advanced aurelia concepts).

I honestly believe that while the aurelia team is doing an amazing job documentation and videos of aurelia itself, but mixing aurelia with type-script and getting it all to run on visual studio 2015 can turn out to be a bit daunting for someone who is starting out his aurelia + typescript journey because there is no single place to get started. It would be really nice to not have to go through so many steps to just set up a basic development project where you can try out and learn features aurelia (with Typescript) has to offer, while working inside visual studio.

I know you can create projects using Aurelia CLI tools but even those had the similar typings related issues that I highlighted in this post. And getting those to work was an equally daunting task. Now that I have been working in aurelia for a few days, I can take a skeleton and make that work too, but as far as I am concerned, the learning curve to get into aurelia itself has been much lower than the learning curve required to get into aurelia with typescript and get it all to work inside visual studio. All I can do is hope that the Aurelia team builds some more documentation around getting started with Aurelia + Typescript. In the meantime, this post you get you on your way.

posted on Tuesday, 01 November 2016 16:03:18 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Sunday, 23 October 2016 by Rajiv Popat

In 2016 I took up the 52 book challenge as a Marathon for my mind. My idea was to read a book a week and write about my progress on this blog. 2016 has been one busy year and I may not have been able to live up to my original expectations but I’ve been lucky enough to have taken time out during my commutes and weekends to sit and enjoy the company of a book every now and then.

I’ve written a review on seven of the books that I’ve read and really like this year but obviously I’ve been reading more. Here is a comprehensive list of all books I’ve finished cover to cover this year (The First Seven are in older posts, which is why this list starts from 8):


  1. The Practicing Mind: An averagely good book that talks about the power and benefits of focused practice. What I liked about the book was it’s basic message but the book lacks story telling and also lacks sufficient science leaving it in the murky territory of a typical self help book. Not that there is anything wrong with typical self help books, but not something I enjoy reading. I’d give it a 3 / 5.
  2. You are your own gym: Bodyweight training was how I started my fitness journey. As a nerd, any book that is focused on body weight training attracts me even today. There is something liberating about not having to depend on gyms, weights and machines to remain healthy. Being able to workout in a hotel room when you are travelling and not using travel as a reason to skip your workout is very empowering too. Written by an author who has trained special forces to be healthier and functional on field, the book has not just workouts but ideas and concepts every person who is into healthy life-style should read and understand. More than just a book, it’s a program that also has an accompanying app that you can download free and then buy if you like. I’d give this program (book + app) a 4 / 5 but don’t expect it to give you any magical gains, unless you have the consistency to stick to the program.
  3. The Tao of Pooh: I’ve always wanted to read philosophy outside the Indian and western philosophies and if there is one book that does an amazing job of introducing you to Taoism it is this book. It’s funny, it’s witty and it’s deep. One of the few books that prove that your writing doesn’t have to be complex to be deeply philosophical. And of course, who can not love Pooh? :) – A 4/5!
  4. Go for No – This is one of the few books this year that did not impress me. The central premise is fine – As a sales person, if you aim for yes’es in your sales call you are at an disadvantage. Every no you hear puts you down and demotivates you. But if you ‘Go for No’ and start your day by aiming for X number of NO’s every day, then you are motivated to keep calling even when you hear a no, because you are moving ahead towards your goal of X no’s. Every yes is a pleasant surprise and pushes you even harder. There are pages and pages of weird time travel based fiction where the protagonist falls on a golf course, hurts himself in the head, time travels and meets his own future self who teaches him the lesson of going for no’s. The book is a little too strange for my taste and what put me off about the book is that the only teacher the protagonist finds even in his own fictional world, is his very own hypothetical future self. The central premise is good but what could have been conveyed in one paragraph or a small readable blog post was stretched to an agonizingly long book with meaningless fluff and crazy fiction which was completely not required (and maybe even detrimental) for spreading the actual message. A 2/5.
  5. Naked Statistics: I haven’t read a book on Math since I finished my college and when I stumbled into this one, I saw it as a good opportunity to brush up on a subject that I never fully grasped in school. The book just blew me away in the way it describes some of the concepts of statistics that I studied in school but never really understood. From the difference between mean, median and mode, to topics like co-relation, the book covers each topic from a real life practical standpoint. It then touches the math side of each topic where the author takes very real simple examples to explain the complexities. The goal is to develop an intuitive understanding of some of the most used mathematical and statistical concepts and the book does indeed do an amazing job at it. A 4/5.
  6. Deep Work: Cal Newport as an author gained my attention with his book ‘So Good They Can’t Ignore You’ where he argued that passion is overrated. In this book he talks about the power and the importance of focused deep work in any creative person’s life. The book cites real examples of folks who go really far to cut themselves off distractions. The book is inspirational and the writing style is pretty good but there are not a lot of real unique ideas in this book that stick with you for life. A fascinating read though to understand how fragmented and distracted our lives today have really become. I’d give it a 4 / 5.
  7. Nudge: Written in the same tone of Switch(which I reviewed earlier) the book covers the topic of choice architecture in much more theory with many more examples. Though a lot of material in this book is very similar to  Switch, it covers a vast variety of topics going from designing toilets that encourage cleanliness to Libertarian paternalism in the world of nutrition. The tone of the book is very research oriented and factual with very little or virtually no self help advice which is what I love about the book. I would give this a 4 / 5. 
  8. Focus: The Hidden Driver for Excellence – From how a house detective scans a huge store full of people, focuses on small tell-tell signs and picks shoplifters; to the science of willpower and the understanding of the famous 10000 hour rule popularized by Malcolm Gladwell, the book covers a lot of ground but provides very little real life tools or frameworks to increase your attention. A good read especially if you enjoy books on Psychology but again, if you’ve read a few books on neuroscience and psychology you will not find a lot of new ideas in this book. I rate this a 3 / 5.  
  9. Eat and Run: After reading born to run when I came across Scott Jurek’s (who was one of the primary real life characters of Born to Run) personal biography, I needed no special nudes to pick it up. Scott is indeed as good a writer / storyteller as he is a runner. A intricately woven collection of experiences resulting out of the  races he has run, experiences he has been through and the life he has lived make the book a fascinating read. Scott’s own character, his vegan diet and his outlook on life is an icing on the cake. Again, a must read for anyone who wants to experience real-life story telling that is much more fascinating than fiction.  A 5/5.
  10. One Up on Wall Street: Maybe it’s my experience with banking software or the fact that I come from a family that has done business for five generations, I’ve always invested a part of my salary in long term stable investments and have been fairly lucky with these investments. When I saw this book by Peter Lynch,  a respected fund manager, I seized the opportunity of learning from a master investor. What’s amazing about this book is that it covers the basic technicalities of investing (things like the PE ratio, value investing etc.) and then jumps into the art of investing. Do you invest in companies which have rich amazing offices or do you buy stocks of companies where a bunch of hard working folks are working in a cramped office in a non-expensive corner of the city? Do you keep your eyes open when you see a real life consumer product in your local supermarket and place your bets by investing on the company before the financial experts of the world start giving positive reviews to the stocks of that company? In a predatory world of bulls, bears, computerized flash trading and deception Peter provides hope to the individual investor and shows them how they can use their local insights to get a one up on wall-street. A 4/5. 
  11. Sleep Smarter: As a nerd who lives an extremely irregular life as far as sleeping habits are concerned, when I bumped into Sleep Smarter I knew this was my chance to bring about some serious change into my life. The book was a collection articles which describe how big an issue sleep deprivation is and then moves into some real pragmatic tips that you can use today to improve your sleep. For example, avoid screen time at-least a few hours before sleep and if you must, install a special app that dims out light on your phone. How temperature effects your sleep, how the clothes you wear have an impact on your sleep and above all, how to make real lasting changes to your sleeping habits. This is not a book that everyone might appreciate but given my love hate relationship with sleep and the fact that I am a night owl who is also fascinated by the idea of waking up before the sun rises, the book was an extremely good read for me. I would give this 4/5.  
  12. Total Money Makeover: Dave Ramsey is one of the few guys in the world of personal finance whose advice I’ve incorporated in my own life and have benefitted HUGELY when it comes to my finances. I read this book early this year (in fact it was one of the first few books I read this year) and the book had one of the deepest influences on my financial life than any other book. I’ve adapted some of Dave’s ideas described in this book and have increased my savings 3X and am really close to becoming completely debt free. The book is an awesome read for everyone who has any debt, doesn’t keep a written monthly budget and doesn’t record every single transaction of his / her life. From busting popular myths about home loans, student loans, credit cards and car loans, Dave takes a slightly confrontational tone in this book but the tone serves it’s purpose of shaking you out of your dream world and brings you face to face with the dark reality of any debt and how that cripples your financial life. I’d give this book a 5 / 5 and the respect it deserves. If you have respect for money you should read this book. If you are a nerd who struggles with managing money, you have to read this book.   
  13. Originals: This book by far is one of the most ‘original’ books I’ve read on creativity. The book just demolishes every single conventional wisdom on creativity. Entrepreneurs are bold; WRONG. Entrepreneurs take chances and risks; WRONG. Most entrepreneurs are sure of their ideas and their vision: WRONG. Most startups are formed by people who are in their early thirties: WRONG. You need to quit your job if you want to form a startup and have conviction and belief in your idea: WRONG. Every single idea or non-scientific random self-help wisdom on creativity and entrepreneurship that you hear about so much these days will be shredded into tiny threads and blown off after you read this book. The book personally gives me validation that I’ve been seeking for a very long time but haven’t found anywhere else in the world. After reading this book all I can do is hope that more and more authors do responsible research like Adam Grant did for this book rather than parroting stupid self help catch words like – ‘passion’, ‘take the plunge’ and the ridiculous – ‘you can do it!’. No wonder this book has an almost 5 star rating on Amazon and is a breath of fresh air in all the books of business and creativity I’ve read thus far. I would rate it a big fat 5 / 5 and if you were going to read one book on creativity or if you were thinking of doing anything creative with your life, I would advice you to grab a copy of this book and read it cover to cover.   
  14. Mini Habits: Having difficulties working out? Why not start with just 1 push up a day? Sounds ridiculous? Try it and before you know it, you’ll be doing 100 a day in a couple of months. And if you don’t, well you can still do one and maintain your habit. The idea is ridiculous. In fact it’s so ridiculous it actually works! The premise behind this book? Our brain often makes an unpleasant activity which is good for us (like working out, eating vegetables) seem so difficult that we don’t even start. But what if we tricked our brain by saying, I’m just going to do one push-up or eat a tiny 1/2 inch slice of broccoli every day? There is very little resistance from your brain because the habit is so tiny. Once you start your brain sees it wasn’t that bad and naturally does more.   If it doesn’t; don’t push it – just do a pushup and you’re done. Which gives your brain no reason to resist. If you do more, you feel happy and encouraged. If you don’t you are not traumatized by the guilt of not living up to self-commitments and can still feel proud about finishing your commitment. It’s a small book, very to the point and a very interesting and practical way of hacking your own brain – which by the way, is a topic very near and dear to my heart. Definitely a 4 / 5.

I’ve obviously not been reading as much as I wanted to and probably will not make it to book 53 by the end of the year, but the challenge has indeed opened me up to new books, new ideas and introduced me to  topics I always wanted to read about. Net-Net it’s been fun so far and I hope I can read a few more interesting books before the end of the year.

posted on Sunday, 23 October 2016 11:48:22 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Saturday, 08 October 2016 by Rajiv Popat

There have been a lot of conversations around IoT lately. As someone who has done his major in accounting and as someone who builds business and financial applications for a living, I had a lot of excitement and some reservations about starting on my IoT journey. I mean I am just a regular nerd without any electronics background. Should I be playing with Microcontrollers and live current? After a few weeks, I’m happy to announce that the journey has been fun and I think it has been a journey worth sharing with you.

The basic underlying idea is to control things over the internet and hence the need for a programmable chip or a microcontroller - a small tiny independent board with a programmable chip that can run code in an infinite loop. The code controls the chip and the chip controls the devices or things it is connected to.

The “control” in the microcontroller can be as simple as turning a LED on / off or something as complex as building a smart home, with lights, fans, entertainment systems and water pumps controlled using your code.

Most articles and you-tube IoT examples out there are either way too complex involving complex circuits and code, or way too simplistic and impractical where someone shows you how to make a LED blink  with your code; which fortunately is a good start; but unfortunately does not allow you to anything practical with your microcontroller, which then puts your micro-controller in the same category as your gym membership - something you own but don’t actually use.

My goal with this series of posts, is to get started on IoT and provide enough insight on the topic to enable you to build something real and practical with it. The goal is also to take you to a point where IoT goes from yet another buzzword that electronics guys should be concerned about, to a practical, real, affordable and simple tool that you can use to build useful projects with.

In the first post we’ll cover some very basic concepts around the Arduino chipset (which is the micro-controller we are going to use for our IoT experiments) and write some basic code that runs on the chipset.

In the posts that follow we will attach some interesting modules to Arduino and write code to control these modules. Going ahead, we’ll get these modules and the microcontroller connected to your home Wifi and we’ll show you how you can control the microcontroller (and the modules connected to it) over the internet; and we’ll finally move on to working with real live electrical devices like, light bulbs and fans and control those with code.

All circuits we build in the process will be open sourced. All code we write in this process will also be on open sourced and  will be posted here on this blog for you to use.

When I started with my IoT journey a few weeks ago, I knew nothing about physics (or electronics) other than some basics I had picked up in high school, most of which I had never paid any attention to or had forgotten over time. Long story short, I’m just a regular nerd who writes business applications / CRUD screens for a living  and hence the series of these posts doesn’t require you to know physics or electronics to start. You will need to go out and buy a couple of cheap gadgets if you want to try some of these examples yourself but your overall investment will be less than 25 dollars.

And as a final disclaimer, I have never officially studied electronics so everything I write about here, is just a regular nerd trying to connect wires and have some fun. If something explodes (or if you cook a chipset or two) the responsibility is all yours!

Sounds good? Let's begin.

To start playing around with IoT we’re going to write code that controls devices so you’ll have to shell out some money and buy some basic devices. Even though there are platforms like the raspberry pi which make IoT much simpler, let’s start with buying a much cheaper micro controller which actually gets you a deeper understanding of the circuits you will be making, will make a smaller hole in your pocket and will help you stay away from having to run and entire Linux clone on your microprocessor like Raspberry Pi does.

Here are a few things you may want to go out and buy if you want to follow along:

  1. An Arduino UNO chipset - You can buy the original one or a cheap clone. I got one from amazon at about 7$.
  2. A Breadboard - so that you can connect wires and devices together without needing soldering equipment. I got mine from amazon at about 2$.
  3. Some jumper wires - so that you can connect devices on your Arduino and your breadboard. I picked up a neat set of male-to-male, male-to-female and female-to-female at Amazon. Cost of the whole kit? About 2$.
  4. A Few LEDs (and a few resistors) - which is the very first thing we will control with our code. You can also grab some resistors at 150 for just 1$ and a few LEDs for 3$.
  5. An ultrasonic transmitter - we will not be using it in the first demo, but we will need this in the third post, so it may be a good idea to get everything you will need in one shot. I picked up mine at 2$.
  6. A Wi-Fi module - that will eventually let you get connected to the internet over your home Wi-Fi connection and let you control the Arduino over an internet connection. Price? About 3$. Again, not something we will use in the first post, but something that we will use pretty soon.
  7. A Relay - that will let us control real live current / devices using our Arduino - we’re not going to use this for the next couple of posts but at 2$ a piece it’s something you may also want to order along with everything else mentioned above.

In under 25$ you have all you need to work on some meaningful IOT experiments and try out a few things.

We’ll get started with Arduino itself in this post and make it control a basic on-board LED light before we do some more interesting things with it. I do realize this example is highly non-practical but it is really simple, gets you used to the Arduino IDE and gets you familiar with the environment. So, let’s get started by making a LED blink, but before that lets begin by knowing our Microcontroller.

You can read article after after to understand the Arduino, but to start messing around with it, all you need to know is that is has 2 power output pins (using which connected devices can draw power) - one is a 3.3V power output pin, the other  a 5V power output pin. Apart from the power pins it also has ground pins labelled “GND” and all circuits that you make will usually end / complete with the ground pin. Put simply, your wiring will start with the power pin and end in the ground pin, and you will control everything else that’s in between (i.e. everything that’s connected to your IO pins).

Depending on the device you are connecting to your Arduino you can decide the power output you want to use. Most devices will have specs which will tell you how much power they expect. Exercise some common sense when you pick the power pin - for example, don’t connect your jumper wire to a 5V pin when the device you are connecting expects 3.3V - if you do there is a high chance you will cook your device.

Apart from the two power pins there are also some digital pins where you write a high or a low. Think of writing a “high” as turning a switch on and think of writing a “low” signal as turning the switch off. Out of all these pins, pin 13 is special because it has an in-built LED (light) attached to it that you can control with your code.

To write code we’re going to get the Arduino studio, which you can download from here and install using a simple installer. Once done, you connect your Arduino to the USB port of your laptop (which is one of the sources from which Arduino gets it’s power). Of course Arduino itself, can also work without a machine and you can hook it up with a battery or direct power, but for now since we will be uploading our code from our machine to the chip, it makes sense to have it connected with our laptop using the USB port.

Once connected go to your Arduino studio and pick the right port your Arduino is connected to. Usually the IDE automatically detects this but if it doesn’t you can try different ports and try to upload your code on each one till it succeeds. All code that typically runs on the microcontroller is referred to as a sketch and each sketch has a loop, which keeps on running as soon as the sketch is uploaded and the microcontroller is powered on.

An empty sketch looks like this.

Setup function is where you write code that runs only once. Anything you write in in “loop” runs in an infinite loop while the microcontroller is powered and on.

Now it’s time to connect the dots and assemble everything we’ve read thus far. Remember when we were talking about writing highs (which is same as turning the pin on) and lows(which is same as turning the pin off)? We know pin 13 has an in-built LED (light) and if we can write a high to pin 13, it should turn the switch on and the LED should glow. If we then write a low to the same pin the LED should shut off. If we do that in a loop function and wait 5 seconds between the on and the off, we should have an LED that keeps on blinking every five seconds the moment you power on the microcontroller. Simple enough? That’s exactly what we are doing in the code below:

int InBuiltLedPin = 13;

void setup() {
  // Let's set Pin 13 as Output Pin
  // Which means we will write high's and low's to it.
  pinMode(InBuiltLedPin, OUTPUT);

void loop() {
  // Turn on the Pin (and LED on board)
  digitalWrite(InBuiltLedPin, HIGH);
  // Wait for 5 Seconds
  delay (5000);
  // Turn off the Pin (and LED on board)
  digitalWrite(InBuiltLedPin, LOW);
  // Wait for another 5 seconds.
  delay (5000);

Verify your sketch (which is the same as compiling your code):

And once verified, upload your sketch on your Microcontroller:

And if all has gone fine you should see your Microcontroller LED blink on in five seconds (notice the Red LED next to pin 13 light up in the below picture):

And off in another five seconds:

Of course, this will continue in a loop till you switch off the microcontroller by pulling the USB cable off, or till you upload a new sketch.

And with that, you have just controlled an onboard LED with your code. In the next post, we will attach an external LED to the Arduino using a breadboard and try and change the same code slightly to make that LED blink. If you’ve never worked on electronics before the next post will introduce you to a lot of basic concepts like breadboards and resistors. And from there we’ll be ready to build some real life projects. So stay tuned for the next post.

posted on Saturday, 08 October 2016 18:33:14 UTC by Rajiv Popat  #    Comments [0] Trackback
Posted on: Sunday, 17 July 2016 by Rajiv Popat

I’m a nerd and I’ve never read anything about marketing other than books from Seth Godin. When I came across Contagious at my office library I was a little skeptical because it sounded like one of those books on social media which tries to teach you how you can spread your business or product. Contagious however, was both pleasantly surprising and analytical.

The book starts with logical and then goes into the illogical aspects beyond your control which decide how and why your products spread. For example the book describes how the sales of Mars candy shot up in mid-1997:

Back in mid-1997, the candy company Mars noticed an unexpected uptick in sales of its Mars bar. The company was surprised because it hadn’t changed its marketing in any way. It wasn’t spending additional money on advertising, it hadn’t changed its pricing, and it hadn’t run any special promotions. Yet sales had gone up. What had happened?

NASA had happened. Specifically, NASA’s Pathfinder mission.

The mission was designed to collect samples of atmosphere, climate, and soil from a nearby planet. The undertaking took years of preparation and millions of dollars in funding. When the lander finally touched down on the alien landscape, the entire world was rapt, and all news outlets featured NASA’s triumph.
Pathfinder’s destination? Mars.

Mars bars are named after the company’s founder, Franklin Mars, not the planet. But the media attention the planet received acted as a trigger that reminded people of the candy and increased sales. Perhaps the makers of Sunny Delight should encourage NASA to explore the sun.

Or how every Friday, millions of individuals are ‘triggered’ to listen to Rebecca Black’s Friday:

In 2011, Rebecca Black accomplished a momentous achievement. The thirteen-year-old released what many music critics dubbed the worst song ever.
Born in 1997, Rebecca was just a kid when she released her first full-length song. But this was far from her first foray into music. She had auditioned for shows, had attended music summer camp, and had sung publicly for a number of years. After hearing from a classmate who had turned to outside help for her music career, Rebecca's parents paid four thousand dollars to ARK Music Factory, a Los Angeles label, to write a song for their daughter to sing.

The result was decidedly, well, awful. Entitled "Friday," the tune was a whiny, overproduced number about teenage life and the joys of the weekend.

All in all, the piece sounds more like a monologue of the random thoughts going through an especially vacant teenager's head than a real song.

Yet this song was one of the most viral videos of 2011. It was viewed more than 300 million times on YouTube, and many millions more listened to it over other channels.

Why? The song was terrible, but lots of songs are terrible. So what made this one a success?
Take a look at the number of daily searches for "Rebecca Black" on YouTube in March 2011, soon after the song was first released. See if you notice a pattern.

Searches for "Rebecca Black" on YouTube March 2011

Notice the spike once every week? Look closer and you'll see that the spike happens on the same day every week. There was one on March 18, seven days later on March 25, and seven days later, on April 1.
The particular day of the week? You guessed it. Friday—just like the name of Rebecca Black's song.
So while the song was equally bad every day of the week, each Friday it received a strong trigger that contributed to its success.

The book talks about dozens of other triggers and techniques you can use in your products to make them contagious and tries to weave it all into a simple framework the authors call the STEPPS framework:

  1. Social Currency: We share things that make us look good.
  2. Triggers: Top of mind, tip of tongue.
  3. Emotion: When we care, we share.
  4. Public: Built to show, built to grow.
  5. Practical Value: News you can use.
  6. Stories: Information travels under the guise of idle chatter.

While the book did leave me with a deep understanding of what is contagious and what is not, it also left me wondering if the contagiousness of products is easy to analyze in the hindsight and much more difficult to plan ahead of time? Would the authors be able to look at an idea or a product before it’s inception and say with certainty if it would be contagious?

Every piece of information the book provided was something every marketing person should know about and yet the book did not convince me that adding all six elements of STEPPS consciously in your product guarantees that your product would be contagious. The book is a good read and provides a nice technical framework to describe contagiousness and maybe even some really pointers to help spread your work and make it more contagious but it didn’t change my overall belief that all you can do as an individual is just keep showing up and hope that the magic of contagiousness touches your work every once in a while.

posted on Sunday, 17 July 2016 10:53:28 UTC by Rajiv Popat  #    Comments [0] Trackback