Shoot yourself in the foot using c#

I’m drunk, way past the Ballmer peak, and now, I need to explain to you in detail how to shoot yourself in the foot with C#, following the concept “Program to an interface”. You can take me for granted or try it for yourself if you don’t believe it. This is the prelude to a “Let your code tell the story” post which will I be writing sometimes in the *khm*distant future*khm*.

First you need to inherit the IFoot interface for both feet, and implement the “placeBullet” method, which accepts bullet object and places it in an aimed Point. Gun class should consist of composite objects such as handle, trigger, aim etc. It aggregates specific bullets which are derived from IBullet interface and hold specific property patterns (which I don’t approve, BTW. They mostly consist of getters and setters). Pulling the trigger causes global event handler invocation. By now you should be getting null reference exception thrown for improper typecasting. As a result you throw your keyboard at your foot which does remotely the same job as intended.

Go foot yourself in the shoot. Now!

Posted in CSharp, General, OOP, Posts in English, Programming | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Absence

I’ve been busy these days, having to battle around with a lot of obligations. Obligations that only waste my time, having done nothing. Mostly college and my personal life. Since I caught some time during these holidays, this post is to prove that I’m still alive and a few more posts are in the making. Tutorial about nginx configuration and OOP concept to see if I understood it correctly. Anyone know how to explain nginx rewrite rules in a baby language? It’s when your plans are not inconsistent, and too much work to be done your mind becomes mushed. But few projects are moving and I’m hoping I’ll get things not only done but efficiently done.

I’m still not done with this blog. But the post is finished though.

Posted in General, Posts in English | 1 Comment

Installing Apache Tomcat on Debian Squeeze

I had some trouble configuring Tomcat server for Java Server Pages(JSP) to work on a particular port on my first install. This post will be brief because there isn’t much work to get the basic configuration going on Debian Squeeze. Basic commands for installing tomcat6 is:

# apt-get update
# apt-get install tomcat6

First command fetches new package list from you repository, and the second fetches tomcat6 package and installs it. Now you have your tomcat6 server installer and running. Tomcat6 is configured to use port 8080 by default. You can verify that it’s up and running by going on to localhost address. Another way, the GUI way, is to fire up synaptic and searching for tomcat6 package then installing it. Same result is expected. I have apache2 installed also, but I wasn’t going to run both of them at the same time so I wanted to switch tomcat from port 8080 to port 80. Stuff became confusing since I thought all I needed to do was edit some configuration files in /etc/tomcat6. I was wrong. That was one of the steps. Since ports from 1-1023 are privileged ports, and not allowed to be used by a non-root user/service, there was one option that needed to be changed. Thanks to the guys from the IRC I managed to enable this. File you need to edit is located at:

/etc/default/tomcat6

You open that file with some editor like nano or vim, and scroll to bottom and find the following line:

AUTHBIND=no

If it’s not there, then add it, and if it’s there it’s most likely commented so uncomment it and set the value to “yes” like this:

AUTHBIND=yes

That enables you to start the server on port 80. Second step is to locate the file:

/etc/tomcat6/server.xml

Find the following line:

<Connector port=”8080″ protocol=”HTTP/1.1″

Change 8080 into your desired port. Save the file and restart the server with the following command:

# /etc/init.d/tomcat6 restart

You don’t want two servers running on the same port so make sure apache2 or some other are stopped before running tomcat on this port. Apache and tomcat are started at boot so what you need to do is to remove one of them from startup. You can use the update-rc.d command on Debian. To remove apache2 from startup use it like this:

# update-rc.d apache2 remove

and to remove tomcat from the startup, type this:

# update-rc.d tomcat6 remove

Of course, you can run multiple HTTP servers at the same time, just make sure you run them on separate ports.
For manual starting or stopping the servers use init scripts in /etc/init.d.
Note1: If you want to run tomcat on ports higher that 1023 “AUTHBIND” option can be set to “no”.
Note2: “#” sign means that all commands must be run as root or at least as privileged user.
P.S. The folder for your web files is located at /var/lib/tomcat6/webapps/ROOT/

Of course this is just a fragment. Next thing you’ll need to do is configure virtual hosts and users. About that some other time.

Posted in GNU/Linux, Java, Posts in English, Web development | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Namespaces in c++

Disecting namespaces

  • What are namespaces?
  • Why use namespaces?

Namespaces are segments of code which contain grouped entities like classes, variable definitions and objects under one name in order to avoid some entities with the same name to collide, which results in redefinition error and build fail. Defined namespaces are usable inside other namespaces. Basic syntax is following:

namespace name
{
    //entities
}

Few examples of namespaces:

namespace one
{
    int a  = 2,b = 3;
}
namespace two
{
    float a=5.5,b = 4.3;
}
namespace three
{
    long multiply()
    {
        using namespace one;
        return a * b;
    }
}
namespace four{
    float multiply()
    {
        using namespace two;
        return a * b;
    }
}
namespace five
{
    float multiply()
    {
        return one::a * two::b;
    }
}

Namespaces are called with “using namespace” keywords followed by namespace name or by calling them by their name followed by “::” and entity which we use, as you can see in the code. Main function can then look like this:

int main(int argc, char** argv)
{
    using namespace std;
    using namespace five;
    cout<<three::multiply()<<endl<<four::multiply()<<endl<<multiply()<<endl;
    return 0;
}

I don’t really see their practical use anywhere besides C# apparently. I don’t think you’ll find yourself in a situation that you must name two variables or functions with the same name. Namespaces are used by library developers to avoid possible name collisions with others. I just thought I could mention them here, you never know when you’ll need them for making someone look confused. I found they’re useful for global variable and object definitions and initializations. Cin and cout are defined that way. Let me know if they can do something that classes don’t already. I thought of testing if they act differently from classes and standard #include directive on compilation time and runtime, but it seems like a drag. Anyways, the end?

Posted in Cpp, OOP, Programming | Tagged , , , , , , , , , , | 1 Comment