2012年11月8日星期四

Redirecting Console Outputs in Visual Studio

Instead of writing the file stream objects into your code, a simpler solution is to redirect the output just like the pipeline in Linux.

Basically, you just have to go to project properties -> Debugging -> Command Arguments, and add:
"> Output.txt".

Here is a nice post for it:
http://asawicki.info/news_1496_redirecting_output_to_file_in_visual_c.html

2012年10月11日星期四

Make LaTeX floats behave better

LaTeX floating objects can easily give me headaches. Today I saw this link:

http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html

It provides a set of really neat commands to put in the beginning of your document, and all of a sudden the floats behave so nicely now :-)


% Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9} % max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07} % allow minimal text w. figs
    %   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7} % require fuller float pages
 % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7} % require fuller float pages

 % remember to use [htp] or [htpb] for placement

2012年10月5日星期五

LaTeX centering a table that is larger than text width

Had this problem today with my thesis proposal, and luckily the solution is not hard to find:
http://mathandprogramming.blogspot.com/2011/07/latex-centering-table-larger-than.html

You basically need to use a package called chngpage and add an environment surrounding the table:

% allows for temporary adjustment of side margins
\usepackage{chngpage}

\begin{table}
    \begin{adjustwidth}{-.5in}{-.5in}  
        \begin{center}
        \begin{tabular}{|c|}
           % really wide table here
        \end{tabular} 
        \caption{This way the caption will also be the same width as the table, wider than the other text. }
        \label{myTable}
        \end{center}
    \end{adjustwidth}
\end{table}

2012年9月25日星期二

Find and replace a word in all the text document

So some day I need to replace a word to another one for all the XML file in a folder. I was like OK I'll write a C++ code. There goes another hour of my working time then.

Then I received this piece of code from a colleague:
find . -name "*.xml" -exec perl -pi.org -e 's/DICOMIO/CartoXP/' {} \;

Works like a charm.

Also, a linux command line to check how many cores do you have:
cat /proc/cpuinfo | grep processor | wc -l

2012年7月6日星期五

I just need to share this one....

So today I was browsing 9GAG, saw a post like: telnet this and enjoy, starwars fans :-)

So I tried:

telnet towel.blinkenlights.nl

Most epic ASCII stuff ever made.

2012年6月17日星期日

How to use nice colors in Matlab Plot

One major problem I always had in Matlab plotting is that other than the "default" 6-7 colors, it's hard to use different colors.

I just found a really nice solution:
http://scslin.blogspot.com/2011/09/matlab-plot-with-more-colors.html

Basically, you first download a small function "rgb" from:
http://www.mathworks.com/matlabcentral/fileexchange/24497-rgb-triple-of-color-name-version-2

Then, you can call:
plot(x,y,'color',rgb('olive'));


You will be able to draw a line using a "olive" color.
The available colors are as follows:


2012年5月15日星期二

Some useful functions for subplot in Matlab

So there are two things that the subplot function in Matlab can not do.

1. Generate an "overall" title on the top of all sub-figures.
2. Make the sub-figures as compact as possible (usually very large margins will be made).

Normally, what we can do is save each sub-figure as eps or pdf, and use LaTeX to organize them. This works well and I highly recommend this way when you are preparing publication ready figures, but there are times that you just want to generate some report quickly and nicely.

So I found this two nice functions in Matlab file exchange:
1. mtit. This one will place a title automatically for you on top of everything.
2. subaxis. This one does roughly the same thing as "subplot", but with options that enables you to remove margins.

2012年5月9日星期三

Upload images to our BBS abroad

Seems that our BBS can not allow we to upload image from other countries...
OK. This script can bypass the IP checking and do the uploading. It is developed by Zimu Liu.

#!/bin/sh

if [ -z "$1" ]; then
 echo "Usage:  ./`basename \"$0\"` "
 exit -1
fi

FULLPATH="$1"
if [ ! -r "$FULLPATH" ]; then
 echo "File does not exist, or you do not have read privilge!"
 exit -1
fi

FILESIZE=$(cat "$FULLPATH" | wc -c)
if [ $FILESIZE -ge 300000 ]; then
 echo "The size of file exceeds 300000 bytes!"
 exit -1
fi

FILENAME="`basename "$1"`"
EXT=$(echo $FILENAME | grep -i .gif$ || echo $FILENAME | grep -i .jpg$)
if [ -z "$EXT" ]; then
 FILENAME="$FILENAME.jpg"
fi

URL=$(curl -F "up=@${FULLPATH};filename=c:\\${FILENAME}" \
 -F MAX_FILE_SIZE=300000 -F board=C_Computer -F level=0 -F live=9999 -F "exp=" \
 bbs.njupt.edu.cn/cgi-bin/bbsdoupload \
 | tr -d "\015" | tr -d "\012" \
     | sed "s/^$//g")

echo "\nCopy the following URL to your brower:\n"
echo "http://bbs.njupt.edu.cn/cgi-bin/$URL\n"


Solving the LaTeX error: "Too many unprocessed floats"

Yesterday I generated a LaTeX document using Matlab script. This document have about 50 tables, with even table embedded with 30 images. So LaTeX thought that it I can't handle this much floating objects.

I searched around on the internet and found the best solution for me is to add
\clearpage
after every table. This command will force LaTeX to dump all the cached floating objects till here. So basically it will print one table per page, which is fine in my case.

2012年3月31日星期六

Kindle菜单乱码问题简单解决方案

Kindle看中文电子书最大的头痛就是菜单有如完形填空,我最喜欢的作家钱锺书居然能变成三个框框,各种纠结。当时上网找方案基本都是教唆我越狱,实在嫌麻烦。今天在网上找到了一个超级方便的,特此留底。

源链接:

解决办法很简单,就是改变默认的语言设置,输入以下命令即可:

;debugOn
~changeLocale zh-CN
;debugOff

输入时要注意大小写,具体输入步骤是:在home页面,先按下回车(也就是方向键旁边那个弯弯箭头键),会出现一个输入框,输入第一条命令后,回车,再输入第二条,再回车,再第3条回车。这样就设置成功了,然后重启kindle 3。

重启步骤:home -> Menu -> Settings -> Menu -> Restart

也就是进入设置那里再按MENU选择restart重启,或者直接滑动那个关机键按住15秒左右就重启了。

重启之后就感觉世界终于清净了,不仅Home里面所有书名都完整显示了,而且之前一直乱码的告别天堂也终于没问题了。

2012年2月8日星期三

Paper writing notes learned from Dr Thompson

Today I received another thorough editing from Dr Paul Thompson. I found some pattern that I think I should keep in mind for later.

1. In .bib files, when you need some character to be in Cap in the generated PDF, e.g. "fMRI" somewhere in the title, do the following in the .bib file: "f{MRI}".

2. The use of tenses! Make them consistent!

3. Dr Thompson seems to have an issue with "utilize", he changed all of them to "use"... I thought "utilize" sounds cooler :-(

4. "More details can be found..." is always changed into "More details may be found..."

5. Things like "achieves the best performance..." is always changed into "perform the best...". I think he don't like to convert verbs into nouns...

6. Do not say "our method can benefit../will be able to...". Say it with proud: "our method benefits.../will..."

7. He generally likes the sentence to be concise. E.g., "if utilizing all these additional information will be beneficial for classification..." is changed to: "if this additional information can help classification..."

8. "The results are summarized in...." is always changed into "Results are summarized in...", not sure why though...

9. He does not like "As we can observe from the Table..."; these are changed to "As we see in Table...". But Sherlock always tells us to observe T__T