<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>2016 on thefourtheye.in</title>
    <link>https://thefourtheye.in/posts/2016/</link>
    <description>Recent content in 2016 on thefourtheye.in</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language><atom:link href="https://thefourtheye.in/posts/2016/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>JS Quirks: stringified numbers</title>
      <link>https://thefourtheye.in/posts/2016/11/15/js-quirks-stringified-numbers/</link>
      <pubDate>Tue, 15 Nov 2016 00:38:30 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2016/11/15/js-quirks-stringified-numbers/</guid>
      <description>&lt;p&gt;When I was working on &lt;a href=&#34;https://github.com/nodejs/node/pull/9492&#34;&gt;Node.js PR 9492&lt;/a&gt;, &lt;a href=&#34;https://github.com/nodejs/node/pull/9492#discussion_r86987446&#34;&gt;this comment&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This should probably test for a wider range of values. &lt;code&gt;test/parallel/test-net-internal.js&lt;/code&gt; has some good examples.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;made me look at &lt;a href=&#34;https://github.com/nodejs/node/blob/fc44bd4d0b984f7b926b8c92b8e9a88da1c08921/test/parallel/test-net-internal.js&#34;&gt;that file&lt;/a&gt;. As I was going through the test, few of the bad values were interesting. I normally test with stringified positive decimal numbers and negative decimal numbers. But I saw stringified negative octal, binary, and hexa decimal numbers.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const bad = [-1, &#39;a&#39;, {}, [], false, true, 0xFFFF + 1, Infinity,
             -Infinity, NaN, undefined, null, &#39;&#39;, &#39; &#39;, 1.1, &#39;0x&#39;,
             &#39;-0x1&#39;, &#39;-0o1&#39;, &#39;-0b1&#39;, &#39;0o&#39;, &#39;0b&#39;];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I got curious as I have never used them before, I just wanted to see their corresponding negative values. So I wrote a program like this&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;[-0x1, &#39;-0x1&#39;, -0o1, &#39;-0o1&#39;, -0b1, &#39;-0b1&#39;].forEach(item =&amp;gt; console.log(item, +item));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and I was expecting to see the result&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;-1 -1
-0x1 -1
-1 -1
-0o1 -1
-1 -1
-0b1 -1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but all I got was&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;-1 -1
-0x1 NaN
-1 -1
-0o1 NaN
-1 -1
-0b1 NaN
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The unary - operator simply negates the magnitude of the numbers. The stringified numbers were not processed in the same way as their number counterparts. So I looked at the ECMAScript specification&amp;rsquo;s &lt;a href=&#34;http://www.ecma-international.org/ecma-262/6.0/#sec-tonumber-applied-to-the-string-type&#34;&gt;ToNumber Applied to the String Type&lt;/a&gt; section (which is actually responsible for converting strings to numbers).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;StrNumericLiteral :::
    StrDecimalLiteral
    BinaryIntegerLiteral
    OctalIntegerLiteral
    HexIntegerLiteral
...
...
StrDecimalLiteral :::
    StrUnsignedDecimalLiteral
    + StrUnsignedDecimalLiteral
    - StrUnsignedDecimalLiteral
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Only the &lt;code&gt;StrDecimalLiteral&lt;/code&gt; production allows signed numbers. If we look at the definition of others in the &lt;a href=&#34;http://www.ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals&#34;&gt;Numeric Literals&lt;/a&gt; section,&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;BinaryIntegerLiteral ::
    0b BinaryDigits
    0B BinaryDigits

BinaryDigits ::
    BinaryDigit
    BinaryDigits BinaryDigit

BinaryDigit :: one of
    0 1

OctalIntegerLiteral ::
    0o OctalDigits
    0O OctalDigits

OctalDigits ::
    OctalDigit
    OctalDigits OctalDigit

OctalDigit :: one of
    0 1 2 3 4 5 6 7

HexIntegerLiteral ::
    0x HexDigits
    0X HexDigits

HexDigits ::
    HexDigit
    HexDigits HexDigit

HexDigit :: one of
    0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, as per the specification, only the decimal numbers can have signs in the stringified number form. That is why the others are not considered as numbers.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>DSL-2730U router&#39;s ipv6 problem in Ubuntu</title>
      <link>https://thefourtheye.in/posts/2016/03/06/dsl-2730u-routers-ipv6-problem-in-ubuntu/</link>
      <pubDate>Sun, 06 Mar 2016 20:32:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2016/03/06/dsl-2730u-routers-ipv6-problem-in-ubuntu/</guid>
      <description>
