扇贝批量加词(Shell script)

先每行一个写入words.txt,然后网页端加一个,开发者工具 – 网络 – Copy as curl,得到如下形式:

curl 'https://www.shanbay.com/bdc/vocabulary/add/batch/?words=clerical&_=1494415650964' -H 'Host: www.shanbay.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: zh-CN,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Referer: https://www.shanbay.com/bdc/vocabulary/add/batch/' -H 'Cookie: csrftoken=?????; _ga=GA?????; _gat=1; auth_token=????????; sessionid="??????"; userid=?????; language_code=zh-CN' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'

然后新建一个add_single.sh,写入

#!/bin/bash
curl "https://www.shanbay.com/bdc/vocabulary/add/batch/?words=${1}&_=1494415650964" ..............

之后chmod +x add_single.sh

最后安装parallel工具,

cat words.txt | parallel ./add_single.sh

利用Docker的自定义网络来管理ip绑定

Docker最近推出了docker network的功能,允许用户自己创建网络。刚好手头合租了一台服务器想试试。

这台服务器有4个公网ip(173.208.194.202,203,205,206/29)。我单独占了个173.208.194.205。我期待的效果是:这个docker network内创建的容器,默认会publish到173.208.194.205(即外界连.205:port也能访问到映射的容器);并且容器内对外connect时,默认的localaddr也是.205。

继续阅读“利用Docker的自定义网络来管理ip绑定”

最近看的一些关于Linux服务端方面的文章

写点C++ user defined literals的奇怪(正常)用途

 

之前写的围棋程序的测试中,我们常常需要vector< { Player, Point } > pieceToPlace。问题在于,如果我们硬编码这个vector,可读性很差:

pieceToPlace.emplace_back(Player::B, make_pair(2, 3));
pieceToPlace.emplace_back(Player::B, make_pair(2, 1));
pieceToPlace.emplace_back(Player::W, make_pair(1, 0));

通过User defined literal,我们可以做到这样:

 auto placeVec = getInput({
    {O,   1_B,   2_W,   4_W},
    {6_W, 3_B,   5_B,   7_W},
    {O,   O,     O,     8_B},
    {9_W, O,     O,     O}
});
for (auto &ele : placeVec) 
{
    cout << (ele.player == Player::B ? "B" : "W") << " " << ele.point.first << "," << ele.point.second << endl; 
}
/*
B 0,1
W 0,2
B 1,1
W 0,3
B 1,2
W 1,0
W 1,3
B 2,3
W 3,0
*/

继续阅读“写点C++ user defined literals的奇怪(正常)用途”