2011年11月25日 星期五

[E-Mail] Hotel Reservations

Dear Sir or Madam,

Please reserve a single room with a shower and air conditioning from Jan 1st to Jan 5th, under the name of Jack Hsu.
I'd like you to provide a room on the seventh floor, overlooking the whole city, if possible. I am arriving on the afternoon of Jan 1st and leaving on the morning of the Jan 5th.
An early confirmation for this reservation would be much appreciated.

Sincerely yours,
Jack Hsu

2011年11月24日 星期四

[E-Mail] Train Ticket Reservations

Dear Sir or Madam,

I'd like to book a hard seat for the T123 train from A to B on January 21st.
I hope the tickets for T123 haven't been all booked up on that day, but if the tickets have been sold out, please inform me as soon as possible.

I appreciate your early confirmation.
Sincerely yours,
Jack

[E-Mail] Airline Ticket Reservations

Dear Sir or Madam,

I am going to fly from A to B on the earliest flight. Could I book one economy class seat on a flight leaving A on May 12th?
The Agricultural Bank of China has been instructed to pay the fare and booking fee, and I would ask you to submit your invoice directly to them?

I will appreciate your early confirmation.
Sincerely yours,
Brain

2011年11月15日 星期二

[Unix Programming] Zombie

Zombie: Child process terminates without parent's waiting.
As a result, all you have to do is to wait the child process while terminating.


void waitchild() {
  signal( SIGCHLD, waitchild); // re-enable the signal to fit all systems
  while( wait(NULL) <= 0 )
    /*NOTHING*/;
}


int
main (int argc, char **argv)
{
  signal( SIGCHLD, waitchild);
  if (fork() == 0) {
    // child process
  } else {
    // parent
  }
}

Refer:
http://home.educities.edu.tw/shirock/comp/Anti_zombie_process.htm
http://starryalley.twbbs.org/blog/index.php?/archives/683-linux-zombie-process.html

2011年11月13日 星期日

[Google MAP] Address to Google Map

Address -> longitude and latitude -> KML -> Google Map

Address to longitude and latitude:
http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html

KML:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>

<name>Vincent Cheng</name>
<description><![CDATA[test]]></description>
<Style id="style">
<IconStyle>
<Icon>
<href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>
</Icon>
</IconStyle>
</Style>

<Placemark>
<name>Test1</name>
<description><![CDATA[]]></description>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>120.913872,24.639008,0.000000</coordinates>
</Point>
</Placemark>

<Placemark>
<name>Test2</name>
<description><![CDATA[]]></description>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>120.916405,24.642361,0.000000</coordinates>
</Point>
</Placemark>

</Document>
</kml>

2011年11月8日 星期二

[C] call by value/reference/address

Call by Value, Call by Address(Pointer), C++ includes Call by Reference
http://csie-tw.blogspot.com/2010/03/call-by-valuecall-by-pointercall-by.html

Call by Value:
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(x);
  printf("x=%d\n", x);
}
void foo(int x)
{
  x++;
}

result:
1
1


Call by Address/Pointer:
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(&x);
  printf("x=%d\n", x);
}
void foo(int *x)
{
  (*x)++;
}

result:
1
2


Call by Reference:(C++)
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(x);
  printf("x=%d\n", x);
}
void foo(int &x)
{
  x++;
}

result:
1
2

[C] pointer to function

#include <stdio.h>
#include <stdlib.h>

void func(int);

main(){
      void (*fp)(int);

      fp = func;

      (*fp)(1);
      fp(2);

      exit(EXIT_SUCCESS);
}

void
func(int arg){
      printf("%d\n", arg);
}