Author Archives: fli10

GNU Emacs Reference Card

http://www.physics.ucsb.edu/~pcs/apps/editors/emacs-quick-1.8.html

(for version 18)

STARTING EMACS
To enter Emacs, type emacs

LEAVING EMACS
suspend Emacs (the usual way of leaving it)          C-z
exit Emacs permanently                               C-x    C-c

FILES
read a file into Emacs                               C-x    C-f
save a file back to disk                             C-x    C-s
insert content of another file into this buffer      C-x    i
replace this file with the file you really want      C-x    C-v
write buffer to a specified file                     C-x    C-w
run Dired, the directory editor                      C-x    d

GETTING HELP
The Help system is simple. Type C-h and follow the directions. If
you are a first-time user, type C-h t for a tutorial.

get rid of Help Window                               C-x    1
scroll Help Windows                                  ESC    C-v
apropos: show commands matching a string             C-h    a
show the function a key runs                         C-h    c
describe a function                                  C-h    f
get mode-specific information                        C-h    m

ERROR RECOVERY
about partially typed or executing command           C-g
recover a file lost by a system crash          M-x recover-file
undo an unwanted change                              C-x  u or C-_
restore a buffer to its original contents      M-x revert-buffer
redraw garbaged screen                               C-l    

INCREMENTAL SEARCH
search forward                                       C-s
search backward                                      C-r
regular expression search                            C-M-s

Use C-s or C-r again to repeat the search in either direction

exit incremental search                              ESC
undo effect of last character                        DEL
abort current search                                 C-g

If Emacs is still searching, C-g will cancel the part of the search
not done, otherwise it aborts the entire search.


MOTION
Cursor Motion:
   entity to move over             backward       forward
   -------------------------------------------------------
   character                       C-b            C-f
   word                            M-b            M-f
   line                            C-p            C-n
   go to line beginning (or end)   C-a            C-e
   sentence                        M-a            M-e
   paragraph                       M-[            M-]
   page                            C-x [          C-x ]
   sexp                            C-M-b          C-M-f
   function                        C-M-a          C-M-e
   go to buffer beginning (or end) M-<            M->

Screen Motion:
   scroll to next screen           C-v
   scroll to previous screen       M-v
   scroll left                     C-x <
   scroll right                    C-x >

KILLING AND DELETING
   entity to kill                  backward       forward
   --------------------------------------------------------
   character (delete, not kill)    DEL            C-d
   word                            M-DEL          M-d
   line (to end of)                M-O C-k        C-k
   sentence                        C-x DEL        M-k
   sexp                            M-- C-M-k      C-M-k
   
   kill region                            C-w
   kill to next occurrence of character   M-z char
   yank back last thing killed            C-y
   replace last yank with previous kill   M-y

MARKING
set mark here                             C-@ ir C-SPC
exchange point and mark                   C-x C-x
set mark arg words away                   M-@
mark paragraph                            M-h
mark page                                 C-x C-p
mark sexp                                 C-M-@
mark function                             C-M-h
mark entire buffer                        C-x h

QUERY REPLACE
interactively replace a text string       M-%
using regular expressions                 M-x query-replace-regexp

Valid responses in query-replace mode are
replace this one, go on to next           SPC
replace this one, don't move              ,
skip to next without replacing            DEL
replace all remaining matches             !
back up to the previous match             ^
exit query-replace                        ESC
enter recursive edit (C-M-c to exit)      C-r

MULTIPLE WINDOWS
delete all other windows                  C-x 1
delete this window                        C-x 0
split window into 2 vertically            C-x 2
split window into 2 horizontally          C-x 5

scroll other window                       C-M-v
switch cursor to another window           C-x o

shrink window shorter                     M-x shrink-window
grow window taller                        C-x ^
shrink window narrower                    C-x {
grow window wider                         C-x }

select a buffer in other window           C-x 4 b
find file in other window                 C-x 4 f
compose mail in other window              C-x 4 m
run Dired in other window                 C-x 4 d
find tag in other window                  C-x 4 .

FORMATTING
indent current line (mode-dependant)      TAB
indent region (mode-dependant)            C-M-\
indent sexp (mode-dependant)              C-M-q
indent region rigidly arg columns         C-x TAB

insert newline after point                C-o
move rest of line vertically down         C-M-o
delete blank lines around point           C-x C-o
delete all whitespace around point        M-\
put exactly one space at point            M-SPC