&lt;div class=&#39;post&#39;&gt;
&lt;div dir=&#34;ltr&#34; style=&#34;text-align: left;&#34; trbidi=&#34;on&#34;&gt;Today I faced a very strange problem. I got a new Tata DOCOMO connection and I wanted to fetch upstream changes from a GitHub repository, with &lt;code&gt;git fetch --all&lt;/code&gt;. But all I got was&lt;pre&gt;fatal: unable to access &#39;https://github.com/&amp;lt;repo&amp;gt;&#39;: Failed to connect to github.com port 443: Network is unreachable&lt;br /&gt;&lt;/pre&gt;I thought that the internet connection has a problem. But then I was able to &lt;code&gt;ping github.com&lt;/code&gt; and access that site in my browser, although curl still failed.&lt;br /&gt;&lt;pre&gt;➜  io.js git:(master) ✗ curl https://github.com&lt;br /&gt;curl: (7) Failed to connect to github.com port 443: Network is unreachable&lt;/pre&gt;At this point I became curious and tried out the verbose curl,&lt;br /&gt;&lt;pre&gt;➜  io.js git:(master) ✗ curl -v https://github.com&lt;br /&gt;* Rebuilt URL to: https://github.com/&lt;br /&gt;* Hostname was NOT found in DNS cache&lt;br /&gt;*   Trying 192.30.252.128...&lt;br /&gt;*   Trying 64:ff9b::c01e:fc81...&lt;br /&gt;* connect to 64:ff9b::c01e:fc81 port 443 failed: Network is unreachable&lt;br /&gt;* Failed to connect to github.com port 443: Network is unreachable&lt;br /&gt;* Closing connection 0&lt;br /&gt;curl: (7) Failed to connect to github.com port 443: Network is unreachable&lt;/pre&gt;Now, it figures out both the IPv4 address and the IPv6 address but favors IPv6 over IPv4. And it looks like, either the modem or the ISP don&#39;t support IPv6 based communication. I don&#39;t know how to confirm what the actual problem is. I tried to upgrade the firmware of my DSL-2730U router, by logging into 192.168.1.1. But it kept failing, saying the the firmware image file is too big.&lt;br /&gt;&lt;br /&gt;So, I decided to disable IPv6 in my Ubuntu machine and I followed the instructions given &lt;a href=&#34;http://askubuntu.com/a/484487/147253&#34;&gt;here&lt;/a&gt; and it worked perfectly. Basically, I edited &lt;code&gt;/etc/sysctl.conf&lt;/code&gt; file to include the following lines&lt;pre&gt;# disable IPv6 on this machine&lt;br /&gt;net.ipv6.conf.all.disable_ipv6 = 1&lt;br /&gt;net.ipv6.conf.default.disable_ipv6 = 1&lt;br /&gt;net.ipv6.conf.lo.disable_ipv6 = 1&lt;/pre&gt;and then executed &lt;code&gt;sudo sysctl --system&lt;/code&gt; and &lt;code&gt;sudo sysctl -p&lt;/code&gt;.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Sane ECMAScript 6 Generators</title>
      <link>https://thefourtheye.in/posts/2016/02/03/sane-ecmascript-6-generators/</link>
      <pubDate>Wed, 03 Feb 2016 20:47:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2016/02/03/sane-ecmascript-6-generators/</guid>
      <description>
