andhapp Random ramblings

IE11's javascript engine doesn't work correctly with promises

Yes, you read it right!

It doesn’t work correctly. Specifically, if you had an array of promises, then in IE 11 (and any other version), the promises are processed synchronously, and it will go through them one by one. In Firefox and Chrome, it works as expected. The promises are resolved as and when they have finished processing and run independently of each other. Synchronous processing makes IE’s performance worst of all. In some cases, it just errors out. We spent quite a while on this issue and had to resort to using callbacks, in the end, to get it working in IE.

My suggestion for anyone working with the latest HTML5 API’s would be to start developing on IE. Browsers like Chrome have spoilt us developers, which makes it harder and at times, frustrating to put in workarounds for IE.

Update NVM to latest version

A very quick post as a reminder to self.

Running the install script for nvm like this will update nvm if it’s installed already.

curl https://raw.githubusercontent.com/creationix/nvm/v0.18.0/install.sh | bash

I had to trawl through few links to find this solution and don’t forget to change the version number in the command.

Adding changes selectively with Git

Here’s a scenario for you developers:

  1. You are happily hacking on a feature from the beach.

  2. But, someone on your team is waiting for your changes to go in because they need a few methods on a class you will add as part of your changes.

  3. You have written those methods but the whole functionality still needs work so you can’t commit it in.

  4. You don’t want the other members of your team to wait.

  5. They could work from your branch, but that would mean their work will now wait for your work to go in first.

  6. Or you could selectively add a couple of methods you have written in the class for them to use.

  7. But, is there a way to selectively add and commit files in git?

Yes, you can with git’s interactively adding a file feature. Below is a better explanation of the same feature with a little scenario:

Imagine I have a git repository with one file called first.txt. The file’s contents in the remote repository are:

code-for-blog(master)$ cat first.txt
This is first bit of text.

This is second bit of text.

This is third bit of text.

I am working through this file and update the contents to something like:

code-for-blog(master)$ cat first.txt
This is first bit of text.

This is second bit of text.

This is third bit of text.

This is fourth bit of text.

This is fifth bit of text.

This is sixth bit of text.

This is seventh bit of text.

This is eighth bit of text.

Now, I only want to commit the last 2-3 lines of this code. I have two options, either, I cut all except last 3 lines that I’ve added since the last commit and check it in and then paste the lines I cut, back into this file. That could work, but, imagine if you have to do the same across 3-4 files. Not very efficient, is it?

Or you could use the interactive tag for the git’s add command. We will take the same file (I’ve been talking about) as an example and try to add and commit only the last 3 lines of this file.

On running the following in a working directory

git add -i

you will see a menu with a list of files and commands one can run on the file.

code-for-blog(master)$ git add -i
           staged     unstaged path
  1:    unchanged       +10/-0 first.txt

*** Commands ***
  1: status	  2: update	  3: revert	  4: add untracked
  5: patch	  6: diff	  7: quit	  8: help

We would like to add only some selected lines we need to enter p(which stands for patch). This will drop you into a patch submenu like the one below. In the patch submenu, you will be able to select the file that you would like to patch. In this case, the letter f is the cue for it. Entering ‘f’ on this submenu and returning will show the same menu again, but this time, you will see that there’s a \* next to the file number on the left. In this case, 1 became \*1.

What now> p
           staged     unstaged path
  1:    unchanged       +10/-0 first.txt
Patch update>> f
           staged     unstaged path
* 1:    unchanged       +10/-0 first.txt
Patch update>>

After the file selection has been made, pressing enter at patch update prompt will drop you into the file, like the screenshot below. You can see the lines that have been added since the last commit. At the bottom, you can see a set of commands that can be run at this stage. You can see the explanation of these commands by typing ? and pressing enter.

Patch update>> f
           staged     unstaged path
* 1:    unchanged       +10/-0 first.txt
Patch update>>
diff --git a/first.txt b/first.txt
index fa9e9e5..e2581bc 100644
--- a/first.txt
+++ b/first.txt
@@ -3,3 +3,13 @@ This is first bit of text.
 This is second bit of text.

 This is third bit of text.
+
+This is fourth bit of text.
+
+This is fifth bit of text.
+
+This is sixth bit of text.
+
+This is seventh bit of text.
+
+This is eighth bit of text.
(1/1) Stage this hunk [y,n,q,a,d,e,?]?

I want to add the last 3 lines, I type e and press enter. e stands for manual editing. This will open up the same file in your default editor. Usually, that’s determined by $EDITOR environment variable.

After editing and saving the file, I will be returned to the first menu again. Type s and press enter to check the status of the files in the working directory. The status shows that 3 lines have been staged and there are still 7 unstaged lines remaining for file first.txt which is what we set out to achieve.

What now> s
           staged     unstaged path
  1:        +4/-0        +6/-0 first.txt

*** Commands ***
  1: status	  2: update	  3: revert	  4: add untracked
  5: patch	  6: diff	  7: quit	  8: help
What now>

There are a lot of other commands in the menu that shows up on git add’s interactive tag and please feel free to explore them in your own time. It seems like a bit long-winded when you do it the first time, but after a few times, it feels very straightforward and natural.

Hope it helps.

File's life through Git

I realised a few months ago that I should read more books. I have a ton of them. I could never read all of them unless I start now. The first one I ended up reading was a short book on git. It was quite basic except for a couple of striking things. One of them is this image I found on a blog that clearly and closely depicts the journey a file may take travelling from your working directory to the destination repository.

File's life through Git

Any seasoned Git user will know this by heart, but, it is still a very concise representation of git’s transport commands and the actual journey. By the way, Index is also known as Staging, just in case you get confused with terminology on Google.

I hope it helps new git users to get used to the process and the various stages.

Monitoring a webpage for changes

I have been following Reconstructing Ruby articles to create a Ruby VM from scratch to learn the process of creating a VM and the tools involved. I want a notification when a new article appears on the scene.

RSS feed?

I wish I could use RSS for it, but this particular side doesn’t have any RSS feeds. Also, the author of these articles updates the page with the links to the next article, so I’d probably need something that checks the page for changes and notifies me of the changes.

So, you are going to write one yourself, right?

Not so fast. Luckily, I found a solution on google. Page monitor chrome extension not only polls for the changes it also allows the user to configure when and how they want any notifications. I have been using the extension for few weeks now and it works like a charm. Next time you are looking for something similar, give it a try.