fill paragraph                            M-q
fill region                               M-g
set fill column                           C-x f
set prefix each line starts with          C-x .

CASE CHANGE
uppercase word                            M-u
lowercase word                            M-l
capitalize word                           M-c

uppercase region                          C-x C-u
lowercase region                          C-x C-l
capitalize region                         M-x capitalize-region

THE MINIBUFFER
The following keys are defined in the Minibuffer.

complete as much as possible              TAB
complete up to one word                   SPC
complete and execute                      RET
show possible completions                 ?
abort command                             C-g

Type C-x ESC to edit and repeat the last command that used the
minibuffer. The following keys are then defined.

previous minibuffer command               M-p
next minibuffer command                   M-n

BUFFERS
select another buffer                     C-x b
list all buffers                          C-x C-b
kill a buffer                             C-x k

TRANSPOSING
transpose characters                      C-t
transpose words                           M-t
transpose lines                           C-x C-t
transpose sexps                           C-M-t

SPELLING CHECK
check spelling of current word            M-$
check spelling of all words in region     M-x spell-region
check spelling of entire buffer           M-x spell-buffer

TAGS
find tag                                  M-.
find next occurrence of tag               C-u M-.
specify a new tags file                   M-x visit-tags-table

regexp search on all files in tags table  M-x tags-search
query replace on all the files            M-x tags-query-replace
continue last tags search or query-replace   M-,

SHELLS
execute a shell command                   M-!
run a shell command on the region         M-|
filter region through a shell command     C-u M-|
start a shell in window *shell*           M-x shell

RMAIL
scroll forward                            SPC
scroll reverse                            DEL
beginning of message                      . (dot)
next non-deleted message                  n
previous non-deleted message              p
next message                              M-n
previous message                          M-p
delete message                            d
delete message and back-up                C-d
undelete message                          u
reply to message                          r
forward message to someone                f
send mail                                 m
get newly arrived mail                    g
quit Rmail                                q
output message to another Rmail file      o
output message in Unix-mail style         C-o
show summary of headers                   h

REGULAR EXPRESSIONS
The following have special meaning inside a regular expression.

