Code, learn & share

Simple obstacle avoiding robot using arduino

Building obstacle avoiding robot is a simple & fun way to start learning arduino and electronics. A lot of useful articles explain this, but you will be blocked if you can’t get the same parts in your region. In this post, I’ll explain how to build a simple and minimal robot using the parts available online in India.

Watch the below video to get an idea of what you could build by following this article.

Soft delete and unique constraint

This post describes a robust solution and other alternatives for having unique constraint at DB level for a table with soft deleted rows.

Problem Context

The system identifies the users by their mobile number and hence mobile number must be unique across users. The users are soft deleted in the system by updating column deleted = 1. A new user can register in with same mobile number as previously deactivated user (since mobile numbers are recycled by telecoms). The unique check at application are susceptible to fail in case of concurrent requests, unique constraint is needed at DB to ensure integrity of data.

Working software is worth thousand assurances

In the beginning of a software project, every one starts with a big list of features. If you ask the product owner, what is the minimum set of features that we can go live with? most of the times you’ll hear a lot more than you expected.

It gets lot harder to talk about minimum scope when you are rewriting an existing software. We would usually want to go live with the minimum viable product(MVP) and build reset of it incrementally. If people are new to agile methodologies, these questions on reducing scope might look stupid & annoying. Fortunately there are ways to get these questions answered, I’m sharing my experience from couple of projects in past few years.

Lets start with a story, where we are writing a new version of the popular website.

Using app objects in multi app functional tests

It is better to create small modular apps instead of single monolithic application. In Bahmni EMR we have small apps for Patient Registration, Consultation, etc. An end to end functional test covering patient registration and consultation goes through multiple apps. We needed to abstract the concept of an app in test code to increase the readability and maintainability.

The app objects are natural extension of page objects recommended for writing functional tests. An app encapsulates all pages and coarse level actions in the app.

Make sure functional tests are user centric

In modern day web applications, most of the data is fetched and saved using ajax calls and the mark up is generated on client side by compiling static HTML templates. The functional tests need to make sure assertions wait till completion of ajax call.

Couple of bad ways to achieve this is by using sleep(xSeconds) or wait_for_ajax like this

Keep your models independent of angular

If you are using MVC framework you need to make sure controllers are very thin and domain logic lies in small, framework independent, composable models - Wise People

In AngularJS, you need to make sure lot of data is not defined directly on $scope and domain logic is not dependent on angular’s digest cycle. If follow this mantra, unit testing the models would be a lot simpler which in turn is a indicates that your code in is good shape.

Javascript functions in JSON configuration

There is no native support for defining functions in JSON. Commonly used approach is to define function as string and use eval() or new Function() to contruct the function. The basic difference between these two are

  • eval() works within the current execution scope. It can access or modify local variables.
  • new Function() runs in a separate scope. It cannot access or modify local variables.

These samples show how the json would differ in these two cases

Spinners in single page apps

One of the good practices in single page apps, is to show spinners (overlay + loading icon) while retrieving data or saving asynchronously. Often people tend to add a generic interceptor to show spinner for all ajax calls. In any mid size app, you will realize that the assumption “Show an overlay for all ajax call” is incorrect. Few examples

  • An autocomplete input box fetching reote data
  • An infininte scroll fetching more data as the use scrolls down the list.