&lt;div class=&#39;post&#39;&gt;
&lt;div dir=&#34;ltr&#34; style=&#34;text-align: left;&#34; trbidi=&#34;on&#34;&gt;This post is cross posted in Medium, &lt;a href=&#34;https://medium.com/@thefourtheye/sane-ecmascript-6-generators-7d1adcd85536#.cpvn9y4n8&#34;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I recently found one interesting thing about ES6 Generators. I come from Python background and I understood generators as in Python. So, I expected the following Python code&#39;s equivalent ECMAScript 6 code also to work as well. &lt;!--?prettify lang=python linenums=true?--&gt;&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&gt;&gt;&gt; numbers = (num for num in range(10))&lt;br /&gt;&gt;&gt;&gt; for num in numbers:&lt;br /&gt;...   if num == 3:&lt;br /&gt;...     break&lt;br /&gt;... &lt;br /&gt;&gt;&gt;&gt; next(numbers)&lt;br /&gt;4&lt;br /&gt;&lt;/pre&gt;You can find the online demo for this Python program, &lt;a href=&#34;http://ideone.com/9lYJOz&#34;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But then, when I used Babel to transpile the following code and executed it&lt;!--?prettify lang=javascript linenums=true?--&gt;&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;function* NumberGenerator() {&lt;br /&gt;  for (var i = 0; i &lt; 10; i += 1) {&lt;br /&gt;    yield i;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var numbers = NumberGenerator();&lt;br /&gt;&lt;br /&gt;for (var num of numbers) {&lt;br /&gt;  if (num === 3) {&lt;br /&gt;    break;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;console.log(numbers.next());&lt;br /&gt;// {&#34;done&#34;:true}&lt;br /&gt;&lt;/pre&gt;You can find the online demo for this JavaScript program, made with Babel&#39;s REPL, &lt;a href=&#34;https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=true&amp;code=function*%20NumberGenerator()%20%7B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%20%2B%3D%201)%20%7B%0A%20%20%20%20yield%20i%3B%0A%20%20%7D%0A%7D%0A%0Avar%20numbers%20%3D%20NumberGenerator()%3B%0A%0Afor%20(var%20num%20of%20numbers)%20%7B%0A%20%20if%20(num%20%3D%3D%3D%203)%20%7B%0A%20%20%20%20break%3B%0A%20%20%7D%0A%7D%0A%0Aconsole.log(numbers.next())%3B%0A&#34;&gt;here&lt;/a&gt;.  As you see here, when I broke out of the loop, the Generator Object got closed. This was pointed out to me by &lt;a href=&#34;http://stackoverflow.com/users/785065/loganfsmyth&#34;&gt;Logan Smyth&lt;/a&gt; in Babel&#39;s Slack discussion. I was really surprised by this behavior and found the &lt;a href=&#34;http://www.ecma-international.org/ecma-262/6.0/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset&#34;&gt;13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation ( lhs, stmt, iterator, lhsKind, labelSet )&lt;/a&gt; section in the ECMAScript 6 Specification, which says  &lt;blockquote&gt;If LoopContinues(result, labelSet) is false, return IteratorClose(iterator, UpdateEmpty(result, V)).&lt;/blockquote&gt;I am not sure about the rationale behind that decision, but I am convinced that it would effectively limit the potential of the Generators. So I decided to fix this.  &lt;h2&gt;Sane Generators&lt;/h2&gt;To close the iterator, &lt;code&gt;Iterator.prototype.return&lt;/code&gt; is called. (At the time of this writing, not many JavaScript Engines support this function. You can find the support for this feature by popular engines, &lt;a href=&#34;https://kangax.github.io/compat-table/es6/#test-generators_yield_*,_iterator_closing&#34;&gt;here&lt;/a&gt;.) So I decided to override that and allow the actual &lt;code&gt;return&lt;/code&gt; function to be invoked only when explicitly called with an argument.&lt;!--?prettify lang=javascript?--&gt;&lt;pre class=&#34;prettyprint&#34;&gt;function returnFunction(originalReturn, genObject) {&lt;br /&gt;  return function(arg) {&lt;br /&gt;    return arguments.length ? originalReturn.call(genObject, arg) : {&lt;br /&gt;      done: false&lt;br /&gt;    };&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function SaneGenerator(genObject) {&lt;br /&gt;  var originalReturn = genObject[&#39;return&#39;];&lt;br /&gt;&lt;br /&gt;  if (typeof originalReturn === &#39;function&#39;) {&lt;br /&gt;    Object.defineProperty(genObject, &#39;return&#39;, {&lt;br /&gt;      value: returnFunction(originalReturn, genObject)&lt;br /&gt;    });&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return genObject;&lt;br /&gt;}&lt;/pre&gt;You can see the actual and complete implementation in my GitHub repository, &lt;a href=&#34;https://github.com/thefourtheye/sane-generator/blob/master/index.js&#34;&gt;https://github.com/thefourtheye/sane-generator&lt;/a&gt;.  Now, you can use the &lt;code&gt;SaneGenerator&lt;/code&gt; like this &lt;!--?prettify lang=javascript?--&gt;&lt;pre class=&#34;prettyprint&#34;&gt;function* NumberGenerator() {&lt;br /&gt;  for (var i = 0; i &lt; 10; i += 1) {&lt;br /&gt;    yield i;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var numbers = SaneGenerator(NumberGenerator());&lt;br /&gt;&lt;br /&gt;for (var num of numbers) {&lt;br /&gt;  if (num === 3) {&lt;br /&gt;    break;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;console.log(numbers.next());&lt;br /&gt;// {&#34;value&#34;:4,&#34;done&#34;:false}&lt;br /&gt;&lt;/pre&gt;You can find the online demo for this JavaScript program, made with Babel&#39;s REPL, &lt;a href=&#34;https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=true&amp;code=function%20returnFunction(originalReturn%2C%20genObject)%20%7B%0A%20%20return%20function(arg)%20%7B%0A%20%20%20%20return%20arguments.length%20%3F%20originalReturn.call(genObject%2C%20arg)%20%3A%20%7B%0A%20%20%20%20%20%20done%3A%20false%0A%20%20%20%20%7D%3B%0A%20%20%7D%3B%0A%7D%0A%0Afunction%20SaneGenerator(genObject)%20%7B%0A%20%20var%20originalReturn%20%3D%20genObject%5B&#39;return&#39;%5D%3B%0A%0A%20%20if%20(typeof%20originalReturn%20%3D%3D%3D%20&#39;function&#39;)%20%7B%0A%20%20%20%20Object.defineProperty(genObject%2C%20&#39;return&#39;%2C%20%7B%0A%20%20%20%20%20%20value%3A%20returnFunction(originalReturn%2C%20genObject)%0A%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20return%20genObject%3B%0A%7D%0A%0Afunction*%20NumberGenerator()%20%7B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%20%2B%3D%201)%20%7B%0A%20%20%20%20yield%20i%3B%0A%20%20%7D%0A%7D%0A%0Avar%20numbers%20%3D%20SaneGenerator(NumberGenerator())%3B%0A%0Afor%20(var%20num%20of%20numbers)%20%7B%0A%20%20if%20(num%20%3D%3D%3D%203)%20%7B%0A%20%20%20%20break%3B%0A%20%20%7D%0A%7D%0A%0Aconsole.log(numbers.next())%3B%0A&#34;&gt;here&lt;/a&gt;.  &lt;h2&gt;NPM Module&lt;/h2&gt;This is available as an NPM module now. &lt;a href=&#34;https://www.npmjs.com/package/sane-generator&#34;&gt;https://www.npmjs.com/package/sane-generator&lt;/a&gt; &lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Sublime Text 3 unhiding menu in Ubuntu - simpler solution</title>
      <link>https://thefourtheye.in/posts/2016/01/10/sublime-text-3-unhiding-menu-in-ubuntu/</link>
      <pubDate>Sun, 10 Jan 2016 20:44:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2016/01/10/sublime-text-3-unhiding-menu-in-ubuntu/</guid>
      <description>
