Floating Sun » programming http://floatingsun.net Mon, 07 Jan 2013 02:53:26 +0000 en-US hourly 1 http://wordpress.org/?v=3.5.1 Toying with node.js http://floatingsun.net/2010/08/04/toying-with-node-js/?utm_source=rss&utm_medium=rss&utm_campaign=toying-with-node-js http://floatingsun.net/2010/08/04/toying-with-node-js/#comments Wed, 04 Aug 2010 17:58:34 +0000 Diwaker Gupta http://floatingsun.net/?p=1512 Related posts:
  1. What is node.js?
  2. Whats up with PageRank?
]]>
A commenter rightly complained that despite my claims of “playing around” with node.js, all I could come up was with the example in the man page. I replied saying that I did intend to post something that I wrote from scratch, and as promised, here is my first toy node.js program:

var sys = require('sys');
var http = require('http');
var url = require('url');
var path = require('path');

function search() {
  stdin = process.openStdin();
  stdin.setEncoding('utf8');
  stdin.on('data', function(term) {
    term = term.substring(0, term.length - 1);
    var google = http.createClient(80, 'ajax.googleapis.com');
    var search_url = "/ajax/services/search/web?v=1.0&q=" + term;
    var request = google.request('GET', search_url, {
      'host': 'ajax.googleapis.com',
      'Referer': 'http://floatingsun.net',
      'User-Agent': 'NodeJS HTTP client',
      'Accept': '*/*'});
    request.on('response', function(response) {
      response.setEncoding('utf8');
      var body = ""
      response.on('data', function(chunk) {
        body += chunk;
      });
      response.on('end', function() {
        var searchResults = JSON.parse(body);
        var results = searchResults["responseData"]["results"];
        for (var i = 0; i < results.length; i++) {
          console.log(results[i]["url"]);
        }
      });
    });
    request.end();
  });
}

search();

This program (also available as a gist) reads in search terms on standard input, and does a Google search on those terms, printing the URLs of the search results.

I was quite surprised (and a bit embarrassed) at how long it took me to get this simple program working. For instance, it took me the better part of an hour to realize that when I read something from stdin, it includes the trailing newline (as the user hits ‘Enter’). Earlier, I was using the input as-is for the search term, and that was leading to a 404 error, because the resulting URL was malformed.

Debugging was also harder, as expected. Syntax errors are easily caught by V8, but everything else is still obscure. I’m sure some of the difficulty is because of my lack of expertise with Javascript. But at one point, I got this error:

events:12
        throw arguments[1];
                       ^
Error: Parse Error
    at Client.ondata (http:881:22)
    at IOWatcher.callback (net:517:29)
    at node.js:270:9

I still haven’t figured out exactly where that error was coming from. Nonetheless, it was an interesting exercise. I’m looking forward to writing some non-trivial code with node.js now.

]]>
http://floatingsun.net/2010/08/04/toying-with-node-js/feed/ 3
Must read for all programmers http://floatingsun.net/2007/01/09/must-read-for-all-programmers/?utm_source=rss&utm_medium=rss&utm_campaign=must-read-for-all-programmers http://floatingsun.net/2007/01/09/must-read-for-all-programmers/#comments Tue, 09 Jan 2007 08:11:30 +0000 Diwaker Gupta http://floatingsun.net/blog/2007/01/09/788/ Related posts:
  1. reCAPTCHA: Stop Spam, Read Books
  2. Books I read this year
  3. Must read for grad students
]]>
If you love programming, and you have not read the Tao of Programming, then I’m afraid, you don’t really love programming.

]]>
http://floatingsun.net/2007/01/09/must-read-for-all-programmers/feed/ 0
Whitespace http://floatingsun.net/2005/08/12/whitespace/?utm_source=rss&utm_medium=rss&utm_campaign=whitespace http://floatingsun.net/2005/08/12/whitespace/#comments Fri, 12 Aug 2005 06:22:47 +0000 Diwaker Gupta http://floatingsun.net/blog/2005/08/12/whitespace/ Related posts:
  1. Udaan and Whitespace
  2. sundry sunday
  3. More on the new theme
]]>

Some people clearly have way too much time on their hands — [[http://compsoc.dur.ac.uk/whitespace/|here's a language]] that only allows whitespaces as valid tokens (all other ASCII characters are treated as comments!)

But seriously, this is //cool//. And the first interpreter is written in Haskell. Wow.

]]>
http://floatingsun.net/2005/08/12/whitespace/feed/ 0
Commenting code http://floatingsun.net/2005/08/01/commenting-code/?utm_source=rss&utm_medium=rss&utm_campaign=commenting-code http://floatingsun.net/2005/08/01/commenting-code/#comments Mon, 01 Aug 2005 20:20:19 +0000 Diwaker Gupta http://floatingsun.net/blog/2005/08/01/commenting-code/ Related posts:
  1. Code updates
  2. The Quixtar Post
  3. Source code search engines
]]>

Via [[http://slashdot.org|Slashdot]], [[http://particletree.com/features/successful-strategies-for-commenting-your-code|Successful strategies for commenting your code]]

For some humor, see my [[http://floatingsun.net/blog/2005/06/17/funny-source-code-comments/|earlier post on funny source code comments]]

]]>
http://floatingsun.net/2005/08/01/commenting-code/feed/ 1
Funny source code comments http://floatingsun.net/2005/06/17/funny-source-code-comments/?utm_source=rss&utm_medium=rss&utm_campaign=funny-source-code-comments http://floatingsun.net/2005/06/17/funny-source-code-comments/#comments Fri, 17 Jun 2005 20:22:16 +0000 Diwaker Gupta http://floatingsun.net/blog/2005/06/17/funny-source-code-comments/ Related posts:
  1. Source code search engines
  2. Commenting code
  3. rec.humor.funny
]]>

