如何让Excel 的Pivot表使用多张表的内容

1. Pivot是不支持多张表的内容做分析的,但是我们可以通过Excel的”Microsoft
Query”导入多张表的数据,通过SQL将多张表中需要的数据生成一张表就可以了。

2. “Microsoft Query”也可以导入Excel中的表格,但是事先要在Excel中创建自己的表格(选中需要的数据,右键选择Name a
Range,起一个名字就好了)

具体的可参见:

http://www.excel-easy.com/examples/microsoft-query.html

在C/C++中如何然程序停住,等待debugger

使用下面的代码片断
1 . 程序的输出被重定向

char command[255];
sprintf(command, "echo pid: %d > /tmp/pid.txt\n", getpid() );
system(command);
sleep(60);

在这里你需要tail -f /tmp/pid.txt来查看文件的内容是否发生了变化。
2 . 程序的输出没有被重定向

printf("pid is: %d", getpid());
getchar();

3 . 使用gdb attach pid来debug就可以了。

tmux的一些使用命令

tmux
1. yum install tmux
2. start
tmux attach session-name
tmux
3. exit
Ctrl+b d #detach
Ctrl+b & #close
4. split screen
Ctrl+b ” #horizonal split
Ctrl+b % #vertical split
exit #exit split window
5. support 256 color
export TERM=xterm-256color, then run tmux
add set -g default-terminal “screen-256color” in ~/.tmux.conf, then run tmux
-2
6. redine Ctrl+b
add set-option -g prefix C-a in ~/.tmux.conf
7. switch in windows
Ctrl+b [0-9]
8. switch in panels
Ctrl+b arrow key
Note:但是用于我的工作环境会设置很多环境变量和启动新的shell,在使用tmux的过程中遇到很多问题,所以不得不弃之。

如何找出大的工程的源文件并进行打包

  1. 如果使用git的话,可以使用下面的命令得到所有git管理的文件
    git ls-files >files.txt

  2. 然后通过下面的命令找出你care的文件
    egrep "\.[Cc]pp$|\.hpp|\.[cChH]$|\.java$|\.[xX]ml|\.properties|\.rb$|\.py$|\.sh$|\.MF$" files.txt > file2.txt

  3. 通过下面的命令将他们打包
    zip 7.0_bl196.zip -@ < file2.txt

gvim的一些设置和tips

功能 方法
到文件第一行 :1
到文件最后一行 G
新建文件 :enew

:w filename
保存gvim的font设置 | 1.search it
:set gfn?
guifont=Mono Uralic 10
2. save it to .gvimrc
vi ~/.gvimrc
set gfn=Mono\ Uralic\ 10
列选择 | CTRL-V
|
do what you want

Fail safe vs Fail fast

“Fail safe” means: it won’t fail.
“Fail fast” means: it may fail
(只是有可能,所以,有时也不会fail,例如你在使用iterator遍历到数组的最后一个元素时,数组被删除了一个元素,这时候是不会fail的) … and
the failure condition is checked aggressively so that the failure condition is
detectedbefore damage can be done.
The alternative to “fail safe” and “fail fast” is to fail unpredictably; e.g.
to sometimes give the wrong answer or throw some unexpected exception. (This
was the behaviour of some standard implementations of the Enumeration API in
early versions of Java.)
… and are they different from the iterator we use for collection.
No. These are properties of the Iterators implemented by standard Collection
types; i.e. they are either “fail fast” or “fail safe” … when used correctly
with respect to synchronization and the Java memory model. (By contrast, if
you use an non-concurrent Iterator or Collection without the correct external
synchronization, all bets are off …)
Also what is the name of iterator we normally use to iterate.
Umm … the actual class name depends on how you got the Iterator, as do the
Iterator’s properties; e.g. “fail fast” versus “fail safe”. For the standard
classes and iterators obtained using the iterator() method, the properties are
specified by the collection classes javadocs.
… how are they implemented.
The fail-fast iterators are typically implemented using a volatile counter on
the list object.

* When the list is updated, the counter is incremented.
* When an Iterator is created, the current value of the counter is embedded in the Iterator object.
* When an Iterator operation is performed, the method compares the two counter values and throws a CME if they are different.

The implementation of fail-safe iterators is typically light-weight. They
typically rely on properties of the specific list implementation’s data
structures. There is no general pattern. (Read the source code for the
specific cases you are interested in.)

HashMap vs ConcurrentHashMap vs Collections.synchronizedMap(HashMap)

HashMap, ConcurrentHashMap和Collections.synchronizedMap(HashMap)有什么区别?

  • HashMap就是一个正常的Dictionary,不是线程安全的;

  • ConcurrentHashMap是线程安全的,它是通过将Map中的entry再分成segment,不同的segement使用不同的锁,来实现多线程安全快速访问的。但是如果不同的线程来访问同一个segment中的entry的话,还是要等上一个线程访问完成,才能继续;

  • Collections.synchronizedMap(HashMap)是通过将一个包装类,将HashMap的所有方法都synchronized住。

Java中BigDecimal的HALF_EVEN

HALF_EVEN是什么意思呢?如果要丢掉的数字不是5的话,需要看这个数字前面的数字的奇偶性,如果是奇数,使用HALF_UP规则;如果是偶数使用HALF_DOWN规则;如果要丢掉的数字是5的话,round到它的偶数邻居上;

round到它的偶数邻居上是什么意思呢?

例子:

System.out.println("==================");
for(int i = 0; i < 10;  i ++) {
    StringBuffer sb = new StringBuffer();
    sb.append(i);
    sb.append(".5");
    BigDecimal bdx = new BigDecimal(sb.toString());
    System.out.println(sb + " " +bdx.setScale(0, RoundingMode.HALF_EVEN));
}

System.out.println("==================");
for(int i = 0; i < 10;  i ++) {
    StringBuffer sb = new StringBuffer();
    sb.append("0.");
    sb.append(i);
    sb.append("5");
    BigDecimal bdx = new BigDecimal(sb.toString());
    System.out.println(sb + " " +bdx.setScale(1, RoundingMode.HALF_EVEN));
}

输出是:

==================
0.5 0 –>0.5距离0和1都是0.5,但是0是偶数,所有round到0
1.5 2
2.5 2
3.5 4
4.5 4
5.5 6
6.5 6
7.5 8
8.5 8

9.5 10

0.05 0.0
0.15 0.2
0.25 0.2
0.35 0.4
0.45 0.4
0.55 0.6
0.65 0.6
0.75 0.8
0.85 0.8
0.95 1.0