艾莉亚的猫 Time is limited, To be a better man

我的GIT配置文件

Git有一个工具被称为git config,它允许你获得和设置配置变量,用以控制Git的外观和操作的各个方面,这些变量可以被存储在三个不同的位置:

/etc/gitconfig 文件

~/.gitconfig 文件,这是我的GIT文件配置,如下:

[user]
    email = jiangzheahu@126.com
    name = jiangzhe

[push]
    default = matching

[color]
    ui = true

[core]
    editor = vim

[alias]
    co = checkout
    ci = commit
    st = status
    br = branch -v
    rt = reset --hard
    unstage = reset HEAD^
    uncommit = reset --soft HEAD^
#l = log --pretty=oneline -- abbrev-commit --graph --decorate
    l = log --pretty=format:'%h : %s' --topo-order --graph
    g = grep -n --color -E
    cp = cherry-pick -x
    nb = checkout -b
    amend = commit --amend
    who = shortlog -n -s --no-merges

#'git add -u' handles deleted files, but not new files
#'git add .' handles any current and new files, but not deleted
#'git addall' noe handles all changes
    addall = !sh -c 'git add . && git add -u'

#Handy shortcuts for rebasing
    rc = rebase --continue
    rs = rebase --skiip
    ra = reabse --abort

位于git目录的config文件(也就是 .git/config),这里稍微瞅瞅:

[core]
    repositoryformatversion = 0 
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = https://github.com/yangtze736/yangtze736.github.io
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

我的.bashrc配置文件

用户主目录下面的.bashrc文件,用于保存个人的一些个性化设置,如别名、路径等。这里就把我觉得不错的一些tips分享出来。

这是我的.bashrc文件配置,挑重点展示如下

export LANG=zh_CN.utf-8 #中文UTF-8编码
export PATH=$PATH:$DB_HOME/bin:/home/bran/bin #我自己写的shell脚本放这里

mcd() { mkdir -p "$1"; cd "$1";}
cls() { cd "$1"; ls;}

alias c="printf '\033c'" #清空屏幕,比clear好用多了,不信你试试。
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

#Funny
alias busy="cat /dev/urandom | hexdump -C | grep \"ca fe\""

#Gdb
ulimit -c unlimited #打开核心转储(core dump)
alias gdb='gdb -q' #屏蔽gdb启动时的提示信息

我自己用的系统是Ubuntu 14.04.3 LTS,.bashrc中也有一些自动生成的部分。如果宏命令很多,单独拉出来放到.bash_aliases貌似也是很不错的。

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
	. ~/.bash_aliases
fi

curl命令

不久前用libcurl写了个简易的中间件(动态链接库),现在总结一下curl工具的简单使用, 上传下载文件等不做介绍,其他的具体细节方面请参考manual文档。

curl - transfer a URL

CURL是一个利用URL语法在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称CURL为下载工具。

菲波那契数列实现

递归实现

使用公式f[n]=f[n-1]+f[n-2],依次递归计算,递归结束条件是f[1]=1,f[2]=1。 需要注意频繁的函数调用对性能的影响。

int fib(int n)
{
	if(n == 0)
		return 0;
	if(n == 1)
		return 1;
	if(n > 1)
		return fib(n-1) + fib(n-2);
}

数组实现

空间复杂度和时间复杂度都是0(n),效率一般,比递归来得快。

int fib(int n)
{
	if(n == 0)
		return 0;
	if(n == 1 || n == 2)    
		return 1;

	int *a = new int[n+1];
	a[0]=0;
	a[1]=1;
	for(int i=2; i <= n; i++)
	{   
		a[i] = a[i-1] + a[i-2];
	}   

	int m = a[n];
	delete[] a;

	return m;
}

字符串匹配的KMP算法

字符串匹配是计算机的基本任务之一,举例来说,有一个字符串”BBC ABCDAB ABCDABCDABDE”,我想知道,里面是否包含另一个字符串”ABCDABD”?许多算法可以完成这个任务,Knuth-Morris-Pratt算法(简称KMP)是最常用的之一。

这种算法不太容易理解,网上有很多解释,但读起来都很费劲。直到读到Jake Boxer的文章,我才真正理解这种算法。下面,我用自己的语言,试图写一篇比较好懂的KMP算法解释。