* [[http://www.kuro5hin.org/story/2004/2/15/71552/7795|We are morons]]
* [[http://blog.contentious.com/archives/2004/02/22/creative-code-commentators|Creative code commentators]]
* [[http://www.freevbcode.com/ShowCode.Asp?ID=2547|How to write unmaintanable code]], originally [[http://mindprod.com/jgloss/unmain.html|here]]

]]>
http://floatingsun.net/2005/06/17/funny-source-code-comments/feed/ 1
I’m a linguist (again!) http://floatingsun.net/2005/05/26/im-a-linguist-again/?utm_source=rss&utm_medium=rss&utm_campaign=im-a-linguist-again http://floatingsun.net/2005/05/26/im-a-linguist-again/#comments Thu, 26 May 2005 23:25:00 +0000 Diwaker Gupta http://floatingsun.net/blog/?p=101 Related posts:
  1. I’m a linguist (again!)
  2. Computerworld Development Survey
  3. Must read for all programmers
]]>

The last time I was on a language learning spree was back at [[http://www.iitk.ac.in|IIT Kanpur]]. We had this course in our 3rd year, called Programming Languages, Tools and Techniques. It was like a crash course whirl-wind tour of a myriad of, well, programming languages, tools and techniques — Perl scripting, CGI, shell scripting, decoding ELF files, latex etc etc.

Somehow things worked themselves in such a way that this quarter I got to lay my hands on two entirely new and really funky languages — [[http://python.org|Python]] and [[http://rubycentral.com|Ruby]]. Though Python is not as funky as Ruby, I really love it. Ruby is darn cool! And I think I will have occasion to visit our old friend Perl.

I found some great links on scripting languages:

* [[http://home.pacbell.net/ouster/scripting.html|John Ousterhout on Scripting Languages]]
* [[http://www.ifi.uio.no/in228/lecsplit/|Notes on problem solving using high level scripting languages by Hans Petter Langtangen]]

]]>
http://floatingsun.net/2005/05/26/im-a-linguist-again/feed/ 0
Computerworld Development Survey http://floatingsun.net/2005/04/04/computerworld-development-survey/?utm_source=rss&utm_medium=rss&utm_campaign=computerworld-development-survey http://floatingsun.net/2005/04/04/computerworld-development-survey/#comments Mon, 04 Apr 2005 21:28:39 +0000 Diwaker Gupta http://floatingsun.net/blog/2005/04/04/computerworld-development-survey/ Related posts:
  1. I’m a linguist (again!)
  2. WP-Dokuwiki development update
  3. I’m a linguist (again!)
]]>

Here’s the [[http://www.computerworld.com/developmenttopics/development/story/0,10801,100542,00.html | survey]]

Here are some of my comments:

* C# seems to be really taking off. [sigh] Now I have learn yet another language. But its fun learning a new language :) However, first I need some interesting project to work on… Will all the talk about [[http://it.slashdot.org/it/05/04/03/0715209.shtml?tid=156&tid=8 | Python moving into the enterprise]] I wonder when it will creep into the top 5 list. Although, somehow even I’m skeptical about writing enterprise application with a language like Python, because it has this scripty, toyish language kind of feel, and something like Java just seems so much more mature and organized. Other factors like IDE and debugging support also make a lot of difference I guess.
* It was interesting to see that open source software is being used more and more in the industry. My take is that commoditized software (like mailing list managers, web servers) are going to be completely dominated by open source. Niche software (like simulation tools, CRM/ERP apps) will still face competition from propritary vendors.
* Everyone seems to be confused about the future of 64-bit. Its obvious that eventually everything will be 64, but recent moves by the industry (IBM withdrew support for the Itanium, for instance) has not done much to bolster confidence in this new architecture.
* UML is going down. I guess that era of software engineering is coming to an end. What is going to be the future in this area? With languages like Python around, I think prototyping will become a much more predominant development model.

]]>
http://floatingsun.net/2005/04/04/computerworld-development-survey/feed/ 0
I’m a linguist (again!) http://floatingsun.net/2004/05/26/im-a-linguist-again-2/?utm_source=rss&utm_medium=rss&utm_campaign=im-a-linguist-again-2 http://floatingsun.net/2004/05/26/im-a-linguist-again-2/#comments Wed, 26 May 2004 06:46:24 +0000 Diwaker Gupta http://floatingsun.net/blog/?p=167 Related posts:
  1. I’m a linguist (again!)
  2. Computerworld Development Survey
  3. Must read for all programmers
]]>

The last time I was on a language learning spree was back at IIT Kanpur. We had this course in our 3rd year, called Programming Languages, Tools and Techniques. It was like a crash course whirl-wind tour of a myriad of, well, programming languages, tools and techniques — Perl scripting, CGI, shell scripting, decoding ELF files, latex etc etc.

Somehow things worked themselves in such a way that this quarter I got to lay my hands on two entirely new and really funky languages — [[http://python.org|Python]] and [[http://rubycentral.com/|Ruby]]. Though Python is not as funky as Ruby, I really love it. Ruby is darn cool! And I think I will have occasion to visit our old friend Perl. I found some great links on scripting languages:

* [[http://home.pacbell.net/ouster/scripting.html|John Ousterhout on Scripting Languages]]
* [[http://www.ifi.uio.no/in228/lecsplit/|Notes on problem solving using high level scripting languages by Hans Petter Langtangen]]

]]>
http://floatingsun.net/2004/05/26/im-a-linguist-again-2/feed/ 0