Wednesday, September 3, 2008

gen_tcp {packet, http} mode - Erlang

This is a very useful undocumented feature in Erlang and very soon they are going to make it official. But there is nothing to refer in erlang documentation yet, So i thought of writing someting about this. Yaws uses this mode very largely and also, http://www.trapexit.org/A_fast_web_server_demonstrating_some_undocumented_Erlang_features

is a good resource for the people who are further interested in about this mode.

In this mode the http header lines are comming line by line and in a format which is very easy to decode and use.

Passive mode:

You can turn your socket in to passive mode by setting the option {active, false}

Request line:

{ok, {http_request, Method, { absoluteURI, http, URL, undefined, Rest}, {Maj, Min}}}

Method – GET, POST, etc

Keep in mind the full PATH you want to get is: URL ++ Rest

{Maj, MIN} is the digits of the http version (i.e: {1, 1} for HTTP/1.1, {1, 0} for HTTP/1.0) , Maj-Min-integer

A sample request line is given below,

{ok,{http_request,'GET',{absoluteURI,http,"www.google.com",undefined,

"/"},{1,0}}}

Header lines:

{ok, {http_header, _Num, Header_Name, undefined, Value}} - This is common for both request and response.

Header_Name - name of the header usually an atom but for user defined headers it can be a string.

Value - value of the header (string)

End of header:

{ok, http _eoh} – This is common for both request and response.

Response Line:

{ok, {http_response, {Maj, Min}, Code, ResContent}}

{Maj, Min} – Same as in Request line.

Code – http status code (e.g: 100, 200) - integer

ResContent – the status code description. (e.g: OK, Moved temporary) - string

Active mode

tuples like this in active mode:

{http_request, Socket, ...}
{http_response, Socket, ...}
{http_header, Socket, ...}

The other fields will be same as the passive mode. But in future they are going to change this to the following,

{http, Socket, {http_request, ...}}
{http, Socket, {http_response, ...}}
{http, Socket, {http_header, ...}}


The purpose is to make the inner tuples look the same regardless of how they were received.

Wednesday, May 14, 2008

Five Reasons why you should learn Erlang

Here are the 5 resons why you should learn Erlang according to Joe Armstrong who is also the creator of Erlang

• You want to write programs that run faster when you run them on
a multicore computer.
• You want to write fault-tolerant applications that can be modified
without taking them out of service.
• You’ve heard about “functional programming” and you’re wondering
whether the techniques really work.
• You want to use a language that has been battle tested in real
large-scale industrial products that has great libraries and an
active user community.
• You don’t want to wear your fingers out by typing lots of lines of
code.

Thursday, May 8, 2008

What a DREAM it was!!!!!!!!

Today is the last day that we all are being in our University. After to day it's all over. What a memorable period it was. Full of joys. I couldn't believe that there is no longer shouting, screaming, joking at the final year lab. The most beautiful period of life is going to over this way. How can we forget this wonderful period with all the brothers and sisters. It will be safe in our hearts through out our life.

Thursday, March 27, 2008

Trip to Kanneliya

Last two days me and my friends at the university went on a trip to Kanneliya (a biological park nere Galle). Probably it will be the last trip that we are going during our stay at the university. We all had a very nice time with each other. Thank you Asiri and Saminda for providing us meals. And Moththe(Sameera) for the Tea. Ah, Dont forget leva and Sura , the fun they gave @ nite hi hi :) .

I think the most important event is providing the gifts of appreciation to Asiri, Saliya and Saminda who had helped us a lot for the exams (By doing "kuppi") through whole four years. The commitment they put can not be measured by the awards we gave. Thank you very much Asiri, Saliya and saminda for all those things you had done for us. Also thank you Amila for arranging such an event.


Tuesday, March 4, 2008

End of a sweetest episod of life

Now its the last few months at the university. Its really hard to believe that it has now come down to the wire. A four years of sweet memories with my friends. We had Lots of joyful moments, thank you dear friend for all those memories. The best part of it is, now I'm certain that there are bunch of friends who will never let me down, who will be with me for joy and sorrow. Thats the kind of relationship each other had in the university life. Any way thats the life is all about. There is a huge future ahead and I think experience gained here will be very important to deal with it. So dear friends may success will be with you in every part of your life. Hope this is GOOD NITE & not GOOD BYE.

