https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

临时使用

1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注意,simple 不能少, 是 https 而不是 http

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

1
2
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip

1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

https://www.cnblogs.com/jimodetiantang/p/9016826.html
https://blog.csdn.net/qq_26079093/article/details/90759175

语法

capture mutable -> return-type { statement }

示例

1
2
[] (int x, int y) { return x + y; } 
[] (int x, int y) -> int { int z = x + y; return z; }

capture

1
2
3
4
5
6
7
8
9
[空]        没有任何函数对象参数。
[=] 函数体内可以使用 Lambda 所在范围内所有可见的局部变量(包括 Lambda 所在类的 this),并且是值传递方式(相当于编译器自动为我们按值传递了所有局部变量)。
[&] 函数体内可以使用 Lambda 所在范围内所有可见的局部变量(包括 Lambda 所在类的 this),并且是引用传递方式(相当于是编译器自动为我们按引用传递了所有局部变量)。
[this] 函数体内可以使用 Lambda 所在类中的成员变量。
[a] 将 a 按值进行传递。按值进行传递时,函数体内不能修改传递进来的 a 的拷贝,因为默认情况下函数是 const 的,要修改传递进来的拷贝,可以添加 mutable 修饰符。
[&a] 将 a 按引用进行传递。
[a, &b] 将 a 按值传递,b 按引用进行传递。
[=, &a, &b] 除 a 和 b 按引用进行传递外,其他参数都按值进行传递。
[&, a, b] 除 a 和 b 按值进行传递外,其他参数都按引用进行传递。

https://crowcpp.org

Crow is C++ microframework for web. (inspired by Python Flask)

入门

1
2
3
4
5
6
7
8
9
10
11
12
#include "crow.h"

int main()
{
crow::SimpleApp app;

CROW_ROUTE(app, "/")([](){
return "Hello world";
});

app.port(18080).multithreaded().run();
}

JSON Response

1
2
3
4
5
6
CROW_ROUTE(app, "/json")
([]{
crow::json::wvalue x;
x["message"] = "Hello, World!";
return x;
});

Arguments

1
2
3
4
5
6
7
8
CROW_ROUTE(app,"/hello/<int>")
([](int count){
if (count > 100)
return crow::response(400);
std::ostringstream os;
os << count << " bottles of beer!";
return crow::response(os.str());
});

Handler arguments type check at compile time

1
2
3
4
5
// Compile error with message "Handler type is mismatched with URL paramters"
CROW_ROUTE(app,"/another/<int>")
([](int a, int b){
return crow::response(500);
});

Handling JSON Requests

1
2
3
4
5
6
7
8
9
10
11
CROW_ROUTE(app, "/add_json")
.methods("POST"_method)
([](const crow::request& req){
auto x = crow::json::load(req.body);
if (!x)
return crow::response(400);
int sum = x["a"].i()+x["b"].i();
std::ostringstream os;
os << sum;
return crow::response{os.str()};
});
阅读全文 »

《Boost.Asio C++ Network Programming》

libtorrent 使用了 Boost.Asio

支持

network
com serial ports
files

实现同步/异步输入输出

1
2
3
4
read(stream, buffer)
async_read(stream, buffer)
write(stream, buffer)
async_write(stream, buffer)

协议

TCP UDP IMCP

可以根据自己的需要扩展使其支持自己的协议

同步和异步

如果使用同步模式,因为是阻塞模式,所以服务器客户端往往使用多线程

编程前尽早决定使用同步还是异步模式

阅读全文 »

https://pugixml.org/docs/quickstart.html

加载XML文件

1
2
3
4
5
pugi::xml_document doc;

pugi::xml_parse_result result = doc.load_file("tree.xml");

std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl;

加载错误处理

1
2
3
4
5
6
7
8
9
10
11
12
13
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_string(source);

if (result)
{
std::cout << "XML [" << source << "] parsed without errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n\n";
}
else
{
std::cout << "XML [" << source << "] parsed with errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n";
std::cout << "Error description: " << result.description() << "\n";
std::cout << "Error offset: " << result.offset << " (error at [..." << (source + result.offset) << "]\n\n";
}

从内存加载XML

1
2
3
4
5
6
7
8
9
10
11
12
const char source[] = "<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>";
size_t size = sizeof(source);

// You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
char* buffer = new char[size];
memcpy(buffer, source, size);

// The block can be allocated by any method; the block is modified during parsing
pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);

// You have to destroy the block yourself after the document is no longer used
delete[] buffer;
阅读全文 »

简介

https://github.com/google/flatbuffers
https://google.github.io/flatbuffers/index.html#flatbuffers_overview

FlatBuffers是Google发布的一个高效的跨平台的序列化库,支持多种编程语言。

Google最初是将其用于游戏开发和其他对性能要求比较高的场合。

FlatBuffers与普通序列化方案的区别:

一般序列化通常采用以下步骤:将数据结构序列化为JSON、XML、二进制或其他格式的数据流,然后接收方或使用方将数据流再解析为数据结构。

以C++为例,FlatBuffers的步骤是:

  1. 编写Schema文件(schema file),即使用接口定义语言(IDL)定义数据结构
  2. 使用flatc编译器编译Schema文件,生成C++文件
  3. 将生成的C++文件添加到项目中一起编译
  4. 使用生成的C++文件提供的接口序列化/反序列化数据
阅读全文 »

《Pro Git》笔记

基础

初次运行Git前的配置

设置用户名和邮箱地址

1
2
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

在已存在的目录中初始化仓库

1
git init

克隆现有仓库

1
git clone https://github.com/libgit2/libgit2
1
git clone https://github.com/libgit2/libgit2 mylibgit
阅读全文 »

https://wiki.qt.io/Qt_for_WebAssembly

安装 Emscripten SDK

从GitHub下载emsdk

https://github.com/emscripten-core/emsdk

Qt版本和Emscripten版本的对应关系参考文首的链接。

安装1.38.27版本的Emscripten

1
./emsdk install sdk-fastcomp-1.38.27-64bit

编译Qt源代码

下载Qt5.14源代码http://download.qt.io/archive/qt/

配置源代码

1
./configure -xplatform wasm-emscripten -nomake examples -prefix $PWD/qtbase
阅读全文 »

《Google软件测试之道》笔记

在Google,软件测试团队归属于一个被称为“工程生产力”的中心组织部门,这个部门的职责横跨开发测试人员使用工具的研发、产品发布和各种级别的测试,从单元级别的测试到探索性级别的测试。

Google是一家以创新和速度为基础的公司,快速地发布有用的代码(如果失败,也只有少数早期用户会失望)、迭代地增加早期用户希望使用的功能(最大化用户反馈)。

在整个公司,我们只有非常少的专职测试人员。

Google的测试团队并非雄兵百万,我们更像是小而精的特种部队。

测试人员的稀缺会导致测试资源变得非常昂贵,因此,我们的原则就是让这些稀缺且聪明的测试员工保持昂扬的斗志和充沛的精力。

阅读全文 »

目的

构建环境,学习 《Linux设备驱动程序》 《Linux内核设计与实现》

Linux环境

Fedora 24,内核版本4.5.5。

Linux 4.5.5-300.fc24.x86_64

下载内核源码

https://www.kernel.org下载了4.19.128版本。

内核配置

使用make help查看所有make选项。

可以使用不同的方法进行配置,比如make configmake menuconfigmake xconfig等。

阅读全文 »
0%