Irony of language fondness

There is an irony about fondness of language in a programmer’s life. I am not very particular about any programming language, I can read and understand and code in quite a few of those. But, my affection is not same for every language I know, and there is the irony.
My favorite language is C++. It is one of the most powerful languages that we have in the industry. It is multi-paradigm and can be used to solve many, if not all, programming problems. Most importantly, to me, C++ sounds very sweet.
On the other hand, there is C#. It has a very strong affiliation with Microsoft and Windows platform and people are prejudiced about it. Nevertheless, it requires proprietary .Net framework to run on top of. Despite these, C# is an amazing language. Its creator had the opportunity to look back into a long history of many languages and decide very carefully from the experiences we had in last half century. So, C# ended up accommodating a plethora of language features, both in terms of capabilities and syntax. I am very fond of C#.
My current job requires me to program in Java. When, I was first introduced to Java when I was a sophomore I became very fond to it. But, then I learned about C# and C++’s wonders kept on unraveling to me. So, I distanced myself from Java, for more than four or five years, until my MS coursework required me into using it. Now, here is the irony! I started my new job here, in Long Island, and my day to day primary language is now Java. I kept rediscovering a lot of facts about Java, and I started to like it again. Specially, Java 8 brings a lot of things I’d like a high level programming language to have. I am learning new things everyday, and would keep learning about them.
So, the irony is, C++ is my favorite language, I admire C# and my primary language is turning out to be Java. Behold, that is not the end of it. I also have to know JavaScript and Python and PHP and happen to like all of them, more or less. And off course, all these languages have their own utilities.
In the end of the day, it occurs to me that, fondness of languages do not matter after all. Every languages have a lot of things to know about and I’d like to be fluent in at least one of them. I just don’t know which one it is going to be!

Originally posted as a Facebook Note. Continue reading

Running Node.js app as a service forever

When you start a Node.js server simply using node app.js, the server stops as soon as the shell session is killed. But if you want to keep you server running, as a server would naturally should, you need some way to keep the server proc alive.

Forever is seemingly a popular choice for running a server, as the name suggests, forever; or technically as long as you want.

While trying to install Forever, globally, via npm, it was complaining about the version number of inherits. So I did:

sudo npm install inherits -g

and then did:

sudo npm install -g forever

You are ready to run a nodejs server forever. Hence, do this:

 forever start --minUptime 1000 --spinSleepTime 1000 app.js

To make sure your new service is up

forever list

And if you want to stop, use

forever stop <PID/PID>

Node.js server on Azure

It is easy to use Node.js on a CentOS VM running on Azure, or any other linux VM on Azure. You can simply yum (with EPEL) install Node.js. Then an easy way to check if everything is working fine, a good idea is to test running a server from node. I am using this simple snippet:

var http = require('http')

var server = http.createServer(function (req, response){
  response.writeHead(200, {"Content-Type":"text/plain"});
  response.end("Hello World");
});

server.listen(8080);

Now you can start it by typing

node app.js

To access this server that you just started, you need to access this port. This server is listening to port 8080. So you need to enable an endpoint on you Azure VM. Go to Microsoft Azure > yourazurevm > Settings > Endpoints and click add.
Capture
Then set following:
Capture
Endpoint: Any name (e.g. Http 8080)
Protocol: TCP
Public port: 8080
Private port: 8080

Now, hit okay and wait for the VM to enable this endpoint (a.k.a. port).

Capture

After this is enabled, you can now go to http://yourazurevm.cloudapp.net:8080/ and see hello world.

List methods from a source file

Sometimes source files can become quite large. This is common mostly in C. But this may happen in other languages too. It makes working with these files particularly hard. Off-course there are IDEs which lists method and properties and what not. But there is a fun way to do the same stuff using python. The regex for the signature of Java methods is, (public|protected|private|static|\s) +[\w\\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;]) You can use this regex in python and have some fun summarizing your Java source files. Here is the script: on Github and via Gist, Cheers!


CLI package installation on Cygwin

Cygwin officially gives a vague answer about where there is a command-line installer for it or not. A quick search gave two options: cyg-apt (last updated in 2009) and apt-cyg (currently maintained). I’d try apt-cyg.

lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin

And you are all set.
If you do not have wget, install it.

apt-cyg install wget

Cheers!