Monday, April 27, 2015

Checkboxes are colored black in IE 10 with ng-repeat

I have encountered a quite strange issue in Internet Explorer 10. Generally a checkboxe’s background color is filled with black and then transitions back to white, to the normal styling in IE 10. But the issue came with the behavior of my application. I had to keep a list of checkboxes and sort them in checked status and in ascending order.
When I click on the first checkbox it works fine; first turn into black and then turns back to normal color. But if I click any link other than the first one, IE 10 doesn’t seems to fire the event that turns the checkbox background color back into the normal color. Somehow I implemented the sorting part with orderBy filter inside the ng-repeat directive and I captured the checkbox select event via $event. Maybe capturing the $event caused the issue.

I have found a similar issue reported in Microsoft Connect, which is marked as won’t fix. Ultimately I decided to create my own directive.

Here is the HTML that does the ng-repeat for checkboxes, and filter's them according to status and name:
<div ng-repeat="item in (items | orderBy:['!status','itemName'])">
       <input type="checkbox" ng-click="itemClickEvent($event, item.itemId)" ng-model="item.status"/>
</div>

Controller method that captures the click event:
$scope.itemClickEvent = function ($event, itemId) {
                var checkbox = $event.target;
                var checkboxState = checkbox.checked;
                if (checkboxState) {
                    $scope.items = itemsFactory.doSomething(itemId);
                } else {
                    $scope.items = itemsFactory.doAnotherthing(itemId);
                }
        };

Custom directive I created:


IE10 version: IE10.0.9200.17229
Angularjs version: AngularJS v1.2.23
I’m still not certain about the cause of the issue and hope someone could shine some light on this J

Sunday, January 4, 2015

Concise UPnP

I had to sit for an exam last Saturday and I did a case study about few protocols during my preparation. One protocol that I was reading about is Universal Plug and Play (UPnP), to be precise its a protocol stack. Meantime I'm thinking of writing a post about potential of UPnP in IoT. So, here I'm summarizing UPnP.

XBox 360, PS4, Wii and Azureus usesUPnP

UPnP allows networked devices to search other devices on the network and establish connections among them.
UPnP supports Zero-Configuration networking. For instance when a UPnP compatible device connects to a network, it assigns an IP address, announces it and provide information about its capabilities upon requests and learn the availability and capabilities of other connected devices.
UPnP uses a concept called Control Points (CP), which are the devices use UPnP protocols to control other connected devices. Each device multicast requests to discover others using HTTP and UDP. UDP is used to avoid acknowledgements from receivers and retransmission in interrupts.
When a device first connects to a network it should search for a DHCP Server (Dynamic Host Control Protocol) and request for an IP address. If there aren't any DHCP servers, device must assign itself an IP address. This is known as AutoIP.
After establishing an IP addresses devices can inform the services they are offering and register them in control points on the network. The protocol used in UPnP to do this is called Simple Service Discovery Protocol (SSDP).
Even though devices are resisted with CPs it is required to get to know how devices are providing their services. Therefore CPs has to request device description, which contains device details, vendor specific details, and services and actions offered by the device. Device descriptions are in form of XML data. Having received device descriptions, CPs can invoke devices actions by sending a control message to the control URL.
A main drawback in UPnP is that it doesn't have a device authentication mechanism. Therefore UPnP systems assumes all connected devices are trustworthy.

References:
  • George F. Coulouris (2012) Distributed systems: concepts and design, 5th edn., Boston: Addison-Wesley.
  •  UPnP Forum (2014) UPnP AV The technology basis of DLNA, United States of America: UPnP Forum.

Saturday, January 3, 2015

Genetic Algorithms

Genetic algorithms are a major topic in evolutionary computing. It is based on the evolutionary process of the nature.
Basically a genetic algorithms is a search function where its objective is to find a good solution; technically a very fit chromosome. A chromosome is usually a set of bits or a complex data structure that represents a state of a system.
A set of chromosomes can be referred as a population where a generation in genetics algorithms in one reproductive cycle of replacing existing chromosome with new chromosomes generated by genetic crossover operations and mutation.
The advantage of genetic algorithms in search functions is that search result won't stuck in a local minimum. Because genetic crossover process produces radically different chromosomes in each generation and occasional mutations causes small changes within population.
Genetic algorithm's search can perform in very large and multidimensional search spaces. If there are N dimensions, N parameters should be encoded in each chromosome. 
For example, maximum value of the function F with one dependent variable x in execution.


F(x) = sin(x) * sin(0.4 * x) * sin(0.3 * x)

Lets find a good value for x where F(x) has its nearly possible maximum value.
References:
  •  Russel, S. J., 2009. Artificial Intelligence: A Modern Approach. 3rd ed. Uncertain Knowledge and Reasoning: Printice Hall.

Saturday, May 10, 2014

Is Karma sexy?




During the last week I had to work with a JavaScript unit test execution tool. At the beginning it was bit difficult since I’m not the guy who has a crush with web based technologies. Guess what I was falling in love with this after a while. So here I’m writing a post on “karma”, another product of Google’s AngularJS team.
Testing a Java or .Net code is not a strange thing, but testing a code that written in JavaScript may be quite tedious due to its’ workflow. Again writing an easily testable code in JavaScript comes with the experience. Test Driven Development can solve these two scenarios with its prerequisites; writing a testable code and providing an effective test environment.   
The philosophy of AngularJS is quite similar with above scenarios I have mentioned, but still it requires a tool that takes the responsibility of testing your code. This is what Karma does for you. It executes test cases on your code and test them in each browser you want.
Testing your code in every browser by opening them is not what developers want to do. Karma does it automatically. You only have to mention what browsers it should be tested in the configurations.

 
                        browsers: ['Chrome']                                             

In TDD, developers have to test code in every unit they code, but this won’t happen with web development due to its workflow. Ultimately it will remain a set of bugs in the code where you have no idea of the root cause. What Karma does is, it executes all test cases when developer save an update in his code.

Karma uses node.js so there are no OS limits. It allows you to write test cases in Behavior Driven Style and wrap BDD test frameworks like Jasmine.
So finally this test runner is all about giving feedback to the developer about what he coded. This feedback is what makes developers more productive. Ultimately this provides you a productive test environment, which requires minimum number of configuration to make your life easy.

Related links: