[emacs]go to end-of-buffer ignore whitespaces


;;we always need goto end-of-buffer, so we bind it to C-. for simple.
;;sometimes we need goto end-of-buffer, but ignore whitespaces at end-of-buffer
;;so by give end-of-buffer an advice, it'll switch between these points, when you
;;continue typing C-.
(defadvice end-of-buffer (around move-backward-skip-whitespace)
  "Never use tabs for alignment."
  (let ((point-before-move (point)))
    (if (and (eq point-before-move (point)) (eq last-command this-command))
        (progn (search-backward-regexp "[^\n\s-]\\W*")
(ad-activate 'end-of-buffer)
(define-key my-keys-minor-mode-map (kbd "C-.") 'end-of-buffer)



[emacs] compare with clipboard like IntelliJ IDEA


(defun compare-with-clipboard  ()
  "compare current buffer with contents in clipboard"
  (let ((clipboard-buffer (get-buffer-create "*clipbord*"))
        (orig-buffer (current-buffer)))
    (switch-to-buffer clipboard-buffer)
    (delete-region (point-min) (point-max))
    (ediff-buffers clipboard-buffer orig-buffer)))



Monitor process file operations by windbg command


* Monitor windows process activities by set breakpoint on API, and print out the parameter contents.

0:000> bp kernel32!CreateFileW ".echo ---------------------------------------;kL;du poi(@esp+4);gu;.echo =======;r eax;g"  
0:000> g  
ModLoad: 62c20000 62c29000   C:/WINDOWS/system32/LPK.DLL  
ModLoad: 77180000 77283000   C:/WINDOWS/WinSxS/x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03/comctl32.dll  
ChildEBP RetAddr    
0012e374 7c814d65 kernel32!CreateFileW  
0012e5dc 7c801d3a kernel32!BasepLoadLibraryAsDataFile+0x125  
0012e640 7c8171dd kernel32!LoadLibraryExW+0x178  
0012e66c 7c81715d kernel32!BasepSxsFindSuitableManifestResourceFor+0x51  
0012e96c 7720b80d kernel32!CreateActCtxW+0x69e  
0012eba4 7720b83f comctl32_77180000!SHFusionInitializeIDCC+0x83  
0012ebb8 7720b857 comctl32_77180000!SHFusionInitializeID+0x12  
0012ebc8 771841a9 comctl32_77180000!SHFusionInitialize+0xf  
0012ebdc 77184267 comctl32_77180000!_ProcessAttach+0x32  
0012ebe8 7c9211a7 comctl32_77180000!LibMain+0x21  
0012ec08 7c93cbab ntdll!LdrpCallInitRoutine+0x14  
0012ed10 7c936178 ntdll!LdrpRunInitializeRoutines+0x344  
0012efbc 7c9362da ntdll!LdrpLoadDll+0x3e5  
0012f264 7c801bb9 ntdll!LdrLoadDll+0x230  
0012f2cc 7c80ae5c kernel32!LoadLibraryExW+0x18e  
0012f2e0 77f5b1a3 kernel32!LoadLibraryW+0x11  
0012f504 766a1110 SHLWAPI!LoadLibraryWrapW+0x51  
0012f53c 766a10af WININET!SHFusionLoadLibrary+0x29  
0012f548 766a107d WININET!DelayLoadCC+0x15  
0012f77c 766a0ff7 WININET!SHFusionInitializeIDCC+0x92  
0012e3d0  "C:/WINDOWS/WindowsShell.Manifest"  
0012e410  ""  
ChildEBP RetAddr    
0012f8cc 7c801a4f kernel32!CreateFileW  
0012f8f0 76d357ff kernel32!CreateFileA+0x30  
0012f954 76d3570a iphlpapi!OpenIPDriver+0x115  
0012f99c 76d35454 iphlpapi!OpenTCPDriver+0xee  
0012f9d0 76d35351 iphlpapi!DllMain+0x157  
0012f9f0 7c9211a7 iphlpapi!_DllMainCRTStartup+0x52  
0012fa10 7c93cbab ntdll!LdrpCallInitRoutine+0x14  
0012fb18 7c94173e ntdll!LdrpRunInitializeRoutines+0x344  
0012fc94 7c941639 ntdll!LdrpInitializeProcess+0x1131  
0012fd1c 7c92eac7 ntdll!_LdrpInitialize+0x183  
00000000 00000000 ntdll!KiUserApcDispatcher+0x7  
7ffdfc00  "//./Ip"  
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:/Program Files/Tencent/QQ2009/Bin/KernelUtil.dll -   
ChildEBP RetAddr    
0012fc34 0044a69c kernel32!CreateFileW  
*** ERROR: Module load completed but symbols could not be loaded for QQ.exe  
WARNING: Stack unwind information not available. Following frames may be wrong.  
0012fca8 004029bd KernelUtil!Version::Init+0x8c  
0012ff08 004027d9 QQ+0x29bd  
0012ff28 00402635 QQ+0x27d9  
0012ffc0 7c816fd7 QQ+0x2635  
0012fff0 00000000 kernel32!BaseProcessStart+0x23  
00c8eca8  "C:/Program Files/Tencent/QQ2009/"  
00c8ece8  "Bin/vi.dat"  
ChildEBP RetAddr    
0012eab4 0044a2ad kernel32!CreateFileW  
WARNING: Stack unwind information not available. Following frames may be wrong.  
0012fbb4 0044a4ea KernelUtil!Util::URL::OpenUrlWithTT+0x1cd  
0012fc4c 0044a6fc KernelUtil!Version::GetBuildVer+0xca  
0012fca8 004029bd KernelUtil!Version::Init+0xec  
0012ff08 004027d9 QQ+0x29bd  
0012ff28 00402635 QQ+0x27d9  
0012ffc0 7c816fd7 QQ+0x2635  
0012fff0 00000000 kernel32!BaseProcessStart+0x23  
00c8ede0  "C:/Program Files/Tencent/QQ2009/"  
00c8ee20  "Bin/QQ.exe"  



Start from helloworld.asm


* asm
** gdb:::
resource                ::$ http://www.chemie.fu-berlin.de/chemnet/use/info/gdb/gdb_toc.html
stop at main            ::$ b main | r
view register           ::info registers
show single reg         ::print/(d|t|x) $eax
show memory value       ::x/<num>(c|d|x)(b|h|w)    x/42cb &output
(gdb) x/s $edi+28
0x600104 <output+28>:    "GenuineIntel'\n"
** common 
Code of helloworld.asm::        
EatMsg: db "hello world", 10
EatLen: equ $-EatMsg
global _start
        mov eax, 4
        mov ebx, 1
        mov ecx, EatMsg
        mov edx, EatLen
        int 80H

        mov eax, 1
        mov ebx, 0
        int 80H
Command to build::
[vagrant@vagrant-centos-6-64 vagrant]$ nasm -f elf -g -F stabs helloworld.asm 
helloworld.asm  helloworld.o
[vagrant@vagrant-centos-6-64 vagrant]$ ld -o helloworld helloworld.o -melf_i386
helloworld  helloworld.asm  helloworld.o
[vagrant@vagrant-centos-6-64 vagrant]$ ./helloworld 
hello world

dump all sections       ::$ objdump -D eatsyscall
08048080 <_start>:      ||break *_start+1 then %epi will contains 0x08048080
 8048080:       90                      nop
 8048081:       b8 04 00 00 00          mov    $0x4,%eax
 8048086:       bb 01 00 00 00          mov    $0x1,%ebx
gcc output              ::$ gcc -S ctest.c
gcc -E                  ::$ gcc -E ctest.c
compile wit debug info  ::$ gcc -gstabs -gp -o ctest ctest.c 
dump code with assembly ::$ objdump -S ctest
int foo()
  400684:       55                      push   %rbp
  400685:       48 89 e5                mov    %rsp,%rbp
  400688:       48 83 ec 10             sub    $0x10,%rsp
  40068c:       e8 a7 fe ff ff          callq  400538 <mcount@plt>  ||<--insert by -gp for gprof

#include <stdio.h>
int main()
  400504:       55                      push   %rbp
  400505:       48 89 e5                mov    %rsp,%rbp
  printf("Hello, World!\n");
  400508:       bf 18 06 40 00          mov    $0x400618,%edi
  40050d:       e8 de fe ff ff          callq  4003f0 <puts@plt>
  400512:       bf 00 00 00 00          mov    $0x0,%edi
  400517:       e8 e4 fe ff ff          callq  400400 <exit@plt>
dump out dynamic symbol table entries::$ objdump -T ctest
ctest:     file format elf64-x86-64
0000000000000000  w   D  *UND*  0000000000000000              __gmon_start__
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 puts
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 exit
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 __libc_start_main
dump dynamic entries::$ readelf -d cpuid2
Dynamic section at offset 0x2b0 contains 15 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
show used share libs::$ ldd cpuid2
        libc.so.6 => /lib64/libc.so.6 (0x00007f0e83eb4000)
        /lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f0e8424f000)
mov:: movl(long word) movw(16-bit word) movb(byte)  | movl %eax, %ebx | movw %ax %bx | movb %al %bh
conditional move:: movl value, %ecx | cmp %ebx, %ecx | cmova %ebx, %ecx
XCHG::exchange value between two general purpos registers, or betwen a register and a memory location.
when one of the operands is a memory location, the processor's LOCK signal is automatically asserted,
to turns the instruction into an atomic instruction in multiple processor environment.
CMPXCHG:: cmpxchg src dest | compare dest with EAX,AX,or AL. if equal, load src to dest. 
otherwise load dest to EAX, AX, or AL.  
unconditional branches::jump calls interrupts
call: 1) push the $eip, modifies the %eip to point to called function address 
      2) call function and ret 
      3) pop %eip to continue
asm function template::
    pushl %ebp
    movl %esp, %ebp
    <normal function code>
    movl %ebp, %esp
    popl %ebp

software interrupts::are provided by OS to enable app to tap info function into the OS. (system calls).

** resources



What Emacs can do?

code alignment  (gif video)

column editing (gif video)

WEIBO, git, git blame, rainbow (gif video)

dynamic selection and Code browsing (gif video)

org-mode + googledriver to manage your notes in one file (gif video)

    weibo and music
    Task management in TDD