Monday, 5 December 2016

Using defer instead of async in scripts

Use defer to load scripts as late as possible

This is a performance boost.

  1. Use defer to defer the loading of the scripts.
  2. Don’t use async="async": it means you are fine with it loading and executing at later time. The smaller scripts will be loaded and executed first.
  3. You don’t need to use type="text/javascript". JavaScript has won.

So your code becomes:

<script src="js/jquery.min.js" defer></script>
<script src="js/bootstrap.min.js" defer></script>
<script src="js/plugin.js" defer></script>
<script src="js/main.js" defer></script>

This should solve your problem.

Refer MDN:


Set this Boolean attribute to indicate that the browser should,
if possible, execute the script asynchronously. It has no effect on
inline scripts (i.e., scripts that don’t have the src attribute)


This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded. The defer attribute shouldn’t be used on scripts that don’t have the src attribute.


Sunday, 4 December 2016

Log and updates

Updates for Dec, 2016

Total time tracked
Between Nov, 1st to Dec 4th
400+ hours


Time spent past month

160+ hours

I slept 18 hours out of last 24 and 29 out of 58. I never liked sleeping, it felt waste of time. I am going to sleep 10 hours a day

Clash of Clans

Time spent past month

60+ hours

I am not going to play CoC for the days left in December.


I don’t track work.

Daily rituals

About 5% of the time.


About 6 hours. In total. I am in bad shape.


Friday, 2 December 2016

Things I like about twitter

Twitter : Things I like about

I rarely like things.

First and foremost, you can hear directly from the sources.

The source factor
This was not possible for a huge period of time in human history.
Think about olden times when someone said something and people who received the message fumbled it while passing on.

However, there were systems of passing knowledge like Vedic system, which managed to pass a huge amount of information on via chants.

Back to how people can misuse messages.

A king decreed a new law. Ministers received it and then passed it on. Somewhere down the 300 miles mark, the rich people of that town modified it a little for their advantage and people didn’t know if it really was from the king.
This would go on until one person figures out, but he/she is bought or killed. Thus giving birth to information economy in olden days.

Anyway, Twitter allows you to hear from the people who do stuff. This gives immense confidence to followers.

You can follow people you want to know about

In olden days, this would be difficult; in recenter times a crime; in current world, cyber-follow is the norm.

You can follow people you care about

The family factor
Your family, in real time. If they choose to let you know via twitter.

You can talk to people who make stuff or write books, or to the movie stars and presidents even

The easy reach factor
For example, I have talked to movie actress, book authors and programming language inventors on twitter and they have replied. True story.
Presidents and Prime Ministers however have been giving me silent treatment. ;) A deserved one.

You can get news from the source

The News Factor: again, the source matters. You can see and read about things as they are happening. For example, I have live tweeted a few of conferences that I have been to.


Tuesday, 29 November 2016

Next is dart-lang


I have been coding for a decade now and have worked with languages: C, C++, JavaScript, C#. I have tried to learn lisp, python, haskell and F#; didn’t succeed as much as I’d hoped initially. I learned somethings from lisp and python but haskell and F# proved just too cryptic for me.

Anyway, Here I am, thinking that I am stuck in the rut. I don’t want to learn typescript; I learned coffeescript thinking that it’s the next big language, turns out that it was merely a preprocessing language or something like that. Powers that can, named such languages transpiling languages.

Back to what to learn next, I am intrigued by dart-lang. This is from the family of C so that it can dupe C, C++, Java, C# and countless other programmers by looking familiar. Believe me, that’s a huge selling point these days in human’s world.

So, dart-lang, another attempt by google at complicating the programming language world; like we need it.

A brain hiccup
Oh, just now I remembered, I dabbled with rust-lang too, a bit. Boy did I greet wall with my forehead with enthusiasm. On that note, D and Julia were also tried, but due to lack of enough grey-matter in my brain, I dropped the idea of learning new languages.

I am still learning AngularJS framework and it’s inner workings, so with angular 2, dart makes sense; since the tooling is out.

Anyway, next stop, dart-lang.

Inspired by Aamir Khan's journey during Dangal movie's shooting

This is awesome. It's inspiring. Wow. I feel like I should learn something from it.

Here are a few take aways from this video and Aamir's narration.

