The website of Lei Chen

Sunshine and rain of a developer

Archive for May, 2009

How to use C++ Sleep() function under Windows

Posted by hide1713 on May 28, 2009

If you want to sleep 1 second in your program, you should do the following thing

1. #include <windows.h>

2. DWORD dwMillseconds=1000;

3. Sleep(doMillseconds);

Posted in Uncategorized | Leave a Comment »

Concatenate String in #define with # and ##

Posted by hide1713 on May 16, 2009

According to C prefprcessor wiki page, There are two kinds of cacatenation.

# string concatenation combines input string value with other strings.

For example.

#define PRINT_NAME(name) printf(“Hi all, my name is “#name” !\n”)

PRINT_NAME(leo);   –>Hi all, my name is leo !

##  tokens concatenation.

For instance:

#define MYCASE(item,id) \
case id: \
  item##_##id = id;\
break

switch(x) {
    MYCASE(widget,23);
}

The line MYCASE(widget,23); gets expanded here into

case 23:
  widget_23 = 23;
break;

Posted in C | Leave a Comment »

Output eps files from R

Posted by hide1713 on May 10, 2009

R is a very good statistical tools.  This guide teach you how to output eps or other formats from R.

R treats output sources as a device, so we must assign a device first( the default device is X windows).

postscript(“RPlot.eps”, height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = “special”)

plot(1:5)

dev.off()

The firs line opens a device. The second line draws the graph. The third line saves the graph.

Posted in Misc | Leave a Comment »

SSH+SCREEN in one command

Posted by hide1713 on May 2, 2009

I always have to login a ssh shell first and start screen manually. I found a trick to login and start screen in one command. That’s very useful.

ssh -t the_server_alias “screen -d -r”

In order to run this command, you need to configure ssh so that  you don’t need to type password to login. There are many tutorials out there to teach you how to do this. After you can login without password, you want to put the following line in your .bashrc

alias what_every_you_want=”ssh -t the_server_alias \”screen -d -r\”"

That’s it.

Posted in screen | Leave a Comment »

Good Writing Tips

Posted by hide1713 on May 1, 2009

I discovered this good writing tips in Randy Pausch’s website. He is the professor that I respect most. The paper is written by  Marc H. Raibert at January 1985 and the key ideas in this paper remain true today.

The full version of the paper can be found here. It is not very long, so you can read it within 10 minutes. I promise that it is worth your time to read it.  Here are the outlines of this paper

  • You must want to produce good writing.
  • You must have confidence that you can produce good writing.
  • Good writing is bad writing that was rewritten.
  • Spill the beans right away.
  • Don’t be a slave to your prose.
  • Outlining helps to get unstuck.
  • Husband your readers.
  • Trust your readers.

Posted in Uncategorized | Leave a Comment »