&lt;div class=&#39;post&#39;&gt;
&lt;div dir=&#34;ltr&#34; style=&#34;text-align: left;&#34; trbidi=&#34;on&#34;&gt;The method which I mentioned in this &lt;a href=&#34;http://www.thefourtheye.in/2014/01/un-hiding-menu-bar-in-sublime-text-3.html&#34;&gt;blog post of mine&lt;/a&gt;, solves the problem, but then you have to&lt;br /&gt;&lt;ol&gt;&lt;li&gt; Close the Sublime Text&lt;br /&gt;&lt;li&gt; Fire up a terminal&lt;br /&gt;&lt;li&gt; Execute a command or two&lt;br /&gt;&lt;li&gt; Open Sublime Text again&lt;br /&gt;&lt;/ol&gt;Quite a lot of steps to do. But then I found a simpler solution today and it works like a charm for me. The solution is to use &#34;Keyboard Shortcuts&#34; :-) Let me explain in detail.  &lt;ol&gt;&lt;li&gt; Click &lt;code&gt;Preferences&lt;/code&gt; -&gt; &lt;code&gt;Key Bindings - User&lt;/code&gt;&lt;br /&gt;&lt;li&gt; In the window that opens, you need to add a new keyboard shortcut for the command &#34;toggle_menu&#34;. For example, this is how my shortcuts looks like&lt;br /&gt;&lt;pre&gt;[{&#34;keys&#34;: [&#34;ctrl+\\&#34;], &#34;command&#34;: &#34;toggle_side_bar&#34;},&lt;br /&gt; {&#34;keys&#34;: [&#34;ctrl+shift+m&#34;], &#34;command&#34;: &#34;toggle_menu&#34;}]&lt;/pre&gt;&lt;li&gt; Save the file and start doing your happy dance.&lt;br /&gt;&lt;/ol&gt;Now, you can simply press the keyboard shortcut whatever you choose to assign to toggle menu :-)  &lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