1. Concentrate on today.
2. Don't look at the task that is left.
3. Diet is #1. Watch what you put in your body.
4. Fool your mind to keep pushing.
5. Surround yourself with better people.
6. Transformations are slow. Catastrophe struck suddenly.

This reminds me of the Eminem's line: You can do anything you set your mind to.

With that, I hope I remember these lessons. Hats off Aamir Khan.


Yup, I have decided to allow google ad sense. I have taken care that sensitive ads are not shown; but hey if you don't like it, blame google ad sense.

Placement of ads is below the post. (duh)

Yes the post's name is pun on Monetising. Yes monetising is relatively new word.

Well, let me know if ads are too off putting; compromise a little.

Monday, 21 November 2016

Function have keys in JavaScript

A few days back, I stumbled upon a syntax error, which should have been but wasn’t. I asked a question on twitter to Dr. Axel and Eric Elliot. (Two JS coders, I try to follow)

This led to a blog post on 2ality (Dr. Axel’s blog).

(In retrospect: He explained how it happens and even in his tweet it was clear. I was dumb then.)

He explains how it works, I just had a few questions, so I walked through the process my self. There are some answers here, but a few more questions.

Let’s do this.

What is the output obtained through following code?

    // 0
    function sum ( ) {
        let args = Array.from(arguments); // 0.0
        return args.reduce( (p, c, i, a) => p + c, 0 ); // 0.1

    // 1
    sum(1, 2, 3, 4, 5);

    // 2
    var a = [1, 2, 3, 4, 5, 6];
    sum.apply(null, a);

    // 3
    typeof sum

Well, 0 is a one true sum function written in pure spirit of javascript. Yes, please stop writing function sum (a, b) { return a + b; }.

There’s nothing fancy about it. All the arguments (from arguments) are converted to a true array using Array.from in 0.0.
0.1 sums the members of the array. Really nothing new here.

Then, output of 1 is 15.
Output of 2 is 21.
3 is "function".

But, here comes the weirdness.

What will be the output of the following code?

    // 4
    sum [ 3 ] = 'duality!';

    // 5
    sum(1, 2, 3, 4, 5);

    // 6
    sum(1, 2, 3);

    // 7
    sum [1, 2, 3, 4];

    // 8
    sum [1, 2, 3];

    // 9
    sum [1, 2];

    // 10
    let x = [1, 2, 3]
    sum x;

    // 11
    typeof sum

    // 12


    // 4
    sum [ 3 ] = 'duality!';
    -> not a syntax error.

    // 5
    sum(1, 2, 3, 4, 5);
    -> functionality still the same, 15

    // 6
    sum(1, 2, 3);
    -> functionality still the same, 6

    // 7
    sum [1, 2, 3, 4];
    -> undefined

    // 8
    sum [1, 2, 3];
    -> here's the change, "duality"

    // 9
    sum [1, 2];
    -> undefined

    // 10
    let x = [1, 2, 3]
    sum x;
    -> finally a syntax error!!!

    // 11
    typeof sum
    -> OME, still function

    // 12
    -> not that surprising really, ["3"]

But, questions I have now are

How does sum function now saves value for key 3?
Where does it store the value?
How’s type still function?
I think since everything is a function, perhaps anything can do so. Can it?

Yup, consider the following example.

    let x = [ 1, 2, 3 ];
    x [4] = [ 5, 6, 7, 8 ];

    // 13
    x [1, 2, 3, 4]
    -> turns out to be [5, 6, 7, 8]

I think I got a glimpse of light here. Anything tangled with , (comma operator), is evaluated to the last value; thus x[1, 2, 3, 4] becomes x[4]. Since, x is anyway an array, x[4] is evaluated and result produced.

Well, this I knew.

Huge Bummer!

But what stumped me is function-name [ ... ] syntax. I guess, this is possible because like array, functions too are objects. And objects cannot help store key-value.

So, back to the question, where is the value stored in the prototype chain?

I have no clue. I am in search of answers. Object playground didn’t help in this case. I need to debug running code.

enter image description here

After value assignment:

enter image description here

(If you are wondering what duality:1 is, it is the name of the script; so nothing)

Well, I still want to talk to a human being about it.

    sum.length = 1;

Since, length is unwritable, it still is 0.