any single character                      . (dot)
zero or more repeats                      *
one or more repeats                       +
zero or one repeat                        ?
any character in set                      [ ... ]
any character not in set                  [^ ...]
beginning of line                         ^
end of line                               $
quote a special character c               \c
alternative ("or")                        \|
grouping                                  \( ... \)
nth group                                 \n
beginning of buffer                       \`
end of buffer                             \'
word break                                \b
not beginning or end of word              \B
beginning of word                         \<
end of word                               \>
any word-syntax character                 \w
any non-word-syntax character             \W
character with syntax c                   \sc
character with syntax not c               \Sc

REGISTERS
copy region to register                   C-x x
insert register contents                  C-x g
save point in register                    C-x /
move point to saved location              C-x j

INFO
enter the Info documentation reader       C-h i

Moving within a mode:
   scroll forward                         SPC
   scroll reverse                         DEL
   beginning of node                      . (dot)

Moving between nodes:
   next node                              n
   previous node                          p
   move up                                u
   select menu item by name               m
   select nth menu item by number (1-5)   n
   follow cress reference (return with l) f
   return to last node you saw            l
   return to directory node               d
   go to any node by name                 g

Other:
   run Info tutorial                      h
   list Info commands                     ?
   quit Info                              q
   search nodes for regexp                s

KEYBOARD MACROS
start defining a keyboard macro           C-x (
end keyboard macro definition             C-x )
execute last-defined keyboard macro       C-x e
append to last keyboard macro             C-u C-x (
name last keyboard macro                  M-x name-last-kbd-macro
insert lisp definition in buffer          M-x insert-kbd-macro

COMMANDS DEALING WITH EMACS LISP
eval sexp before point                    C-x C-e
eval current defun                        C-M-x
eval region                               M-x eval-region
eval entire buffer                        M-x eval-current-buffer
read and eval minibuffer                  M-ESC
re-execute last minibuffer command        C-x ESC
read and eval Emacs Lisp file             M-x load-file
load from standard system directory       M-x load-library

SIMPLE CUSTOMIZATION
Here are some examples of binding global keys in Emacs Lisp. Note
that you cannot say "\M-#"; you must say "\e#".

(global-set-key "C-cg" 'goto-line)
(global-set-key "\e\C-r" 'isearch-backward-regexp)
(global-set-key "\e#" 'query-replace-regexp)

An example of setting a variable in Emacs Lisp:

(setq backup-by-copying-when-linked t)

WRITING COMMANDS
(defun  ()
   ""
   (interactive "")
   )

An example:

(defun this-line-to-top-of-screen (line)
   "Reposition line point is on to the top
of the screen. With ARG, put point online ARG. 
Negative counts from bottom."
   (interactive "P")
   (recenter (if (null line)
          0
          (prefix-numeric-value line))))

The argument to "interactive" is a string specifying how to get the
arguments when the function is called interactively. Type "C-h
interactive" for more information.



Copyright 1987 Free Software Products Inc
designed by Stephen Gildea, March 1987, v 1.9
for GNU Emacs version 1.8 on Unix Systems.

Qt Designer and KDevelop-3.0 for beginners

http://women.kde.org/articles/tutorials/kdevelop3/

这几天用的一直都是KDE,发现KDE用起来还是挺方便的。无聊的时候打开KDevelop看了看,写C code用起来我感觉比Eclipse的CDT要方便多了,而且和QT结合的很好,以后在linux下写code就用它了,感觉界面比vi看起来要舒服很多。

DDD

 程序编译过了就要调试了,没想到以前对linux的一点点了解都忘光了,运行gdb后只想到了r,b,l这几个命令和help,其他都忘了。更可恶的是,装了ddd后,只会用next,查看变量值的命令也忘了,太郁闷了。

以前用过的一个Makefile

# Training Projects
CC = icc  -xW -O3   #-march=i686 -mcpu=i686
#CPP = icc -ipo -xW -O3
CPP = g++ -w -O3 -march=pentium4
#CPP = icpc -O0 -xW
#CPP= icpc -xW -O3 -no-ipo
INC = -I/usr/include -I/usr/local/include -I/opt/intel/opencv/include/opencv  -I/opt/intel/ipp41/ia32_itanium/include
LIB = -I/usr/lib -I/usr/local/lib -L/opt/intel/opencv/lib  -L/opt/intel/ipp41/ia32_itanium/sharedlib
OPT = -lcxcore -lcvaux -lcv -lhighgui -lippcore -lipps -lippm -lippi -lstdc++ -lpthread
OBJ = extractfeatures.o learn.o main.o
BIN = train   # executables to create
all: $(BIN)      
$(BIN): $(OBJ)
        $(CPP) -o $(BIN) $(OBJ)  $(LIB) $(OPT)
main.o: main.cpp stdafx.h learn.h Makefile
        $(CPP) -c main.cpp -o main.o  $(INC)
learn.o: learn.cpp stdafx.h learn.h extractfeatures.h Makefile
        $(CPP) -c learn.cpp -o learn.o $(INC)
extractfeatures.o: extractfeatures.cpp stdafx.h learn.h wtfwd53.h extractfeatures.h Makefile
        $(CPP) -c extractfeatures.cpp -o extractfeatures.o  $(INC)
clean:
        rm *~ *.o $(BIN) core train

The std::list Container Class

Last updated May 7, 2003.

Linked lists are another widely-used data structure. Yet writing a linked list from scratch is an arduous, frustrating and time-consuming task. Instead of reinventing the wheel every time anew, use the STL std::list container class. Its uniform interface, generic nature and seamless integration with other STL constructs make it a superior choice to any homemade list class, as I will show in the following sections.

Creating a list object

The header <list> contains the declaration of std::list and its specialized algorithms. Our first step is to create an empty list of integers called li:

#include <list>
using std::list;
int main()
{
 list <int> li;
}

To insert a single element, use the push_back() member function:

li.push_back(1);

To remove the last element of a list, use the pop_back() member function

li.pop_back();

As opposed to push_back(), push_front() inserts an element before the list’s beginning:

li.push_front(0); // the first element is now 0, not 1

Similarly, pop_front() removes the first element of a list:

li.pop_front();

To remove a certain value from the list without indicating its exact position, use remove(). remove(n) removes all the elements that equal to n from the list:

li.remove(0); // li doesn't contain 
       //any zeros anymore
Dealing with Sequences

Up until now I have exemplified list operations that operate on a single element at a time. std::list supports sequence operations as well. These operations enable you to traverse, fill, sort and reverse multiple elements at once.

Iteration is easy. The begin() and end() member functions return iterators pointing at the list’s beginning and end, respectively. Use them to access all the list’s elements sequentially. Note that we’re using a const_iterator instead of an ordinary iterator object because the iteration process in this case doesn’t modify the list’s state:

list<int>::const_iterator it;
for(it=li.begin(); it!=li.end(); ++it)
{
 cout << *it << endl; // each element on a separate line
} 

The assign() member function fills a list with the contents of another sequence such as a vector or an array. It takes two input iterators (for further information on iterator categories, see the resources below) that mark the sequence’s beginning and end, respectively. In the following example, we fill a list with the elements of an array:

int arr[3] = {10,20,30};
li.assign( &arr[0], &arr[3]);

You can merge two lists into one. The merge() member function takes a reference to another list object:

list <int> x;
//..fill x
li.merge(x); // merge the elements of x into li

merge() merges x into li. x becomes empty after the merge operations. To erase one or more elements, use the erase() member function. This function has two overloaded versions; the first of which takes an iterator and erases the element to which it points. The second version takes two iterators that mark the beginning and the end of the sequence to be erased. Suppose you have a list of 10 elements and you want to remove all the elements but the first two. Use erase() as follows:

list<int>::it=li.begin();
++it; ++it; // advance to third element
li.erase(it, li.end()); // erase elements 3 – 10
Support for User-Defined Types

The generic nature of list enables you to define specializations, or instances, of user-defined types. For example, you may create lists of strings and Date objects like this:

#include <string>
#include "Date.h"
list<std::string> ls;
list <Date> ld;

Operations that require element comparison such as sort() and unique() use the overloaded < operator. If you intend to use any of these algorithms with lists, define a matching overloaded version of this operator for your class first:

bool operator < (const Date& d1, const Date& d2);
ld.sort(); // OK, using overloaded < operator

Note that in general, sorting a list is less efficient than sorting a vector or a queue. Therefore, if you need to sort elements frequently, you probably shouldn’t use a list in the first place. The same is true for reverse(), which is also supported:

ld.reverse();
for(it=ld.begin(); it!=ld.end(); ++it)
{
 cout << *it << endl; // descending order
} 

收拾server小记(1)–Update the Firmware of Intel S5000PSL

读ph.d的过程就是磨练自己脾气的过程,收拾琐碎的东西就是很好的一种方式,比如收拾server。其实今天没打算修理它的,后来因为早上换了块fireware卡以后,server启动不了了,才决定修理它的。

不停的重起,拔掉4个pci卡,插上这些卡,重复一两次不会觉得有什么,重复十次呢?如果重复一百次能?中间每次拔插卡的时候再拧拧螺丝什么的,呵呵,肯定很爽~

终于在下午快3点的时候发现是显卡的问题,插上pci-e的显卡就挂了,系统启动不了,status led一直是amber常亮。开始上intel的网站上down firmware的update,提供三种方式升级,一种是用Deployment Assistant 1.2,一种是One Flash Update Utility,还有是在纯dos下用iflash update。第一种主板自带的启动盘版本低,每次用的时候出错,说系统无可启动硬盘;下载的要刻盘,一开始没有空盘;第二种在xp下装了半天一直出错,过了好一阵子才明白这玩意要在win server下装才行,切到win2k3下,装到一半crash,我无语。。。

到晚8点的时候开始准备用dos来升级,花了快2个多小时来整usb启动盘。以前用过usboot来做启动盘,都没有成功过,到公司的时候试了试还是没有搞定。今天终于搞定了!那就是用winimage和DOS80V31.img来做启动盘,也就是先装winimage,然后用用winimage load那个imgfile(有很多imgfile的后缀名为.exe, 不用管它,直接加载),再选择usb盘,开始write就行了,很方便。

一开始的时候用的是dos7.1,碰到了这个错误:

causeway Error 11: Dos reported an error or corrupt file found.

然后google,google也没找到答案,想着可能是dos的版本低,不支持这些新的dos程序,就down了个dos80的下来(发现天空软件上的软件挺多的),最后将bios先升级到66,然后升级到74,都没有问题。想着应该没有问题了,可是装上显卡后server还是在进bios之前挂掉了,又捣鼓了快两个小时,我放弃了,我要先休息一下,恢复一下我的听觉。

对PTgrey的camera编程

对ptgrey的camera进行编程还是比较painful的。想想以前自己写olympus和DH-400的程序也没这么麻烦呀,可能是应用相对简单吧。现在写ptgrey的程序真是头疼,没有人可以请教请教,API的doc也讲的很简单,提供的sample也比较少,有时候基本上全靠自己一个人在那瞎琢磨,简直就在挑战自己的想象力和排列组合能力。经过3天的排练组合,程序终于可以了修改frame rate和video mode了,但是改成任意大小显示还有点问题,不过应该可以将就着用了。

——————————–

下面是细节的东西,可能也就自己会看看:

程序是从timeSliceDemo这个例子该过来的,创建了单文档多视图的程序,还创建了CMultiDocTemplate。修改frame rate和video mode主要是修改startSync()和grabAndCheckSync()这两个函数,

grabAndCheckSync(), 其中grab image主要由两个函数实现flycaptureLockNext和flycaptureConvertImage。flycaptureConvertImage将arbitrary image type转成dst image,转换之前要设置dst image的格式,我试了一下,这里只能是FLYCAPTURE_BGRU,不然该程序就会报错,血的教训呀,2天时间。如果设置成FLYCAPTURE_BGRU的话,在startSync中创建buffer的时候就要为cols * rows * 4,因为4个channel嘛。

startSync(),这个函数里pixelFormat也要设置成FLYCAPTURE_BGRU,如果设置成FLYCAPTURE_MONO8, FLYCAPTURE_422YUV8, FLYCAPTURE_BGR, FLYCAPTURE_RGB8等都会出错。doc里没有说,显然ptgrey连明年版本里的功能都先写进doc里了,可把我害惨了。如果要改变图像的分辨率,要在这两个函数里改,flycaptureGetCustomImagePacketInfo和flycaptureStartLockNextCustomImagePacket。或者不用packet,直接用flycaptureStartLockNext,而不用flycaptureStartLockNextCustomImagePacket,这样就可以设置VIDEO_MODE和FRAME_RATE。比如设置成15Hz,省得server的workload太大。

刚刚配好了Fedora6

今天有点时间,装了一直期待中的Fedora6。这样写AI的hw,做research会方便很多。花了不少时间来配置fedora,整了一会中文输入,又装了Matlab2007,还又配了vncserver。但最为得意的是今天是用grub启动时的菜单来硬盘安装fedora的,感觉很爽。

装的时候,先把第一张cd里的isolinux解压出来,然后装个grub(这个grub不是我专门装的,在装dos硬盘版时产生的,就是因为dos引导不了,才到grub菜单下的),在grub菜单里依次输入

>kernel (sd0, 4)/boot/vmlinuz
>initrd (sd0,4)/boot/initrd.img
>boot

然后就开始装了,爽。

Setup Vncserver on Fedora6

1. configure firewall, add tcp ports 5900:5905

2. vi /etc/sysconfig/vncservers, uncomment the following 2 lines

VNCSERVERS=
VNCSERVERARGS[2]=

3. under the user mode (not root), run "vncserver", this will generate ".nvc" in the home directory. Revise the file "xstartup", and uncomment the following 2 lines

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

4. kill the vncserver by "vncserver -kill :1" and restart it. It would be OK now. Maybe you need to kill the vnc service during the configuration by "killall Xvnc".

http://fedorasolved.org/network-solutions/vncserver-setup/

How to Install Matlab R2006b on linux (Fedora Core 6)

First problem: matlab install requires libXp.so.6 library for xsetup and text-mode install does not work.

Solution: install xorg-x11-deprecated-libs rpm for fedora core from for instance rpmfind.net. This installs libXp.so.6 in /usr/X11R6/lib/libXp.so.6. In order for matlab to be able to find this library, add in directory /etc/ld.so.conf.d a file xorg-x11-deprecated-libs.conf with a single line containing /usr/X11R6/lib. Then run /sbin/ldconfig. After this the installation procedure itself did not report any more problems.

Second problem: When trying to run matlab, it does not want to start. Error message:
/usr/local/Matlab_R2006b/bin/glnx86/MATLAB: error while loading shared libraries: /usr/local/Matlab_R2006b/bin/glnx86/libmwlapack.so: cannot restore segment prot after reloc: Permission denied
Solution: I found the solution on comp.soft-sys.matlab:
chcon -t texrel_shlib_t /usr/local/matlab2006b/bin/glnx86/*.so

Alternative solution is disabling SELinux

http://www.nin.knaw.nl/~heimel/computers/HowToInstallMatlabR2006b.html