Levon's Blog

微信: L6241425

vector deque

在使用 vector、deque遍历删除元素时,也可以通过erase的返回值来获取下一个元素的位置:

1
2
3
4
5
6
7
8
9
10
11
std::vector<int> Vec;
std::vector<int>::iterator itVec;
for( itVec = Vec.begin(); itVec != Vec.end(); )
{
if( WillDelete( *itVec) )
{
itVec = Vec.erase( itVec);
}
else
itList++;
}
阅读全文 »

问题提出:有一个模板函数,函数在处理int型和double型时需要进行特殊的处理,那么怎么在编译期知道传入的参数的数据类型是int型还是double型呢?
如:

1
2
3
4
5
6
7
#include <iostream>
template <typename TYPE>
void typeCheck(TYPE data)
{
//do something check data type
//std::cout<< out put the type
}

这里就需要用到C++11的type_traits头文件了,type_traits头文件定义了很多类型检查相关的方法,上面的例子具体用到了其中两个结构:

阅读全文 »

1. Git 数据流转模型

理解 Git 的核心在于掌握数据在不同区域间的流转。

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#4F46E5', 'primaryTextColor': '#fff', 'primaryBorderColor': '#3730A3', 'lineColor': '#6366F1', 'secondaryColor': '#10B981', 'tertiaryColor': '#F59E0B'}}}%%
flowchart LR
    Workspace["工作区<br/>(Workspace)"] -->|"git add"| Index["暂存区<br/>(Index/Stage)"]
    Index -->|"git commit"| Repository["本地仓库<br/>(Local Repo)"]
    Repository -->|"git push"| Remote["远程仓库<br/>(Remote Repo)"]
    Remote -->|"git pull/fetch"| Repository
    Repository -->|"git checkout/restore"| Workspace
    
    classDef primary fill:#4F46E5,stroke:#3730A3,color:#fff
    class Workspace,Index,Repository,Remote primary
阅读全文 »

首先找到Xcode中的自带的配置文件

1
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

这个文件里配置了一些可以设置快捷键的操作, 使用常用的编辑器打开它(需要root权限)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<key>GDI Commands</key>
<dict>
<key>GDI Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>GDI Delete Current Line</key>
<string>deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:</string>
<key>GDI Move Current Line Up</key>
<string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Move Current Line Down</key>
<string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Insert Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>GDI Insert Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
</dict>
阅读全文 »

Xcode 主题

1
https://github.com/tursunovic/xcode-themes

elfDark

1
2
3
https://code.google.com/archive/p/elf-ios-resource/downloads

cd /Users/liuwei/Library/Developer/Xcode/UserData/FontAndColorThemes 放进去
阅读全文 »

公司需要把所有代码放到一个文件内,加上版权信息. 于是用shell简单的处理了下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

NAME="a.txt"
if [ -f $NAME ]; then
`rm $NAME`
fi

DIR=""
FILE=""
for file in `ls -R`
do
if [ -f $file ]; then
if [ $file = "a.sh" ];then
continue
fi
# echo "===================== $file begin =====================" >> $NAME
# `cat $file >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $file
else
if [ ${file:0:1} = "." ];then
DIR=${file/://}
else
if [ "$DIR" != "" ] && [ ${DIR:0:6} = "./base" ];then
continue #此处可以过滤不想要的文件夹
fi
FILE=$DIR$file
if [ -f $FILE ]; then
# echo "===================== $file begin =====================" >> $NAME
# `cat $FILE >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $FILE
fi
fi
fi
done

工作需要把 Mud makes my mom mad. 这句话带有m的加上颜色,或者把某些单词加上颜色
临时写了个脚本处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
import sys


# replace letter
#find = "m"
#str = "Mud makes my mom mad."

#replace key words
#find = "Mud|makes|mad"
#str = "Mud makes my mom mad."

# how to use
# python b.py "m" "Mud makes my mom mad."
# python b.py "mud|mess|mop|make|the|help" "Mud makes my mom mad."


find = sys.argv[1]
str = sys.argv[2]


result = re.sub(r'('+find+')', r'<color:#ff0000>\1</color>', str, 0, re.IGNORECASE)
print result

执行命令安装vim 注意要加上--with-override-system-vi

1
brew install vim --with-override-system-vi

安装过程中如果出现 ruby.h找不到

执行下面的命令

1
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
1
sudo ln -s ../universal-darwin15/ruby/config.h ./config.h

注意不要复制上面的, 对应自己的sdk版本,ruby版本,darwin版本

阅读全文 »

配置文件和快速设置

  1. PlugClean
  2. PlugInstall
  3. 去到YCM里执行
1
./install.py --clang-completer --gocode-completer

安装插件管理器

1
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

安装插件

1
2
3
4
5
6
7
8
9
10
call plug#begin()
Plug 'fatih/vim-go' "go
Plug 'tomasr/molokai' "主题
Plug 'SirVer/ultisnips' "tab补全
Plug 'ctrlpvim/ctrlp.vim' "快速查文件
Plug 'Shougo/neocomplete.vim' "实时提示
Plug 'majutsushi/tagbar' "tagbar
Plug 'scrooloose/nerdtree' "导航
Plug 'vim-airline/vim-airline' "下面
call plug#end()
阅读全文 »
0%