Posts

Table sorting accessibility for AngularJS table/list

Has your SPA accessibility compliance done ?
Ahhh … let me get back to you.That’s usual scenario for dynamic single page application. Since content of the web app changes dynamically/asynchronously. It required need addition planning to make dynamic web accessibility complain. For those who are new to web accessibility The power of the Web is in its universality. Access by everyone
regardless of disability is an essential aspect.There are many tools are being provided to make the web accessible like screen reader. The screen reader read out the html content with help of aria attributes. One of the accessibility attribute is aria-sort . It let the user know that the given html table is sorted by of the its column and in which order. The sorted column of the table expected to have ng-aria=”ascending/descending”.The problem with SPA table is that on sorting the table the content get sorted without loading the web, so having static aria-sort attribute is going to help. The aria-sor…

Management lesson from The Bridge Riddle

Most of us come across the Bridge Riddle sometime before, it is all about optimizing time to cross the bridge. Here is the riddleYou, an assistance, a jenitor and a scientist have to cross a wooden bridge in 17 minutes. The bridge is weak and only able to carry the weight of
two of them at a time. Because they are in a rush and the light is
fading they must cross in the minimum time possible and must carry a
torch (flashlight,) on each crossing.They only have one torch and it can’t be thrown. Because of their
different fitness levels and some minor injuries they can all cross at
different speeds. You can cross in 1 minute, assistance in 2 minutes, the janitor
in 5 minutes and the scientist in 10 minutes.Below TED Ed video explains and solve this riddle
https://www.youtube.com/watch?v=7yDmGnA8Hw0As explained in the video the key decision is to reply on the assistant who is comparatively less efficient than “You”, the assistant takes double time to cross the bridge th…

All about Java stream collect offering

Lets start with a problem statement “Provided collection of employees, we need to find average, max and min age of employee by county”public static void avgMaxMinEmployeeAgeByCounter() { String AVG = "AVG"; String MAX = "MAX"; String MIN = "MIN"; String SUM = "SUM"; String COUNT = "COUNT"; List<Employee> employees = Employee.EMPLOYEES;//LIst of all employees, pojos // Mapping country name to average, max, min age of employee Map<String, Map<String, Double>> summary = new HashMap<>(); for(Employee e: employees) { if(summary.containsKey(e.getCountry())){ Map<String, Double> map = summary.get(e.getCountry()); map.put(SUM, (map.get(SUM) + e.getAge())); map.put(COUNT, map.get(COUNT) +1); map.put(MAX, map.get(MAX) < e.getAge() ? e.getAge():map.get(MAX)); map.put(MIN, map.get(MIN) > e.getAge() ? e.getAg…

Utilizing ES6 Generator

I am going through Mozilla documentation about the Iterator and Generator concept introduced in ECMAScript6. Here is the overview as per Mozilla JS guideProcessing each of the items in a collection is a very common
operation. JavaScript provides a number of ways of iterating over a
collection, from simple for loops to map() and filter(). Iterators and
Generators bring the concept of iteration directly into the core
language and provide a mechanism for customizing the behavior of
for…of loops.This post is not about how it works, it is better explained at Mozilla JS guide.I have tried to apply the JS generator for one of the our day to day code. I think it is better suitable for lazy traversing and evaluating each item and proceed further if required. A common example comes in my mind is the tree traversing. I have implemented Depth First Search ( pre-order) using generator. Consider the scenario where you need to traverse the tree node, evaluate/process the node and go …

Looping & Closure

Image
Here is simple code to dynamically create set of buttons that greet in different languages.document.body.onload = createButtons; function createButtons() { var greetings = [ {lang:'English', msg:'Good Morning !!'}, {lang:'German', msg:'Guten Morgen !!'}, {lang:'French', msg:'Bonjour !!'}, {lang:'Finnish', msg:'Huomenta !!'} ]; document.createElement('h1'); console.log(greetings); for(var i=0;i<greetings.length; i++){ var greet = greetings[i] var input = document.createElement("button"); input.appendChild(document.createTextNode(greet.lang)); input.setAttribute('class','btn btn-default btn-lg'); input.onclick = function(event){ alert(greet.msg); }; document.body.appendChild(input); } } Pretty simple, looping through array of objects and adding buttons with languag…

NPE as well as Null check free code ... Really ?

Image
NPE as well as Null check free code … Really ?Is this how your Java code review start ? NPE is always nightmare for a Java developer. Lets not discussion to much and jump on an usual Java code snippet public interface Service { public boolean switchOn(int timmer); public boolean switchOff(int timmer); //Other controls } public class RefrigeratorService implements Service { // ... } public class HomeServices { private static final int NOW = 0; private static HomeServices service; public static HomeServices get() { //Null Check #1 if(service == null) { service = new HomeServices(); } return service; } public Service getRefrigertorControl() { return new RefrigeratorService(); } public static void main(String[] args) { /* Get Home Services handle */ HomeServices homeServices = HomeServices.get(); //Null Check #2 if(homeServices != null) { Service re…

Java doesn't have "Diamond" problem : Really ..?

Java doesn’t have “Diamond” problem : Really ..?We have been confidently telling that Java doesn’t have diamond problem even if it support multiple inheritance.In object-oriented programming languages with multiple inheritance and
knowledge organization, the diamondproblem is an ambiguity that
arises when two classes B and C inherit from A, and class D inherits
from both B and C.But do you that the diamond problem is now there in newly introduced Java 8. It is because of the introduction of default methods in Interface. In Java8 Interfaces not only have method declaration but their default implementation. Any class implementing can either use default implementation from interface or provide its own implementation. Since Java class can implement multiple interfaces it is possible that two interfaces has same default methods, that brings diamond problem.How do we overcome diamond problem ?Consider following code snippetpublic interface InterfaceA { default long calculateA…