Intelligence without ambition is a bird without wings.

2015-01-28

选项

功能字符

必须指定1个,可以指定多个,多个可以连在一起,前面的’-‘不是必需的

-A
追加tar文件到一个archive

-r
追加files到archive

-c
创建新的archive

-x
解包并解压

-t
查看包内容

###选项

-a
根据包名字后缀自动选择相应的压缩程序

-f archive

指定包名字,打包就是目的包名字,解包就是要解包的包名字

-C dir

解包到指定目录(该目录需要已存在)

-p
保留文件权限,属性信息

-P
不拿掉绝对路径前面的’/‘

-h, –dereference

follow symlinks; archive and dump the files they point to

压缩选项

-z
gzip

-j
bzip2

-J
xz

实例

  • 解压,解包

    tar xf *.tar.gz
    
  • 将当前目录打包,压缩

    tar vczf tar.tar.gz .
    
  • 解开包中某一个文件

    • 先查看文件

      tar tf tar.tar.gz | grep tar
      
    • 再解压指定文件

      tar vxzf tar.tar.gz .tar实例.swp
      
  • 给当前目录下,某个文件夹打包压缩

    tar vczf src.tar.gz src
    
阅读此文

2015-01-27
python-遍历目录

os.walk

1
2
3
4
5
import os

for root, dirs, files in os.walk('.'):
for file in files:
print file

查找指定文件

glob.glob

1
2
3
4
import glob

for file in glob.glob('*.txt'):
print(file)

fnmatch.fnmatch

1
2
3
4
5
6
import fnmatch
import os

for file in os.listdir('.'):
if fnmatch.fnmatch(file, '*.txt'):
print file

re.match

1
2
3
for d in [f for f in os.listdir('.') if re.match(r'build-\(.*\)-.*', f)]:
print('cleanning {} ...'.format(d))
shutil.rmtree(d)

参考

  1. http://stackoverflow.com/questions/2225564/get-a-filtered-list-of-files-in-a-directory
阅读此文

2015-01-27
python-映射list

数学联系

对某个集合进行映射(数学运算),生成一个新集合

作用

将一个序列映射为另一个序列,新序列的元素依赖于原序列的元素

示例

  • 简单转换
1
2
3
4
5
6
7
8
>>> li = [1, 9, 8, 4]
>>> [elem*2 for elem in li] 1
[2, 18, 16, 8]
>>> li 2
[1, 9, 8, 4]
>>> li = [elem*2 for elem in li] 3
>>> li
[2, 18, 16, 8]
  • buildConnectionString
1
2
3
4
5
6
7
8
9
>>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
>>> params.items()
[('server', 'mpilgrim'), ('uid', 'sa'), ('database', 'master'), ('pwd', 'secret')]
>>> [k for k, v in params.items()] 1
['server', 'uid', 'database', 'pwd']
>>> [v for k, v in params.items()] 2
['mpilgrim', 'sa', 'master', 'secret']
>>> ["%s=%s" % (k, v) for k, v in params.items()] 3
['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret']

过滤列表推导

1
2
3
>>> special_squares = [ x**2 for x in range(10) if x**2 > 5 and x**2 < 50 ]
>>> print special_squares
[9, 16, 25, 36, 49]

执行顺序

  • range(10)

  • for x in range(10)

  • if ...

  • x**2

参考

  1. http://www.u.arizona.edu/~erdmann/mse350/topics/list_comprehensions.html
  2. http://woodpecker.org.cn/diveintopython/native_data_types/mapping_lists.html
  3. https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
阅读此文

2015-01-26
vim-xptemplate片段编写

  • 调用vim函数
1
~expand("%:r")^
  • 可视模式下wrap

    XPT code wrap=cursor " 
    code ```
    1
    2
    ```~language^
    ~cursor^
阅读此文

2015-01-26
vim-代码片段插件比较

xptemplate

优点

  • 支持菜单弹出显示

    当有多个片段时,弹出popup菜单显示

  • 支持前缀唯一匹配

UltiSnips

缺点

  • 不支持菜单弹出显示

  • 不支持前缀唯一匹配

阅读此文

2015-01-26
python-ImportError-No-module-named-_curses

原因

python中的curses不支持windows

参考:

  1. https://docs.python.org/2/library/curses.html

解决

安装拓展包,参见{ iLink title:python-install-curses-on-windows %}

阅读此文

2015-01-26
python-install-curses-on-windows

Environment

  • python2.7-32bit

  • win7

Step

  • Download corresponding package

    In my environment, I downloaded curses-2.2-cp27-none-win32.whl.

  • cd to download directory and Install it

    pip install curses-2.2-cp27-none-win32.whl
    

Thanks

阅读此文

2015-01-26
cmake-Disable Warning Manually-specified variables were not used by the project

阅读此文

2015-01-24
git-push-warning

warning: push.default is unset;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

解决

  • 默认只推送当前分支

    git config --global push.default simple
    
阅读此文

2015-01-24
vim-script编码规范

阅读此文