0%

问题提出:有一个模板函数,函数在处理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头文件定义了很多类型检查相关的方法,上面的例子具体用到了其中两个结构:

阅读全文 »

git的配置

  1. 安装git
  2. 安装完成后,需要设置自己的用户名和email,在命令行输入:
1
2
git config --global user.name "levon"
git config --global user.email "levonfly@gmail.com"

git和目录绑定

  1. 在一个目录里可以通过git init命令把这个目录变成Git可以管理的仓库,然后通过以下命令绑定提交的地址
1
git remote add origin https://github.com/unix2dos/unix2dos.github.io
  1. git clone 地址 就会创建目录和地址绑定
阅读全文 »

首先找到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 放进去
阅读全文 »

1. 安装hexo

1
2
3
4
5
apt install npm
npm install -g hexo-cli
mkdir hexo
hexo init hexo
cd hexo
阅读全文 »

公司需要把所有代码放到一个文件内,加上版权信息. 于是用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
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()
阅读全文 »

自己写的一个简单去除html标签(xml)的脚本

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<text font="Palatino Linotype">
<p>
<s end_audio="262" start_audio="13">
<w end_audio="94" id="0" start_audio="13" variants="mud">Mud</w>
<w end_audio="122" id="1" start_audio="95">makes</w>
<w end_audio="140" id="2" start_audio="123">my</w>
<w end_audio="215" id="3" start_audio="141">mom</w>
<w end_audio="262" id="4" start_audio="216" variants="mad">mad.</w>
</s>
</p>
</text>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re
import sys

# how to use
# pythone a.py C6M01B1-001.xml

file = sys.argv[1]
f = open(file, 'r')

res = ""
for line in f.readlines():
#str = re.sub(r'</?\w+[^>]*>','',line)
str = re.sub(r'<(/|\?)?\w+[^>]*>','',line)
if str != '\r\n':
res = res + str
res = re.sub('\r\n',' ',res)
print res
#print "len =",len(res)