Intelligence without ambition is a bird without wings.

2015-01-20
cmake-函数中遍历ARGN

1
2
3
4
5
6
7
8
9
10
11
12
function(use_library)
foreach(name ${ARGN})
if(${name} STREQUAL ".")
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
else()
message(${PROJECT_SOURCE_DIR}/3rdparty/${name}/include)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/${name}/include)
link_directories(${PROJECT_SOURCE_DIR}/3rdparty/${name}/lib)
endif()
endforeach()
endfunction()

参考

  1. http://www.cmake.org/cmake/help/v3.0/command/foreach.html
阅读此文

2015-01-20
winsock-error-10014

错误代码

1
2
3
4
if (recvfrom(socket, recv_buf, sizeof(recv_data), 0, (sockaddr *)&server_addr, NULL) == SOCKET_ERROR) {
WinSock::printError("recvfrom error");
return false;
}

原因

recvfrom最后一个参数是指定socket地址,为传入传出参数,不能为NULL!

解决

1
2
3
4
5
int len = sizeof(server_addr);
if (recvfrom(socket, recv_buf, sizeof(recv_data), 0, (sockaddr *)&server_addr, &len) == SOCKET_ERROR) {
WinSock::printError("recvfrom error");
return false;
}

参考

  1. http://stackoverflow.com/questions/17306405/c-udp-recvfrom-is-acting-strange-wsagetlasterror-10014
阅读此文

2015-01-20
jsoncpp-使用

前提

1
#include <json/json.h>

生成json数据对象

1
2
3
4
5
6
7
8
9
10
Json::Value send_data;

send_data["msgType"] = 1;

// json对象
send_data["data"]["ipAddress"] = "192.168.1.1";

// json数组
send_data["name"].append("li");
send_data["name"].append("zhang");

json对象转为字符串

转为格式化过的字符串

1
std::string str = send_data.toStyledString();

转为非格式化字符串

1
2
Json::FastWriter fast_writer;
std::string str = fast_writer.write(send_data);

读取json数据

1
2
3
4
5
6
7
8
9
Json::Value send_data;
send_data["msgType"] = 1;
send_data["msgCode"] = 10000;
send_data["errCode"] = 0;
send_data["data"]["ipAddress"] = "192.168.1.1";
send_data["data"]["macAddress"] = "";

send_data["msgType"].asInt();
send_data["data"]["ipAddress"].asString();
阅读此文

2015-01-16
vim-输入二合字母

二合字母

二合字母用来输入不能用普通键盘输入的字符。它们通常是可显示的非 ASCII 字符。

输入方法

<Ctrl-k>{char1}{char2}

实例

CR ^M

参考

:help digraph
阅读此文

2015-01-16
vim-去除^M

阅读此文

2015-01-16
修改网络邻居登录密码

通过【凭据管理器】

  • [控制面板] => 【小图标】 => 凭据管理器

  • control userpasswords2 => [高级] => [管理密码]

  • control keymgr.dll

通过【命令】

  • net use \\hostname\IPC$ /delete

注:

  1. hostname为要连接的电脑主机名,也可以是IP

注意

  • 修改后,注销生效!
阅读此文

2015-01-16
autohotkey-字符串

字符串是否为空

1
2
3
4
if (var = "")
{

}

字符串拼接

  • 表达式方法
1
Var := "The color is " . FoundColor
  • 传统方法
1
Var = The color is %FoundColor%

参考:

  1. http://www.autohotkey.com/docs/Variables.htm#Operators
阅读此文

2015-01-16
python-字符串

将其他数据类型转换为string

1
str(data)

重复字符串指定次数

1
‘abc' * 128

字符串前缀匹配

1
string.beginswith(str)

字符串后缀匹配

1
string.endswith(str)
阅读此文

2015-01-16
python-打印不追加换行

  • python2, 3

    import sys
    sys.stdout.write('hello world')
    
  • python3

    print('hello world', end="")
    
  • python2

    print('hello world', )
    

参考

  1. http://www.zhihu.com/question/20390166
  2. http://stackoverflow.com/questions/493386/how-to-print-in-python-without-newline-or-space
阅读此文

2015-01-16
python-windows彩色打印

安装colorama

代码

1
2
3
4
5
6
7
8
9
10
11
from colorama import init, Fore, Back, Style

init()

print(Fore.RED + 'some red text')
print(Fore.GREEN + 'some green text')
print(Fore.RESET)
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Fore.RESET + Back.RESET + Style.RESET_ALL)
print('back to normal now')
阅读此文