Monday, January 01, 2018

Moving to Medium

I have decided to publish on You can follow my posts there.

Tuesday, September 27, 2016

Light Cone Animation

I generated this animation of Past and Future Light Cones of a stationary point object with vertical line as it's world line using Mathematica. As such the each light cone should sweep a (pencil-like cylendrical) shape as time passes, but I am showing the light cones at any given moment only. Also the cones extend to + ve and -ve infinite time as such.

The vertical axis is time axis with unit t seconds.
The z=0 is the NOW plane showing two (not three) dimensional space. The normalized unit for space axes is ct, where c is the speed of light. Thus distance of 1 in x or y direction is the distance travelled by light in 1 second.
That gives us 45 degree sloped light cones.
The downward moving planes are future moments, becoming NOW and then the past moments.
The top cone is the Future cone.
The bottom cone is past cone.
The vertical line is the world line of a stationary point object.

Sunday, September 25, 2016


I started playing with Mathematica this weekend. Here is a simple widget to plot Cos and Sin functions on Unit circle. You may have to force evaluate the cell by clicking on Gear > Evaluate Cell.

Saturday, August 20, 2016

Console magic

You can detect duplicate ids by evaluating this Javascript expresssion in Chrome devtools console:

    .map(function(ele){ return;})
    .reduce(function(countMap, word) {countMap[word] = ++countMap[word] || 1;return countMap}, {})

Boom! You will get:

> Object { 
   id1: 1, 
   id2: 1,
   some-other-id: 1,
   duplicate-id: 2

What is going on here:

  • document.querySelectorAll() returns the NodeList of elements that have id attribute
  • slice() - converts a NodeList to a JavaScript Array
  • map() - converts elements array to array of id strings
  • sort() - sorts the array. If you evaluate only up to here you will get the sorted list of ids (with duplicates)
  • reduce() - creates an object with id value as key and number of occurrences as value

Additionally, if you add Object.keys(resultFromAbove).sort() you will get a sorted list of unique ids.

Also an example of Map-Reduce 

BTW you can use similar, slightly modified selector expression to list the CSS classes that are used on the page and also mow many times.

Monday, August 15, 2016

Appear on hover

Recently I needed a way to have controls for resizing appear on hover using pure CSS. I wanted allow progressive discovery of the feature to collapse the panels but did not want have a clutter of controls. I also wanted that once the user learns about the new feature they can directly access it by moving their mouse there and clicking.

I did it using :nth-child(1), :nth-child(2), and :hover pseudo classes. For the pair on left hand side, the key idea is that, I had to use display:inline-block; on the container span and float: left; style on :nth-child(2)to get around the CSS limitation of not being able to use a following sibling in markup order to affect the style of preceding sibling.

Do you have better suggestions?

Saturday, August 13, 2016

A simple gradle plugin to print the task execution graph of a gradle build.

Here is a gist for a simple gradle plugin implementation that can generate an HTML report of your gradle build's Task Execution Graph.

Here is a sample output for a simple project:

↦ :clean - Deletes the build directory.
↦ :build - Assembles and tests this project.
   ┖ :assemble - Assembles the outputs of this project.
      ┖ :jar - Assembles a jar archive containing the main classes.
         ┖ :classes - Assembles main classes.
            ┖ :compileJava - Compiles main Java source. ⊣
            ┖ :processResources - Processes main resources. ⊣
   ┖ :check - Runs all checks.
      ┖ :test - Runs the unit tests.
         ┖ :classes - Assembles main classes. ↑
         ┖ :testClasses - Assembles test classes.
            ┖ :compileTestJava - Compiles test Java source.
               ┖ :classes - Assembles main classes. ↑
            ┖ :processTestResources - Processes test resources. ⊣

To use it simply apply it in your build.gradle like so:

apply from: 'build-task-graph.gradle'

And then run any build like this;

> .\gradlew -m clean build

and find the output report in:


It should be a simple exercise to generate hyperlinked output or alternatively emit a .dot file graph or even generate SVG.

I use this to determine which tasks I should exclude using the -x flag and only (carefully) run the ones I need. Of course you have to know what you are doing. The idea is similar to my Maven Phases and Goals plugin.

Feedback welcome!