<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>2013 on thefourtheye.in</title>
    <link>https://thefourtheye.in/posts/2013/</link>
    <description>Recent content in 2013 on thefourtheye.in</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language><atom:link href="https://thefourtheye.in/posts/2013/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Python Dictionary Comprehension</title>
      <link>https://thefourtheye.in/posts/2013/11/17/python-dictionary-comprehension/</link>
      <pubDate>Sun, 17 Nov 2013 13:35:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/11/17/python-dictionary-comprehension/</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;Dictionary comprehensions were &lt;a href=&#34;http://docs.python.org/2.7/whatsnew/2.7.html#other-language-changes&#34; target=&#34;_blank&#34;&gt;backported from Python 3.x to 2.7&lt;/a&gt;. I always have believed that they are very pythonic and functional way of programming. Whenever comprehension is used, mutation of mutable elements (set, dict, list etc) becomes unnecessary and that definitely improves the performance as well. Lets start with a simple dictionary comprehension&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&gt;&gt;&gt; myMatrix = [[1, 100], [2, 200], [3, 300]]&lt;br /&gt;&gt;&gt;&gt; {key:value for key, value in myMatrix}&lt;br /&gt;{1: 100, 2: 200, 3: 300}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here we use unpacking from &lt;code&gt;myMatrix&lt;/code&gt; list and we have used &lt;code&gt;{}&lt;/code&gt; with &lt;code&gt;key:value&lt;/code&gt; notation. This way, we can easily convert a list of lists to a dictionary with dictionary comprehension. Lets look at a complicated example&lt;/p&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&gt;&gt;&gt; myMatrix = [[100, 100], [20, 200], [30, 300]]&lt;br /&gt;&gt;&gt;&gt; {(key + 100 if key &lt; 100 else key):(value/10 if value &gt;= 200 else value/5) for key, value in myMatrix}&lt;br /&gt;{120: 20, 130: 30, 100: 20}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here we use &lt;a href=&#34;http://docs.python.org/2/reference/expressions.html#conditional-expressions&#34; target=&#34;_blank&#34;&gt;conditional expressions&lt;/a&gt; to dynamically decide what the key and the value are going to be.&lt;/p&gt;&lt;h2&gt;Performance&lt;/h2&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&gt;&gt;&gt; def changeDict():&lt;br /&gt;...     newDict = {}&lt;br /&gt;...     for key, value in myMatrix:&lt;br /&gt;...         newDict[(key + 100 if key &lt; 100 else key)] = value/10 if value &gt;= 200 else value/5&lt;br /&gt;...     return newDict&lt;br /&gt;...     &lt;br /&gt;&gt;&gt;&gt; from timeit import timeit&lt;br /&gt;&gt;&gt;&gt; timeit(&#34;{(key + 100 if key &lt; 100 else key):(value/10 if value &gt;= 200 else value/5) for key, value in myMatrix}&#34;, setup=&#34;from __main__ import myMatrix&#34;)&lt;br /&gt;0.7076609134674072&lt;br /&gt;&gt;&gt;&gt; timeit(&#34;changeDict()&#34;, setup=&#34;from __main__ import myMatrix, changeDict&#34;)&lt;br /&gt;0.7484149932861328&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The use of comprehension is slightly faster than the function which adds keys and values to an existing dictionary. This difference will be significant when the &lt;code&gt;myMatrix&lt;/code&gt; has huge amount of data.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Zen of Python by Tim Peters</title>
      <link>https://thefourtheye.in/posts/2013/10/27/zen-of-python-by-tim-peters/</link>
      <pubDate>Sun, 27 Oct 2013 17:20:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/10/27/zen-of-python-by-tim-peters/</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;Python has an Easter Egg :) just try to import &lt;code&gt;this&lt;/code&gt; like this&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;import this&lt;/pre&gt;you ll get this&lt;br /&gt;&lt;pre&gt;The Zen of Python, by Tim Peters&lt;br /&gt;&lt;br /&gt;Beautiful is better than ugly.&lt;br /&gt;Explicit is better than implicit.&lt;br /&gt;Simple is better than complex.&lt;br /&gt;Complex is better than complicated.&lt;br /&gt;Flat is better than nested.&lt;br /&gt;Sparse is better than dense.&lt;br /&gt;Readability counts.&lt;br /&gt;Special cases aren&#39;t special enough to break the rules.&lt;br /&gt;Although practicality beats purity.&lt;br /&gt;Errors should never pass silently.&lt;br /&gt;Unless explicitly silenced.&lt;br /&gt;In the face of ambiguity, refuse the temptation to guess.&lt;br /&gt;There should be one-- and preferably only one --obvious way to do it.&lt;br /&gt;Although that way may not be obvious at first unless you&#39;re Dutch.&lt;br /&gt;Now is better than never.&lt;br /&gt;Although never is often better than *right* now.&lt;br /&gt;If the implementation is hard to explain, it&#39;s a bad idea.&lt;br /&gt;If the implementation is easy to explain, it may be a good idea.&lt;br /&gt;Namespaces are one honking great idea -- let&#39;s do more of those!&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>File Upload with jQuery and Ajax</title>
      <link>https://thefourtheye.in/posts/2013/10/27/file-upload-with-jquery-and-ajax/</link>
      <pubDate>Sun, 27 Oct 2013 16:30:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/10/27/file-upload-with-jquery-and-ajax/</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 requirement is simple. I should be able to upload files to the server with jQuery and ajax. Lets get started.&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&amp;lt;html&amp;gt;&lt;br /&gt;   &amp;lt;form&amp;gt;&lt;br /&gt;     File Description:&amp;lt;input type=&#34;text&#34; id=&#34;desc&#34; /&amp;gt;&lt;br /&gt;     Choose File:&amp;lt;input type=&#34;file&#34; id=&#34;chosenFile&#34; /&amp;gt;&lt;br /&gt;     &amp;lt;input type=&#34;button&#34; id=&#34;submitFile&#34; value=&#34;submitTheFile&#34; /&amp;gt;&lt;br /&gt;   &amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;Now, the real jQuery stuff&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&amp;lt;script type=&#34;text/javascript&#34;&amp;gt;&lt;br /&gt;    jQuery.noConflict();&lt;br /&gt;    jQuery(document).ready(function() {&lt;br /&gt;        jQuery(&#34;#submitFile&#34;).click(function() {&lt;br /&gt;            jQuery.ajax({&lt;br /&gt;                url: &#34;[url to be submitted to]&#34;,&lt;br /&gt;                type: &#34;POST&#34;,&lt;br /&gt;                contentType: false,&lt;br /&gt;                processData: false,&lt;br /&gt;                data: function() {&lt;br /&gt;                    var data = new FormData();&lt;br /&gt;                    data.append(&#34;fileDescription&#34;, jQuery(&#34;#desc&#34;).val());&lt;br /&gt;                    data.append(&#34;chosenFile&#34;, jQuery(&#34;#chosenFile&#34;).get(0).files[0]);&lt;br /&gt;                    return data;&lt;br /&gt;                    // Or simply return new FormData(jQuery(&#34;form&#34;)[0]);&lt;br /&gt;                }(),&lt;br /&gt;                error: function(_, textStatus, errorThrown) {&lt;br /&gt;                    alert(&#34;Error&#34;);&lt;br /&gt;                    console.log(textStatus, errorThrown);&lt;br /&gt;                },&lt;br /&gt;                success: function(response, textStatus) {&lt;br /&gt;                    alert(&#34;Success&#34;);&lt;br /&gt;                    console.log(response, textStatus);&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;        });&lt;br /&gt;    });&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;&lt;/pre&gt;Important things to be noted here are&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;contentType: false,&lt;br /&gt;                processData: false,&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;contentType&lt;/code&gt; will be determined automatically, so we don&#39;t have to set that explicitly and &lt;code&gt;processData&lt;/code&gt; has to be false, otherwise the data will be processed and transformed into a query string, fitting to the default content-type &#34;application/x-www-form-urlencoded&#34;. Next important thing is&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;data: function() {&lt;br /&gt;                    var data = new FormData();&lt;br /&gt;                    data.append(&#34;fileDescription&#34;, jQuery(&#34;#desc&#34;).val());&lt;br /&gt;                    data.append(&#34;chosenFile&#34;, jQuery(&#34;#chosenFile&#34;).get(0).files[0]);&lt;br /&gt;                    return data;&lt;br /&gt;                    // Or simply return new FormData(jQuery(&#34;form&#34;)[0]);&lt;br /&gt;                }(),&lt;br /&gt;&lt;/pre&gt;You can read about FormData &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/FormData&#34;&gt;here&lt;/a&gt;. We basically set the values being submitted. The first parameter is the key and the second parameter is the actual value to be passed. We can get the value of any form field with &lt;pre class=&#34;prettyprint&#34;&gt;jQuery(&#34;#desc&#34;).val()&lt;/pre&gt;expect the files. If we use the same for files, we ll get just the file name instead of the file contents. So, we have to do something like &lt;pre class=&#34;prettyprint&#34;&gt;jQuery(&#34;#chosenFile&#34;).get(0).files[0]&lt;/pre&gt;If we dont want to set individual values and want to pass all the fields in the form, we can simply do &lt;pre class=&#34;prettyprint&#34;&gt;data: new FormData(jQuery(&#34;form&#34;)[0])&lt;/pre&gt;Thats it. Enjoy Ajaxified file upload :)&lt;br /&gt;&lt;b&gt;References:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/FormData&#34;&gt;FormData&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/File&#34;&gt;File&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications&#34;&gt;Using files from web applications&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects&#34;&gt;Using FormData Objects&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Installing the thefourtheyeEditor - topcoder plugin</title>
      <link>https://thefourtheye.in/posts/2013/09/07/installing-thefourtheyeeditor/</link>
      <pubDate>Sat, 07 Sep 2013 13:38:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/09/07/installing-thefourtheyeeditor/</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;thefourtheyeEditor is a very lightweight plugin for Topcoder Arena to participate in Single Round Matches, which can build testcases and lets the users to store the solutions as local files, so that any editor or IDE can be used to edit them. It also maintains the solutions in the directories named as the SRM&#39;s display name.&lt;/p&gt;&lt;h2&gt;Features&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;Very lightweight - Only one jar file. It doesn&#39;t depend on any other external jar files.&lt;/li&gt;&lt;li&gt;Organized solutions storage - Solutions will be stored as per the SRM names&lt;/li&gt;&lt;li&gt;File based configuration - Configurations are done in contestapplet.conf file. No need to use UI.&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Installation&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;Download thefourtheyeEditor plugin (thefourtheyeEditor.jar) from &lt;a href=&#34;https://github.com/thefourtheye/thefourtheyeEditor/releases/download/latest/thefourtheyeEditor.jar&#34;&gt;https://github.com/thefourtheye/thefourtheyeEditor/releases/download/latest/thefourtheyeEditor.jar&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Open topcoder contest applet and login with your username and password&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://3.bp.blogspot.com/-pWmhTKJgMuU/UirZL3XombI/AAAAAAAABaQ/ElKofTOUZLo/s1600/topcoder+Login.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://3.bp.blogspot.com/-pWmhTKJgMuU/UirZL3XombI/AAAAAAAABaQ/ElKofTOUZLo/s1600/topcoder+Login.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;Select &lt;code&gt;Editor&lt;/code&gt; from the &lt;code&gt;Options&lt;/code&gt; menu. You &#39;ll see something like this&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://4.bp.blogspot.com/-i-I4SZM6w0Y/UiraJxyoHjI/AAAAAAAABaY/rsfdcOmIVFc/s1600/topcoder+Editor+Preferences+Empty.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://4.bp.blogspot.com/-i-I4SZM6w0Y/UiraJxyoHjI/AAAAAAAABaY/rsfdcOmIVFc/s1600/topcoder+Editor+Preferences+Empty.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;Click on &lt;code&gt;Add&lt;/code&gt; and you &#39;ll get a window like this. Fill in the details as you see in this picture. Actually you can give any name in the &lt;code&gt;Name&lt;/code&gt;field and in &lt;code&gt;ClassPath&lt;/code&gt; field, you have to locate the &lt;code&gt;thefourtheyeEditor.jar&lt;/code&gt; file using Browse button. &lt;code&gt;EntryPoint&lt;/code&gt; must be exactly the same as &lt;code&gt;thefourtheyeEditor.Main&lt;/code&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://1.bp.blogspot.com/-fYASUa_iIWo/Uiravmk9dJI/AAAAAAAABag/RhTfUoZX-1w/s1600/topcoder+plugin+Information.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/-fYASUa_iIWo/Uiravmk9dJI/AAAAAAAABag/RhTfUoZX-1w/s1600/topcoder+plugin+Information.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;Once these steps are done, the Editor preferences page will look like this&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://2.bp.blogspot.com/-NeWwv8YD2WE/Uird2isJrGI/AAAAAAAABas/tLVrupAZrj8/s1600/topcoder+After+plugin+installation.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://2.bp.blogspot.com/-NeWwv8YD2WE/Uird2isJrGI/AAAAAAAABas/tLVrupAZrj8/s1600/topcoder+After+plugin+installation.png&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;Click on Save button and close that window. That&#39;s it. Installation is complete :)&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Ubuntu bug related to network and power</title>
      <link>https://thefourtheye.in/posts/2013/09/04/ubuntu-bug-related-to-network-and-power/</link>
      <pubDate>Wed, 04 Sep 2013 18:32:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/09/04/ubuntu-bug-related-to-network-and-power/</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;Last week, I faced this weird problem. When my laptop is not connected to a power source (not on battery), I could not connect to LAN network with my LAN cable, but Wi-Fi worked fine. I struggled a lot for a week and then I found a solution in the internet.&lt;br /&gt;&lt;p&gt;All you have to do is to execute this one liner in your terminal.&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;echo on &gt; /sys/class/net/eth1/device/power/control&lt;br /&gt;&lt;/pre&gt;Here &lt;code&gt;eth1&lt;/code&gt; corresponds to my second ethernet interface. It might vary from machine to machine. And if the directories &lt;code&gt;eth&lt;/code&gt;, &lt;code&gt;device&lt;/code&gt; and &lt;code&gt;power&lt;/code&gt; dont exist, you might have to manually create them.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Compiling Node.js scripts in Windows 7 with Sublime Text 3</title>
      <link>https://thefourtheye.in/posts/2013/07/29/compiling-node.js-scripts-in-windows-7-with-sublime-text-3/</link>
      <pubDate>Mon, 29 Jul 2013 19:56:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/07/29/compiling-node.js-scripts-in-windows-7-with-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;This is a continuation of &lt;a href=&#34;http://www.thefourtheye.in/2013/07/Compiling-Cpp-11-Programs-with-Sublime-Text-3.html&#34;&gt;Compiling CPP 11 Programs with Sublime Text 3 in Ubuntu&lt;/a&gt; where we saw how to configure Sublime Text 3 in Ubuntu 13.04 to compile C++ 11 programs. In this post, we ll see how to execute Node.js programs in Windows 7 machine&#39;s Sublime Text 3. I am going to assume that Node.js is installed properly and PATH variable is also set properly. If you are using Windows Installer, we dont have to worry about this. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;We need to create the following directory structure in the User&#39;s home directory &lt;code&gt;AppData\Roaming\Sublime Text 3\Packages\JS\&lt;/code&gt;. In my machine, home directory is &lt;code&gt;C:\Users\[username]&lt;/code&gt;. To know the current user&#39;s home directory, open &lt;code&gt;Cmd.exe&lt;/code&gt; and type &lt;code&gt;echo %userprofile%&lt;/code&gt;. &lt;br /&gt;&lt;li&gt;In that directory, create a file called &#34;JS.sublime-build&#34;. So, the location of the file from the home directory is &lt;code&gt;AppData\Roaming\Sublime Text 3\Packages\JS\JS.sublime-build&lt;/code&gt; You can name the sublime-build file as anything you want. I have simply named it here as JS.&lt;br /&gt;&lt;li&gt;Copy and paste the following text in to it.&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;{&lt;br /&gt; &#34;cmd&#34;: [&#34;node.exe&#34;, &#34;${file}&#34;],&lt;br /&gt; &#34;file_regex&#34;: &#34;^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$&#34;,&lt;br /&gt; &#34;working_dir&#34;: &#34;${file_path}&#34;,&lt;br /&gt; &#34;selector&#34;: &#34;source.js&#34;,&lt;br /&gt; &#34;variants&#34;:&lt;br /&gt; [&lt;br /&gt;  {&lt;br /&gt;   &#34;name&#34;: &#34;Run&#34;,&lt;br /&gt;   &#34;cmd&#34;:[&#34;node.exe&#34;, &#34;${file}&#34;]&lt;br /&gt;  }&lt;br /&gt; ]&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;li&gt;Thats it. Open Sublime Text 3. Click on Tools-&gt;Build System. You should see JS as one of the options. From now on, you can execute node.js scripts simply by pressing Ctrl-B.&lt;br /&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Compiling C&#43;&#43;11 Programs with Sublime Text 3</title>
      <link>https://thefourtheye.in/posts/2013/07/21/compiling-cpp-11-programs-with-sublime-text-3/</link>
      <pubDate>Sun, 21 Jul 2013 16:41:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/07/21/compiling-cpp-11-programs-with-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;For &lt;b&gt;Windows 7&lt;/b&gt;, you may want to read this post &lt;a href=&#34;http://www.thefourtheye.in/2013/07/Compiling-Node.js-scripts-in-Windows-7-with-Sublime-Text-3.html&#34;&gt;http://www.thefourtheye.in/2013/07/Compiling-Node.js-scripts-in-Windows-7-with-Sublime-Text-3.html&lt;/a&gt;&lt;br /&gt;&lt;p&gt;Today I installed Sublime Text 3&#39;s public beta on my Ubuntu 13 and the first thing I noticed is, the inability to compile C++ 11 programs. The obvious problem is, it was missing &lt;code&gt;-std=c++0x&lt;/code&gt; parameter to g++. I tried to figure out how to edit the build parameters of Sublime. After an hour&#39;s struggle managed to figure out.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;You need to create the following file &lt;code&gt;~/.config/sublime-text-3/Packages/C++/C++.sublime-build&lt;/code&gt;. The &lt;code&gt;~&lt;/code&gt; refers to the home directory of the current user.&lt;br /&gt;&lt;li&gt;Now insert the below seen text to that file&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;{&lt;br /&gt; &#34;cmd&#34;: [&#34;g++&#34;, &#34;-std=c++0x&#34;, &#34;${file}&#34;, &#34;-o&#34;, &#34;${file_path}/${file_base_name}&#34;],&lt;br /&gt; &#34;file_regex&#34;: &#34;^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$&#34;,&lt;br /&gt; &#34;working_dir&#34;: &#34;${file_path}&#34;,&lt;br /&gt; &#34;selector&#34;: &#34;source.c, source.c++&#34;,&lt;br /&gt; &#34;variants&#34;:&lt;br /&gt; [&lt;br /&gt;   {&lt;br /&gt;     &#34;name&#34;: &#34;Run&#34;,&lt;br /&gt;     &#34;cmd&#34;:[&#34;bash&#34;, &#34;-c&#34;, &#34;g++ -std=c++0x &#39;${file}&#39; -o &#39;${file_path}/${file_base_name}&#39; &amp;&amp; &#39;${file_path}/${file_base_name}&#39;&#34;]&lt;br /&gt;   }&lt;br /&gt; ]&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;li&gt;Save this file and close it. Sublime will pick up the changes immediately.&lt;br /&gt;&lt;/ol&gt;This will take care of compiling C++ 11 programs. &lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>SPOJ Best Solutions for The Double Helix</title>
      <link>https://thefourtheye.in/posts/2013/06/30/spoj-best-solutions-for-double-helix/</link>
      <pubDate>Sun, 30 Jun 2013 18:08:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/06/30/spoj-best-solutions-for-double-helix/</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;Unforgettable day. Got my solution featured, as one of the best Python solutions to &#34;&lt;a href=&#34;http://www.spoj.com/problems/ANARC05B/&#34;&gt;The Double Helix&lt;/a&gt;&#34; problem. &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/-wzk1jclGSXQ/UdAmerJssFI/AAAAAAAABYk/pb3O4uzgCmk/s1280/SPOJ+Top+20.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/-wzk1jclGSXQ/UdAmerJssFI/AAAAAAAABYk/pb3O4uzgCmk/s1280/SPOJ+Top+20.png&#34; style=&#34;max-width: 100%; max-height: 100%;&#34; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Project Euler - 15 - Lattice paths</title>
      <link>https://thefourtheye.in/posts/2013/06/15/project-euler-15-lattice-paths_15/</link>
      <pubDate>Sat, 15 Jun 2013 21:22:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/06/15/project-euler-15-lattice-paths_15/</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;In this post we are dealing with &lt;a href=&#34;http://projecteuler.net/problem=15&#34;&gt;Project Euler - 15 - Lattice paths&lt;/a&gt;. This is one of the simple dynamic programming problems. We have to find the number of paths to reach the bottom right from the top left, moving only downwards and right sidewards. It was not so easy for me to see the solution even for the sample data given. It would be easy when we look from the bottom-left. For the sample 2x2 grid, lets say the bottom-left (2, 2) point has 0 path and 1,2 and 2,1 have 1 path each. It is evident that number of paths to reach (2, 2) from all the points on the bottom most row (0, 2), (1, 2) and the right most column (2, 0), (2, 1), as we cannot move upwards and left sidewards. Now, (1, 1) has two paths to reach (2, 2), either through (1, 2) or (2, 1). So it has the value 2. Same way, (0, 1) and (1, 0) have 3 ways ( (0, 1) can take (1, 1) (which has 2 paths to (2, 2) ) and (0, 2) (which has 1 path to (2, 2) ). So, (0, 0) has 6 paths to (2, 2) either via (0, 1) or via (1, 0). Applied this idea as a dynamic programming program and it solved this problem.&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;Total = 21&lt;br /&gt;&lt;br /&gt;Array = [[0]*Total for i in xrange(Total)]&lt;br /&gt;for i in xrange(Total): Array[i][Total - 1], Array[Total - 1][i] = 1, 1   #Initializing bottom row and right column with 1&lt;br /&gt;&lt;br /&gt;def Rec(i, j):&lt;br /&gt;    global Array&lt;br /&gt;    if Array[i][j]: return Array[i][j]&lt;br /&gt;    Rec(i+1, j)&lt;br /&gt;    Rec(i, j+1)&lt;br /&gt;    Array[i][j] = Array[i+1][j] + Array[i][j+1]&lt;br /&gt;&lt;br /&gt;Rec (0, 0)&lt;br /&gt;print Array[0][0]&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Project Euler - 14 - Longest Collatz sequence - memoization</title>
      <link>https://thefourtheye.in/posts/2013/06/15/project-euler-14-longest-collatz-sequence-memoization/</link>
      <pubDate>Sat, 15 Jun 2013 18:56:00 +0530</pubDate>
      
      <guid>https://thefourtheye.in/posts/2013/06/15/project-euler-14-longest-collatz-sequence-memoization/</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 about the &lt;a href=&#34;http://projecteuler.net/problem=14&#34;&gt;Project Euler - 14 - Longest Collatz sequence&lt;/a&gt; problem. This is one of the perfect examples of memoization technique. This is the actual problem.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;The following iterative sequence is defined for the set of positive integers:&lt;br /&gt;&lt;br /&gt;n → n/2 (n is even)&lt;br /&gt;n → 3n + 1 (n is odd)&lt;br /&gt;&lt;br /&gt;Using the rule above and starting with 13, we generate the following sequence:&lt;br /&gt;13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1&lt;br /&gt;&lt;br /&gt;It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.&lt;br /&gt;&lt;br /&gt;Which starting number, under one million, produces the longest chain?&lt;br /&gt;&lt;br /&gt;NOTE: Once the chain starts the terms are allowed to go above one million.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h2&gt;Simple Solution&lt;/h2&gt;&lt;br /&gt;The problem statement looks pretty simple and a brute force will work just fine. This code runs in 20 seconds.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&lt;br /&gt;def Series(N):&lt;br /&gt;    Counter = 1&lt;br /&gt;    while N != 1:&lt;br /&gt;        N = N/2 if N % 2 == 0 else 3*N+1&lt;br /&gt;        Counter += 1&lt;br /&gt;    return Counter&lt;br /&gt;&lt;br /&gt;Max, Element = 0, 0&lt;br /&gt;for x in xrange (1, 1000000):&lt;br /&gt;    series = Series(x)&lt;br /&gt;    if (Max &amp;lt; series):&lt;br /&gt;        Max = series&lt;br /&gt;        Element = x&lt;br /&gt;&lt;br /&gt;print Max, Element&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As I had to wait for 20 seconds to get the solution, I was thinking about improving the performance. Then I found this. From the problem statement, &lt;code&gt;13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1&lt;/code&gt;, starting with any number, if it becomes 13 at any point of time, it has to take the same route and if it becomes 13 it will take 10 steps to become 1. So I wanted to store this information first time itself, so that I don&#39;t have to recalculate. This is called &lt;code&gt;Memoization&lt;/code&gt;. Quoting from wikipedia&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;In computing, memoization is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously processed inputs&lt;/blockquote&gt;&lt;br /&gt;&lt;h2&gt;Optimized (Memoized) Solution&lt;/h2&gt;&lt;br /&gt;To optimize it, I just had to change the Series function alone. I stored the computed values in a dictionary and if the current number in the sequence happens to be in the dictionary, I ll just return the value corresponding to it. This program responded with the result in 2 seconds. That is &lt;b&gt;10 times faster&lt;/b&gt; than the first version.&lt;br/&gt;&lt;br /&gt;&lt;pre class=&#34;prettyprint&#34;&gt;&lt;br /&gt;Dict = {}&lt;br /&gt;&lt;br /&gt;def Series(N):&lt;br /&gt;    Counter = 1   #It is 1, because we are counting the initial N&lt;br /&gt;    Original = N&lt;br /&gt;    while N != 1:&lt;br /&gt;        N = N/2 if N % 2 == 0 else 3*N+1&lt;br /&gt;        if N in Dict:                    # Check if the length has been computed for this number already&lt;br /&gt;            Counter += Dict[N]           # Add it to the current length counter&lt;br /&gt;            Dict [Original] = Counter    # Store the computed value for future look back&lt;br /&gt;            return Counter&lt;br /&gt;        Counter += 1&lt;br /&gt;    Dict [Original] = Counter            # Store the computed value for future look back&lt;br /&gt;    return Counter&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
