<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>2014 on thefourtheye.in</title>
    <link>https://thefourtheye.in/posts/2014/</link>
    <description>Recent content in 2014 on thefourtheye.in</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language><atom:link href="https://thefourtheye.in/posts/2014/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Python&#39;s venv problem with ensurepip in Ubuntu</title>
      <link>https://thefourtheye.in/posts/2014/12/30/python-venv-problem-with-ensurepip-in-ubuntu/</link>
      <pubDate>Tue, 30 Dec 2014 14:52:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2014/12/30/python-venv-problem-with-ensurepip-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;Ubuntu 14.04&#39;s Python 3.4 installation has a problem with &lt;code&gt;ensurepip&lt;/code&gt; module, as described in &lt;a href=&#34;https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847&#34;&gt;this bug&lt;/a&gt;. So if you follow the steps mentioned in the &lt;a href=&#34;https://docs.python.org/3/library/venv.html#creating-virtual-environments&#34;&gt;official documentation&lt;/a&gt;, you would see an error message like this&lt;pre class=&#34;prettyprint&#34;&gt;➜  Python  python3 -m venv py3.4venv&lt;br /&gt;Error: Command &#39;[&#39;/home/thefourtheye//py34venv/bin/python3&#39;, &#39;-Im&#39;, &#39;ensurepip&#39;, &#39;--upgrade&#39;, &#39;--default-pip&#39;]&#39; returned non-zero exit status 1&lt;br /&gt;&lt;/pre&gt;To resolve this problem, first install the &lt;code&gt;venv&lt;/code&gt;, without &lt;code&gt;pip&lt;/code&gt;, like this&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;python3 -m venv py3.4venv --without-pip&lt;/pre&gt;And then if you install &lt;code&gt;pip&lt;/code&gt;, like this, it will still fail&lt;pre class=&#34;prettyprint&#34;&gt;(py3.4venv) ➜  py3.4venv  python -m ensurepip --upgrade&lt;br /&gt;/home/thefourtheye/Python/py3.4venv/bin/python: No module named ensurepip&lt;br /&gt;(py3.4venv) ➜  py3.4venv  python&lt;br /&gt;Python 3.4.0 (default, Apr 11 2014, 13:05:11)&lt;br /&gt;[GCC 4.8.2] on linux&lt;br /&gt;Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;So, you need to install, &lt;code&gt;pip&lt;/code&gt; separately, like mentioned in the &lt;a href=&#34;http://pip.readthedocs.org/en/latest/installing.html#install-pip&#34;&gt;pip&#39;s official documentation&lt;/a&gt;. So, the actual list of steps go like this&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;➜  Python  python3 -m venv py3.4venv --without-pip &lt;br /&gt;➜  Python  cd py3.4venv &lt;br /&gt;➜  py3.4venv  source bin/activate&lt;br /&gt;(py3.4venv) ➜  py3.4venv  wget https://bootstrap.pypa.io/get-pip.py&lt;br /&gt;--2014-12-30 14:35:34--  https://bootstrap.pypa.io/get-pip.py&lt;br /&gt;Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 103.245.222.175&lt;br /&gt;Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|103.245.222.175|:443... connected.&lt;br /&gt;HTTP request sent, awaiting response... 200 OK&lt;br /&gt;Length: 1581355 (1.5M) [text/x-python]&lt;br /&gt;Saving to: ‘get-pip.py’&lt;br /&gt;&lt;br /&gt;100%[=====================================================================================================================&gt;] 15,81,355    129KB/s   in 8.9s   &lt;br /&gt;&lt;br /&gt;2014-12-30 14:35:43 (173 KB/s) - ‘get-pip.py’ saved [1581355/1581355]&lt;br /&gt;&lt;br /&gt;(py3.4venv) ➜  py3.4venv  python get-pip.py &lt;br /&gt;Collecting pip&lt;br /&gt;  Downloading pip-6.0.3-py2.py3-none-any.whl (1.3MB)&lt;br /&gt;    100% |################################| 1.3MB 139kB/s &lt;br /&gt;Collecting setuptools&lt;br /&gt;  Downloading setuptools-9.1-py2.py3-none-any.whl (552kB)&lt;br /&gt;    100% |################################| 552kB 180kB/s &lt;br /&gt;Installing collected packages: setuptools, pip&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Successfully installed pip-6.0.3 setuptools-9.1&lt;br /&gt;(py3.4venv) ➜  py3.4venv  deactivate &lt;br /&gt;➜  py3.4venv  source bin/activate                      &lt;br /&gt;(py3.4venv) ➜  py3.4venv  pip install django&lt;br /&gt;Collecting django&lt;br /&gt;  Using cached Django-1.7.1-py2.py3-none-any.whl&lt;br /&gt;Installing collected packages: django&lt;br /&gt;&lt;br /&gt;Successfully installed django-1.7.1&lt;br /&gt;(py3.4venv) ➜  py3.4venv  which pip&lt;br /&gt;/home/thefourtheye/Python/py3.4venv/bin/pip&lt;br /&gt;(py3.4venv) ➜  py3.4venv  &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Sending POST/PUT requests, with JSON form body, in Node.js</title>
      <link>https://thefourtheye.in/posts/2014/09/15/sending-postput-requests-with-json-form/</link>
      <pubDate>Mon, 15 Sep 2014 21:05:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2014/09/15/sending-postput-requests-with-json-form/</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 one of my friends asked me to help him with sending a PUT request to a remote server, in Node.js. I started Googling and as usual I found this &lt;a href=&#34;http://stackoverflow.com/a/11298667/1903116&#34;&gt;excellent Stackoverflow answer&lt;/a&gt;.&lt;pre class=&#34;prettyprint&#34;&gt;var http = require(&#39;http&#39;);&lt;br /&gt;&lt;br /&gt;var options = {&lt;br /&gt;host: &#39;localhost&#39;,&lt;br /&gt;path: &#39;/users/1&#39;,&lt;br /&gt;port: 3000,&lt;br /&gt;method: &#39;PUT&#39;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;var callback = function(response) {&lt;br /&gt;var str = &#39;&#39;;&lt;br /&gt;&lt;br /&gt;//another chunk of data has been recieved, so append it to `str`&lt;br /&gt;response.on(&#39;data&#39;, function(chunk) {&lt;br /&gt;str += chunk;&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;//the whole response has been recieved, so we just print it out here&lt;br /&gt;response.on(&#39;end&#39;, function() {&lt;br /&gt;console.log(str);&lt;br /&gt;});&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;http.request(options, callback).end();&lt;br /&gt;&lt;/pre&gt;This works well. It creates a HTTP PUT request, to the server hosted at localhost on port 3000 and in the path &#39;/users/1&#39;. Now the interesting part is, normally, when we send PUT/POST requests, we used to send parameters. These parameters will be represented normally as key-value pairs. It will be easy to represent them in JSON format. So, the above code just needs few more changes to send the request with a JSON body.&lt;pre class=&#34;prettyprint&#34;&gt;var http = require(&#39;http&#39;);&lt;br /&gt;&lt;br /&gt;var bodyString = JSON.stringify({&lt;br /&gt;    username: &#39;thefourtheye&#39;,&lt;br /&gt;    password: &#39;********&#39;&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;var headers = {&lt;br /&gt;    &#39;Content-Type&#39;: &#39;application/json&#39;,&lt;br /&gt;    &#39;Content-Length&#39;: bodyString.length&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;var options = {&lt;br /&gt;    host: &#39;localhost&#39;,&lt;br /&gt;    path: &#39;/users/1&#39;,&lt;br /&gt;    port: 3000,&lt;br /&gt;    method: &#39;PUT&#39;,&lt;br /&gt;    headers: headers&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// callback is same as in the above seen example.&lt;br /&gt;...&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;http.request(options, callback).write(bodyString);&lt;br /&gt;&lt;/pre&gt;What we are actually doing here is, creating a JSON structure for the form body and then we are converting that to a valid JSON string. This is important, since we are sending the body as a JSON structure, it should conform to the JSON semantics. So, if you printed the bodyString, you would get something like this&lt;pre class=&#34;prettyprint&#34;&gt;{&#34;username&#34;:&#34;thefourtheye&#34;,&#34;password&#34;:&#34;********&#34;}&lt;br /&gt;&lt;/pre&gt;Now, we constructed the body string. But, how will we let the server know that the request is not over immediately after the HTTP Request line and the headers in the HTTP Request.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href=&#34;http://www.tcpipguide.com/free/t_HTTPRequestMessageFormat.htm&#34;&gt;http://www.tcpipguide.com/free/t_HTTPRequestMessageFormat.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&#34;separator&#34; style=&#34;clear: both; text-align: center;&#34;&gt;&lt;a href=&#34;http://www.tcpipguide.com/free/diagrams/httprequest.png&#34; imageanchor=&#34;1&#34; style=&#34;margin-left: 1em; margin-right: 1em;&#34;&gt;&lt;img border=&#34;0&#34; src=&#34;http://www.tcpipguide.com/free/diagrams/httprequest.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As we see in the picture, after the headers section, there is the body section, which is where the body string we generated will be put in. But how will the web-server know the format of the body section and where it actually ends? That is why we put in two &#39;headers&#39; in the &#39;options&#39; object. &lt;pre class=&#34;prettyprint&#34;&gt;var headers = {&lt;br /&gt;    &#39;Content-Type&#39;: &#39;application/json&#39;,&lt;br /&gt;    &#39;Content-Length&#39;: bodyString.length&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here we specify the type of the body and the actual length of it. Okay, now that we specified the type and the length, how are we going to send the string? We simply write it to the &#39;ClientRequest&#39; object returned by the &#39;http.request&#39;, like this &lt;pre class=&#34;prettyprint&#34;&gt;http.request(options, callback).write(bodyString);&lt;br /&gt;&lt;/pre&gt;That is it :-)&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Node.js - modules and exports</title>
      <link>https://thefourtheye.in/posts/2014/03/01/nodejs-modules-and-exports/</link>
      <pubDate>Sat, 01 Mar 2014 09:26:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2014/03/01/nodejs-modules-and-exports/</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;&lt;p&gt;I think most of us haven&#39;t understood the concept of modules in Node.js properly. Let us discuss the basics of that in this post.&lt;/p&gt;&lt;h2&gt;Module System&lt;/h2&gt;&lt;p&gt;In Node.js, when you create a new JavaScript file, that will be considered as a separate module. Inside that module, you can access the module itself with &lt;code&gt;module&lt;/code&gt; object. You can check that, like this&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;console.log(module);&lt;/pre&gt;which produces something like this&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;{ id: &#39;.&#39;,&lt;br /&gt;  exports: {},&lt;br /&gt;  parent: null,&lt;br /&gt;  filename: &#39;/home/thefourtheye/Desktop/Test.js&#39;,&lt;br /&gt;  loaded: false,&lt;br /&gt;  children: [],&lt;br /&gt;  paths:&lt;br /&gt;   [ &#39;/home/thefourtheye/Desktop/node_modules&#39;,&lt;br /&gt;     &#39;/home/thefourtheye/node_modules&#39;,&lt;br /&gt;     &#39;/home/node_modules&#39;,&lt;br /&gt;     &#39;/node_modules&#39; ] }&lt;br /&gt;&lt;/pre&gt;&lt;h2&gt;exports and module.exports&lt;/h2&gt;&lt;p&gt;As you can see, it is just a plain JavaScript object. The important thing to be noted here is, &lt;a href=&#34;http://nodejs.org/api/modules.html#modules_module_exports&#34;&gt;the exports object in module&lt;/a&gt;. In every module, JavaScript, by default, offers another variable called &lt;a href=&#34;http://nodejs.org/api/modules.html#modules_exports_alias&#34;&gt;exports&lt;/a&gt;. That is nothing but the same object in module object of the same name. You can check that like this&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;exports.jabberwocky = &#34;blah blah blah&#34;;&lt;br /&gt;console.log(module.exports);            // { jabberwocky: &#39;blah blah blah&#39; }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;So, they are one and the same. But, when some other module requires this module, the object returned will be module.exports only. As long as you are augmenting module.exports and exports, there will be no problem. But when you assign something to either exports or module.exports, they no longer refer to the same object.&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;exports = {&#34;king&#34;: &#34;Sourav Ganguly&#34;};&lt;br /&gt;console.log(module.exports);           // {}&lt;br /&gt;console.log(exports);                  // { king: &#39;Sourav Ganguly&#39; }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;You are making both exports and module.exports refer to different objects. So, when this module is exported, an empty object will be exported (remember, &lt;b&gt;only module.exports will be exported when required from other files&lt;/b&gt;), even though we assigned a valid object to exports. So, care should be taken when you replace either of those objects. That is the reason why we often see something like this&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;exports = module.exports = ...&lt;br /&gt;&lt;/pre&gt;&lt;h2&gt;Scope&lt;/h2&gt;&lt;p&gt;All the variables and functions declared within the module will be accessible only inside the module (as long as they are created with var keyword). Quoting from the &lt;a href=&#34;http://nodejs.org/api/modules.html#modules_modules&#34;&gt;modules documentation&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;Variables local to the module will be private, as though the module was wrapped in a function.&lt;/blockquote&gt;Happy modularizing the code :)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Bad UI Design - Twitter Account page</title>
      <link>https://thefourtheye.in/posts/2014/01/28/bad-ui-design-twitter-account-page/</link>
      <pubDate>Tue, 28 Jan 2014 20:34:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2014/01/28/bad-ui-design-twitter-account-page/</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;I am going to consider this as a bug in Twitter. When I wanted to change my profile information (in Chrome 32, Ubuntu 13.04), I don&#39;t see a save or update button. Highly frustrating. Hope they fix it soon.&lt;br /&gt;&lt;br /&gt;&lt;div class=&#34;separator&#34; style=&#34;clear: both; text-align: center;&#34;&gt;&lt;a href=&#34;http://1.bp.blogspot.com/-3ZdOmDdBq1w/UufF1ibUsyI/AAAAAAAABck/kDtU8j1hoCk/s1600/Screenshot+from+2014-01-28+20:21:37_new.png&#34; imageanchor=&#34;1&#34; style=&#34;margin-left: 1em; margin-right: 1em;&#34;&gt;&lt;img border=&#34;0&#34; src=&#34;http://1.bp.blogspot.com/-3ZdOmDdBq1w/UufF1ibUsyI/AAAAAAAABck/kDtU8j1hoCk/s640/Screenshot+from+2014-01-28+20:21:37_new.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Un-hiding Menu Bar in Sublime Text 3 - Ubuntu</title>
      <link>https://thefourtheye.in/posts/2014/01/05/un-hiding-menu-bar-in-sublime-text-3/</link>
      <pubDate>Sun, 05 Jan 2014 12:13:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2014/01/05/un-hiding-menu-bar-in-sublime-text-3/</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;&lt;p&gt;&lt;b&gt;Edit on 13-Jan-2016&lt;/b&gt;&lt;br /&gt;I found another easy way to fix this problem. You can toggle the menu with a keyboard shortcut. You can read more about that in &lt;a href=&#34;http://www.thefourtheye.in/2016/01/sublime-text-3-unhiding-menu-in-ubuntu.html&#34;&gt;this blog post of mine&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;It has been a very long wait to get the &#34;Hide Menu&#34; feature in Linux versions of Sublime Text 3. Finally it was released.  But the problem is, if it hidden once, there is no straight forward way to get the Menu back. I tried &lt;kbd&gt;F10&lt;/kbd&gt;, &lt;kbd&gt;Alt&lt;/kbd&gt; etc etc and nothing worked. So, I am sharing the trick which worked for me in this post.&lt;/p&gt;&lt;p&gt;It is simple. Close the Sublime Text 3, if it is open. Open&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;~/.config/sublime-text-3/Local/Session.sublime_session&lt;/pre&gt;in any of your favorite editors and then make sure that, &#34;menu_visible&#34; is &#34;true&#34; in all places in that file.&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&#34;menu_visible&#34;: true,&lt;/pre&gt;Thats it :) Open Sublime Text 3 now and ta-da... Menu is back :)&lt;br /&gt;&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;&lt;b&gt;Edit On Jan 10 - 2016&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;As I was doing the same task more often, I decided that put that in a script, like this&lt;br /&gt;&lt;pre&gt;export FILE=/home/thefourtheye/.config/sublime-text-3/Local/Session.sublime_session&lt;br /&gt;export TEMP_FILE=/home/thefourtheye/.config/sublime-text-3/Local/Session.sublime_session.bkp&lt;br /&gt;sed -e &#39;s/&#34;menu_visible&#34;: false/&#34;menu_visible&#34;: true/g&#39; $FILE &gt; $TEMP_FILE&lt;br /&gt;mv $TEMP_FILE FILE&lt;br /&gt;&lt;/pre&gt;and then I added that to my shell script&#39;s rc file as an alias like this&lt;br /&gt;&lt;pre&gt;alias sublime_fix_menu=~/.sublime_fix_menu.zsh&lt;/pre&gt;That&#39;s it :-) Now, I just have to close Sublime Text 3, type sublime_fix_menu in the shell, open Sublime again :-)&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
