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.



Thursday, 17 November 2016

Left rotate array in javascript - Data Structure - Array


    var rotateTimes = 3;
    var arr = [1, 2, 3, 4, 5, 6];
    var spliced = arr.splice(0, rotateTimes);
    arr.push.apply(arr, spliced);
    console.log(arr.join(' '));

With comments

    // This many times we want to rotate our array
    var rotateTimes = 3;
    // our array
    var arr = [1, 2, 3, 4, 5, 6];
    // splice will remove first rotateTimes numbers
    var spliced = arr.splice(0, rotateTimes);
    // since spliced is an array, simple push wouldn't do.
    arr.push.apply(arr, spliced);
    console.log(arr.join(' '));

One caveat though, the number of rotations is less than length of the input array.

It’s so easy in javascript. Believe me, if it was C, you were going to go through a for loop.



Wednesday, 16 November 2016

Bash Profile Updates Nov 2016

Bash profile

You should have read

This post is an update on that.

This is from the ~/.profile file that I have at present.

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
export PS1="\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

export NVM_DIR="/Users/myuser/.nvm"
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/"  # This loads nvm

alias gs="git status"

alias gd="git diff"

alias gl="git log"
alias gln3="git log -n3"

alias gpr="git pull --rebase"
alias gprud="git pull --rebase upstream develop"
alias gprum="git pull --rebase upstream master"
alias gprur="git pull --rebase upstream release"

alias gpo="git push origin"
alias gpom="git push origin master"
alias gpod="git push origin develop"

alias gpfom="git push -f origin master"
alias gpfod="git push -f origin develop"

alias gpu="git push upstream"
alias gpo="git push origin"

alias gf="git fetch"

alias gco="git checkout"
alias gcom="git checkout master"
alias gcod="git checkout develop"
alias gcor="git checkout release"

alias grv="git remote -v"
alias gra="git remote add"
alias grr="git remote rename"

alias gconflicted="git diff --name-only --diff-filter=U"
alias gstaged="git diff --cached"

alias gvizt="git log --pretty=oneline --graph --decorate --all"
alias gignored="git ls-files --others -i --exclude-standard"

alias grh="git reset --hard HEAD"
alias gfollow="git log --follow -p"

alias gfetcho="cd ~/code/work/xyz && gcod && gprud && gcor && gprur && gcod"


gfetcho is something of a morning ritual.

- goes the work project directory
- checkouts to develop branch
- pulls with rebase the upstream develop branch
- checkouts release branch
- pulls with rebase the upstream release branch
- checksout the develop branch
- doesn’t fetch changes if current working branch is dirty (thanks git for that one).


Because of PS1 and parse_git_branch() my prompt is something like:

current-directory (current-branch)