Tuesday, 31 January 2017

git clean ( 清理)

git clean ( 清理)
有时,Git会提示“untracked working tree files”会“overwritten by checkout”。造成这种情况的原因有很多。不过通常来说,我们可以使用如下命令来保持工作树的整洁,从而防止这种情况的发生:
$ git clean -f     # remove untracked files
$ git clean -fd    # remove untracked files/directories
$ git clean -nfd   # list all files/directories that would be removed

Friday, 27 January 2017

emacs 按列块删除

“emacs 里面那个默认的列编辑不会出来像 vim 里面那样的矩形选区(不过有别的方法好像可以做到),所以当你选择的时候,还是按行来选择的,你只需要关心选择的起始点和结束点之间的那个矩形就好了,你的操作只会在里面起作用。” 之前我总是视图用vim 的方式理解emacs, 发现每次ctrl + x + r + k 都不能删除列方块,原来emacs 根本不会像vim 那样标记列矩阵块!而是从开始行的开始字符到终止行的终止字符直接所有的内容都被高亮选中,但是不用担心,删除的时候实际只会删除开始字符和终止字符直接的矩形块,别的会保留! ~ 看来转换思维很重要。

kill-rectangle

try to delete the middle column
3c21 646f 6374
6874 6d6c 3e3c
2063 6861 7273
202f 3e0a 3c6d
6965 7770 6f72
2277 6964 7468
 
CommandKeyPurpose
kill-rectangleCtrl+x r kDelete selected column of text.
  1. Put your cursor before “646f”.
  2. Call set-mark-commandCtrl+Space】.
  3. Move cursor to end of “6964”. (move down 5 lines and right 3 columns).  At this time, the screen will looks like below (unlike vim, only the middle columns to be deleted are marked)







4. Call kill-rectangle


Wednesday, 25 January 2017

Ways to copy directory from one machine to another

There are several ways you can achieve this goal. Two the common ways are using rsync and scp.

(1)  rsync
rsync -a dir1/ dir2
This will archive and copy directory dir1 recursively to dir2.

The -a option is a combination flag.
It stands for "archive" and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions.
 If you want to copy to another machine as destination. Just add the machine full name as the prefix for 
dir2. 
syntax:
rsync -a dir1/    user_name@neodynium.bell.ca:dir2
 e.g:
rsync -a test1/  jyj407@tj12.zte.com.cn:test2
 The above  command copies test1 directory recursively from the current machine to the remote 
tj12.zte.com.cn machine directory test2.  Here, ':' colon symbol stands for the home directory for user
jyj407.

(2) Another way is use scp.
scp -r dir1/    user_name@neodynium.bell.ca:dir2
 The scp command is similar to rsync, but slower than rsync, especially for large directory with 
tons of files. Also rsync does incremental  copy, scp will copy everything. So generally speaking,
I would recommend  using 'rsync' instead of 'scp'.






Tuesday, 24 January 2017

gdb basics tutorial

      Note these commands are universal except the first two are specific for llvm build and debug. For other application you want to debug, simply build a debug version using your own way (either make or cmake), then just 'gdb yourApplication' . For some complex applications you may need --args to pass some flags.

(1)    Build a debug version executable.  
cmake -DGCC_INSTALL_PREFIX=/home/llvm/gcc/install/gcc-6.2.0 -DCMAKE_BUILD_TYPE="Debug" -DBUILD_SHARED_LIBS=ON -DLLVM_ENABLE_ASSERTIONS=ON  ~/src/llvm ; make -j20

(2)    Start gdb:
gdb --args /home/jtony/debug/bin/llc  test/CodeGen/PowerPC/expand-isel.ll

(3)    Query function:
  info func expandMergeableISELs  (info func MergeableISEL also works, fuzzy matching?)
(4)     Set break points:
Function breakpoint:
b[reak] function_name
e.g: b(reak) PPCExpandISEL::expandMergeableISELs
set breakpoint at a specified file-line pair:
b[reak] file.cpp:7
break current line:
b[reak]
conditional break is also allowed:  b[reak] file.cpp:7 if a > 5

(5)    Start the program and run to breakpoint
r[un]
Run to next breakpoint:
c[ontinue]
typing r(un) again would restart the program from beginning

(6)    Switch to TUI mode
lay src          (ctrl + x  + a)

Step into:   ‘s[tep]’             -- will go into a function call, and walk through every line of code
Step over:  ‘n[ext]’            -- treat function call as one instruction, won’t go into it
Step out:    ‘fin[ish]’          --  finish the rest of the function call and return to the caller
Note: press ENTER gdb will repeat the same command you just gave to it

Save breakpoints:  save breakpoints filename
Reload breakpints:  source filename
Show breakpoints:   ‘info break’

‘show commands’
Print value of a variable:      p[rint] varName
Print in hexadecimal:       p[rint]/x  varName
print the type of var:             ptype ‘varName

Print calling stack:   ‘where’ or ‘backtrace
Navigate between calling stack:
Go up one level:       ‘up
Go down one level:  ‘down
Go up N level:           ‘up  N
Go down N level;     ‘down N
refresh the screen:   ‘refresh

call a function: call function_name(parameters)

(13) jump to a line (not safe, unpredictable, unless you know what you are doing)   
                 First set a break point on the line you want to jump to:   b[reak]   line_number    e.g  b 321
                 Then jump line number:  jump  line_number                       e.g  jump 321


New skills learned during the tutorial:

n(ext) N       will step over N steps, if N = 1, is equivalent to just n(ext)

Thursday, 12 January 2017

git clean

40. How to remove all the untrack files in the current branch?

    Step 1 is to show what will be deleted by using the -n option:
    git clean -n
    Clean Step - beware: this will delete files:
    git clean -f



Ref:     http://stackoverflow.com/questions/61212/how-to-remove-local-untracked-files-from-the-current-git-branch

git revert

 How to revert one commit (may not be the HEAD one) ?
git revert commit_number
git revert 6d80fe73c689b51358b05cc945a53c44a092ebe3

Wednesday, 11 January 2017

What is GNU Libtool?

Introduction to GNU Libtool

GNU libtool is a generic library support script. Libtool hides the complexity of using shared libraries behind a consistent, portable interface.

To use libtool, add the new generic library building commands to your Makefile, Makefile.in, or Makefile.am. See the documentation for details. 

Ref:
https://www.gnu.org/software/libtool/libtool.html


VIM: Deleting from current position until a character

Switch to command mode in vim and then try d + t + space. In general d + t + x deletes from current position till just before x. Just t + x moves the cursor to just before character x in current line.

To delete up to and including the space, use d + f + space  (or d + t + space)


Reference: http://stackoverflow.com/questions/1607904/vim-deleting-from-current-position-until-a-space

Tuesday, 10 January 2017

Emacs editing by column

For example here is the text I want to edit:
foo
foo
foo
And here is the text result I want to have:
bar foo
bar foo
bar foo
 
 
Use rectangles (as mentioned in another answer). 
The explicit directions for that are:

  1. goto first line, first column
  2. Ctrl-Space
  3. goto last line (first column)
  4. Ctrl-x r t bar space RET