Monday, February 25, 2008

Accesing a veriable defined in another file in C++

This might be a very simple thing to most of the programmers. But I thought of writing this in my blog as I spent half a day finding a way to access a variable in .cpp from another .cpp(without importing the .h or defining as public inside a class.)

suppose the variable we want to access is defined as follows in the original file,

bool flag;

if you want to access this from another .cpp simply you have to do is define it with extern key word in that file,

i.e extern bool flag;

both declarations refer to the same variable "flag".

Friday, February 22, 2008

C++ threading in windows

Any one had trouble in implementing threading in C++(well, I had, as C++ directly not providing threading) . We have to use the treading support in the windows API. But it is bit difficult to directly code to the windows API using "windows.h". while I 'm searching I found the article "C++ And Threads, by Randy Charles Morin" which has implemented the threading in C++ very effectively. If you are interested I recommend you to go through it. here is the link

http://www.kbcafe.com/articles/HowTo.Thread.pdf

Thursday, February 21, 2008

Bug in OpenCV

I wanted to capture an image from the web cam and convert that to gray scale in my application. I use openCV to do that. But when I directly convert the captured image to gray scale it returned a horizontally flip gray image of the original. but if I load an image using cvLoadImage() and then convert it to gray scale there was no problem. No flipping is involved. I think this was a bug in openCV. Correct me if I am wrong.

here is the code that cause the flipping,

CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
IplImage* frame = cvQueryFrame( capture );

IplImage* gray = cvCreateImage( cvGetSize(frame), 8, 1 );
cvCvtColor( frame, gray, CV_BGR2GRAY );

Sunday, February 3, 2008

Einstein's Challenge

Would you like some brainstorming challenge. Here it is. It is often called "Einstein's Puzzle" or "Einstein's Riddle" because it is said to have been invented by Albert Einstein as a boy. Some claim that Einstein said "only 2 percent of the world's population can solve it". But I believe it should be more than 2% if they given sufficient time. so here it is, ENJOY !!!!!!!!!!!!!!!

There are 5 houses in 5 different colors. In each house lives a person with a different nationality. The 5 owners drink a certain type of beverage, smoke a certain brand of cigar, and keep a certain pet. No owners have the same pet, smoke the same brand of cigar, or drink the same beverage.
  • The British lives in the red house.
  • The Swedish keeps dogs as pets.
  • The Danish drinks tea.
  • The green house is on the left of the white house.
  • The green homeowner drinks coffee.
  • The person who smokes Pall Mall rears birds.
  • The owner of the yellow house smokes Dunhill.
  • The man living in the center house drinks milk.
  • The Norwegian lives in the first house.
  • The man who smokes Blend lives next to the one who keeps cats.
  • The man who keeps the horse lives next to the man who smokes Dunhill.
  • The owner who smokes Bluemaster drinks beer.
  • The German smokes prince.
  • The Norwegian lives next to the blue house.
  • The man who smokes Blend has a neighbor who drinks water.
the question is , Who owns the fish?


try it your self, it's fun. Here is the answer..........................

But don't look at it till you finished.




House 1

House 2

House 3

House 4

House 5

Nationality

Norwegian

Dane

Brit

German

Swede

Color

Yellow

Blue

Red

Green

White

Pet

Cats

Horses

Birds

Fish

Dog

Beverage

Water

Tea

Milk

Coffee

Beer

Cigarettes

Dunhill

Blend

Pall Mall.

Prince

Blue Mstr




Thursday, January 31, 2008

Inter department tournament

Today we have participated to our inter department cricket tournament. As we are now in our final year this is the last tournament we are competing in the university. Though our team couldn't make it to the finals, it's a great pleasure to took part in such an event as all the batch mates from different departments had the opportunity have a good time with their friends from other departments. Department of Civil Engineering won the trophy and Department of Mechanical engineering was the runners up.

Wednesday, January 30, 2008

Erlang Rocks

Erlang is a general-purpose concurrent programming language. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. It supports hot swapping so code can be changed without stopping a system. One of the main reasons for using Erlang instead of other functional languages is Erlang's ability to handle concurrency and distributed programming. So why don't you try this. believe me you'll love it .