开始接触boost是因为项目中用到C++与Python的相互调用传值,后来找到一本《boost程序库完全开发指南》感觉boost库很强大,就学了一下。所以boost学习笔记基本沿用《boost程序库完全开发指南》书中脉络。
因为C++是强类型语言,所以对于Python,perl之类的动态语言来说很麻烦的一件事情就是类型转换,虽然C中也提供了atoi(),atof()之类的函数,但是总体也还是很麻烦。幸而有了lexical_cast
,他可以用来进行字符串、整数/浮点数之间的字面转换。
lexical_cast 位于boost命名空间,为了使用 lexical_cast,需要包含头文件 <boost/lexical_cast.hpp>,即:
#include <boost/lexical_cast.hpp>
using namespace boost;
lexical_cast在转换字符串时,字符串中只能包含数字和小数点,不能出现除e/E以外的英文字符或者其他非数字字符。
using boost::lexical_cast;
int a = lexical_cast<int>("123"); // string -> int
long b = lexical_cast<long>("2015"); // string -> long
double c = lexical_cast<double>("123.12"); // string -> double
float pai = lexical_cast<float>("3.14159"); // string -> float
std::cout << a << b << c << pai << std::endl;
数字转换成字符串时不支持高级格式控制。
string str = lexical_cast<string>(123); // int -> string
std::cout << str << std::endl;
cout << lexical_cast<string>(1.234) << endl; // float -> string
cout << lexical_cast<string>(0x11) << endl; // 16进制 -> string
// lexical_cast can cast 0 & 1 to bool, but only support 0 & 1, not support True or False string
bool bl = lexical_cast<bool>("1"); // string -> bool, only support 1 & 0
当 lexical_cast 无法执行转换时会抛出异常 bad_lexical_cast ,它是 std::bad_cast 的派生类。可以使用 try/catch 块来保护代码。
try{
cout << lexical_cast<int>("0x100");
cout << lexical_cast<bool>("false");
}catch (bad_lexical_cast& e){
cout << "error: " << e.what() << endl;
}
代码运行结果:
error: bad lexical cast: source type value could not be interpreted as target
lexical_cast 对转换对象有如下要求:
C++中内建类型(int,double等)和std::string 都是符合三个条件的。
如果想要将 lexical_cast 用于自定义类,实现 java 中 Object.toString() 的用法,只需要满足 lexical_cast 的要求,实现流输出操作符 operator« 即可。
class demo_class{
friend ostream& operator<<(ostream& os, const demo_class& x){
os << "class content" << endl;
return os;
}
};
int main() {
demo_class demo = demo_class();
cout << lexical_cast<string>(demo) << endl;
}
输出结果:
class content
这篇文章讲如何安装 boost 库,最完整的教程永远在官网。以下内容部分翻译自官方文档。
首先来看一看在Linux下安装 boost 库。
运行以下命令:
sudo apt-get install libboost-all-dev
然后输入密码,安装,安装完之后目录在 /usr/include/boost
下。
Eclipse或者其他IDE中使用 boost 时,需要以下几步,引入头文件,添加库。
C/C++ Build, Cross G++ Linker,Libraries, 添加相应Libraries(-l),并添加相应Library search path(-L) /usr/include
Max 下安装 boost 最简单的方式,就是用 brew:
brew install boost
或者手动安装,参考boost官网
简单翻译:
一部分组件(Header-Only Libraries)在完成1和2以后就能直接用,因为是直接写在hpp的inline函数,但是要利用其它功能,需要build boost库里面的各个组件(步骤4-6)
需要单独编译的库有:
cd path/to/boost_1_60_0
./bootstrap.sh
开始配置,添加 --prefix
选择安装地址
./bootstrap.sh –prefix=path/to/installation/prefix./b2 install
开始安装备注:如果第5步直接输入./bootstrap.sh 则默认会安装到/usr/local下面的include和lib目录下,而/usr是在Macintosh HD下面的一个隐藏目录,到此boost就安装到了电脑上,可以使用它进行编程了。
Mac下默认安装地址是在 /usr/local/include
和 /usr/local/lib
下,因此在配置环境的时候需要注意将boost地址写入。
基本思路和Linux中一样,添加头文件搜索路径,添加lib搜索路径,引用相应lib文件。
/usr/local/include/
和 /usr/local/lib
目录参考:YouTube
其他操作系统请参考以上 YouTube Playlist,我收集整理了一些基本够用了。
Security is the most important thing we should take care at first.
The first thing you login into your VPS using root is to change your root password your VPS provider gave. Run the passwd
to change your root password.
After you run this command, your terminal will prompt you to input new password. So just type your new password twice. Linux will check your new password to prevent simple password or short password. So don’t use any exist words or any password only contains number.
One of the most important security thing is try your best not to login to your VPS using root account. A better way is to create a new user account and do anything you like as this new user.
Following command is to create a new user and set a password for this user. Please replace einverne
as your own name.
# create a new user called einverne
adduser einverne
# set password for user einverne
passwd einverne
After you create a new user account successfully, we give the new user root privileges. Someone may be curious about why we create a new user and grant root privileges, so why don’t we just use root account. There are two points. One is that this can prevent user making system-destroying mistakes, second is that all command run by sudo
will have a record in /var/log/secure
which can be reviewed later if needed.
apt install vim -y
update-alternatives --config editor
choose: vim
Run visudo
command to enter sudo config file. Find a section called user privilege specification. And add a new line under this section like this:
# User privilege specification
root ALL=(ALL) ALL
# new add
einverne ALL=(ALL) NOPASSWD:ALL
Now it’s time to make the server more secure. You can set the ssh configuration to permit root login. But before doing this config, please make sure to have a new account have the root privileges.
Edit ssh config file:
sudo vim /etc/ssh/sshd_config
Then change follow line:
Port 22
PermitRootLogin no
Port means the ssh port you can connect, you can set any number between 1025 and 65535. PermitRootLogin means you can disallow root login, if you set to no.
Finally, add AllowUsers einverne
at the bottom of the sshd_config file.
Then reload the config file to make ssh work.
service ssh reload
To test the new ssh config, do not logout of root. Open a new terminal and login with your new account like:
ssh -p port einverne@server.address
After you set up server ssh, you can generate SSH key at local computer and use SSH key to connect to server rather than using password. Generating a key at local computer:
ssh-keygen -t ed25519 -C "your@email.com"
follow the instruction of this command, for example you name it vps , just enter to skip password of key, and you will get two files under ~/.ssh/
, vps is your private key, keep it safe. And vps.pub is the public key. And Now use ssh-copy-id
to copy public key to server.
ssh-copy-id user@server.address
Then type the password. And it will be the last time to type your password to connect to server. If your computer don’t have the command ssh-copy-id
, you have to copy the public key to server ~/.ssh/authorized_keys
manually.
scp ~/.ssh/name.pub user@server:~/.ssh/
Then copy the file content to authorized_keys
file.
cat name.pub >> authorized_keys
Finally to check the permission of the folder .ssh
and file authorized_keys
drwx------ 2 einverne einverne 4096 Apr 19 21:25 .ssh
-rw------- 1 einverne einverne 744 Apr 19 21:14 authorized_keys
and if not:
chmod 700 ~/.ssh/
chmod 600 authorized_keys
Add alias to .bashrc
or .zshrc
file.
alias vps = "ssh username@server -p port"
Then next time, you can just type vps
to connect to server.
There are two config file to setup ssh. One is system wide configuration file which can be found /etc/ssh/ssh_config
. And another is per-user configuration file which is located under user home directory ~/.ssh/config
. Most time we only care about user config.
Try to set up:
Host ds #this can be anything just a alias
HostName server
Port 22
User username
Then we can use ssh ds
to connect to server. If you have multi config just add to following like:
Host ds
HostName server
Port 22
User einverne
Host github
HostName github.com
Port 22
User einverne
IdentityFile ~/.ssh/private_key_name
After all this, you can type following command to have a try:
scp filename ds:~/filename # copy file to server
ssh ds "ls ~" # list server files
hostnamectl set-hostname example_hostname
设置时区:
sudo dpkg-reconfigure tzdata
单独总结了一篇文章来讲如何测评一个 VPS 性能。
You can use this solution to solve the problem. Or there are some download test file.
Install speedtest package:
pip install speedtest-cli
or
easy_install speedtest-cli
Usage:
$ speedtest-cli -h
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
[--server SERVER] [--mini MINI] [--source SOURCE]
[--timeout TIMEOUT] [--secure] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli
optional arguments:
-h, --help show this help message and exit
--bytes Display values in bytes instead of bits. Does not affect
the image generated by --share
--share Generate and provide a URL to the speedtest.net share
results image
--simple Suppress verbose output, only show basic information
--list Display a list of speedtest.net servers sorted by
distance
--server SERVER Specify a server ID to test against
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers
--version Show the version number and exit
一些机房 100M 测速下载文件地址,用于测速之用
description: VPS 的网络性能,主要分出口和入口二个指标,入口可以用 wget 文件得到。 看下载速度,如果是 11M/s,大概就是百兆口,70M/S,大概就是 G 口。 您的 VPS 搭建好网站环境后,可以用其它的 VPS 去拽这个文件,得到出口的带宽。
Directspace 机房 /10M.100M 测试包 Portland
wget http://bandwidth.directspace.net/10MBtest.zip
wget http://bandwidth.directspace.net/100MBtest.zip
sudo apt install zsh
chsh -s $(which zsh)
logout and login again.
BBR 是 Google 提出的 TCP拥塞控制算法,可以使Linux服务器显著地提高吞吐量和减少TCP连接的延迟,已经提交并合并到了 Linux 内核。
检查是否开启了 BBR:
sudo sysctl net.ipv4.tcp_available_congestion_control | grep bbr
sudo sysctl net.ipv4.tcp_congestion_control | grep bbr
如果开启通常会在结果中包含 bbr。如果没有开启则使用 Teddysun 的一键脚本,注意开启之后需要重启才能生效。
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
Docker become much powerful these days, I can build and sever all my self-host services by using Docker.
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
或者通过一键脚本:
curl -fsSL https://get.docker.com/ | sh
# 启动并设置开机自启docker
systemctl enable --now docker
Executing the docker command without sudo 非 root 用户执行 docker 命令:
# sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
设置后登出,然后登录。
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 如果/usr/local/bin不在PATH里
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
如果使用我的 dotfiles 配置,在 ~/.zshrc
第一次配置的时候就会把 docker-compose
二进制文件拉下来。
sock5 proxy.
first install pip
yum update && yum install python-setuptools
easy_install pip
or use command yum -y install python-pip
to install pip
install shadowsocks using pip
pip install shadowsocks
just run this command
create json config file
vim /etc/shadowsocks.json
edit file as follow:
{
"server":"[ip]",
"server_port":[port],
"local_port":[port],
"password":"[password]",
"timeout":600,
"method":"AES-256-CFB"
}
Explanation of each field:
- server: your hostname or server IP (IPv4/IPv6).
- server_port: server port number.
- local_port: local port number.
- password: a password used to encrypt transfer.
- timeout: connections timeout in seconds.
- method: encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is table, which is not secure. "aes-256-cfb" is recommended.
start server
ssserver -c [json_path] -d start
start service
Second thing is to install lnmp, if you want to host a website on your VPS. You can use screen to install lnmp.
Screen can prevent network connection error during the lnmp installation. You can find more details on the lnmp official site
screen -S lamp
to create a screen sessionwget -c http://soft.vpser.net/lnmp/lnmp1.1-full.tar.gz
tar zxf lnmp1.1-full.tar.gz
cd lnmp1.1-full/
./centos.sh
, If you are using Debian run ./debian.sh
, If you are using Ubuntu run `./ubuntu.shIf you’re ssh connection suddenly failed, you can connect to your server. Then run command screen -r lnmp
to restore your lnmp installation.
From:http://www.vpser.net/manage/run-screen-lnmp.html
After installation, you will see some short instructions.
lnmp status manage: /root/lnmp {start|stop|reload|restart|kill|status}
default mysql root password:12345678
phpinfo : http://yourIP/phpinfo.php
phpMyAdmin : http://yourIP/phpmyadmin/
Prober : http://yourIP/p.php
Add VirtualHost : /root/vhost.sh
The path of some dirs:
mysql dir: /usr/local/mysql
php dir: /usr/local/php
nginx dir: /usr/local/nginx
web dir : /home/wwwroot/default
LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux
This script is a tool to Manage status of lnmp
For more information please visit http://www.lnmp.org
Usage: /root/lnmp {start|stop|reload|restart|kill|status}
说是N6的Tips,当然里面很多都是Android 6.0 隐藏的功能。只要是原生 6.0 的系统都能够开启。
Nexus 6 double tap to wake, root 之后安装一个app即可。
具体参考:xda-developers
原生 Android 6.0 有个小技巧能够开启状态栏的电池百分比,下拉通知栏,长按开启设置的齿轮,会打开Android 6.0 隐藏的设置,此时进入系统设置,会多出一个“System UI Tuner”,进入打开“Show embedded battery percentage”,则能在状态栏电池上显示百分比。
另一个Android 6.0 隐藏功能,可能是官方并未完成对这个功能的开发和测试,但是就使用来看稳定性OK。开启过程如下,一句话就是修改 /system/build.prop。
具体参考:xda-developers
需要第三方kernel,可以根据以下教程自行刷入。
几大常见的kernel:
写给自己备忘:电源键+音量下可以进入recovery mode
详情参考:xda-developers
最后总结一下N6的几个缺点:
摩托罗拉官方网站显示Nexus 6将会有两个版本,分别是美国版的XT1103和国际版的XT1100,两者在基本硬件规格上大部分相同,只是支持的数据流模式和频谱略微有差别。美国版XT1103支持制式频段较少,国际版相对比较通用。
Americas Model (XT1103)
GSM/GPRS/EDGE (850, 900, 1800, 1900 MHz)
CDMA (800, 1900, secondary 800 MHz)
WCDMA (1, 2, 4, 5, 8)
LTE (2, 3, 4, 5, 7, 12, 13, 17, 25, 26, 29, 41)
CA DL (B2-B13, B2-B17, B2-29, B4-B5, B4-B13, B4-B29)
Global Model (XT1100)
GSM/GPRS/EDGE (850, 900, 1800, 1900 MHz)
WCDMA (1, 2, 4, 5, 6, 8, 9, 19)
LTE (1, 3, 5, 7, 8, 9, 19, 20, 28, 41)
CA DL (B3-B5, B3-B8)
XT1100国际版联通3G WCDMA制式可以直接使用,4G LTE部分支持1、3、5、7、8、9、19、20、28、41这些频段,国内联通和电信主要采用FDD-LTE制式中的1、3、7频段,移动则是TD-LTE中的41频段,因此理论上两种制式都可以直接使用。当然理论上永远是理论,毕竟国内运营商具体每个地方用何种频段并不一定,购买前还需要考虑这个问题。
再详细说下:
移动用户:从频段上看无论国际版还是北美版都支持band41,可以接收移动2.6G的4G信号。但用起来肯定不爽,具体原因跟Nexus 5相同,因为移动目前用于广覆盖和室内分布的TDD频段是39和40,而Nexus 6不支持这两个频段。另外Nexus 6也不支持移动3G,导致其极有可能出现Nexus 5一样的情况,接打电话后需要手工调才能返回4G待机。
联通用户:应该无忧,无论国际版还是北美版都支持band3,也就是联通的4G主频段。另外和Nexus 5一样,Nexus 6肯定也是完美支持CSFB语音回落,所以4G会用的很爽。不过话说回来,Nexus 6有的这些东西,Nexus 5国际版同样也有。
电信用户:总的来说,Nexus 6比Nexus 5强,至少在网络支持方面。如果可以接受Nexus 6的6寸巨屏。电信主力4G频段band3,两个版本的Nexus 6都支持,但仅有北美版支持CDMA,因此电信用户只能选择北美版。不过有一点要注意,电信在很多城市还用band1部署了4G,而北美版沿袭了摩托罗拉一贯的鸟样,对于美国本土不用的频段一律不支持,这次竟然连Nexus 5都支持的band1都删了。这样的后果就是,Nexus 6在未来用电信4G时,由于接收不到band1,可能网速会不如其他国内机子。不过亮点是,这次Nexus 6北美版支持Verizon的网络,这意味着,Nexus 5在电信网络上无法实现的CDMA语音回落,在Nexus 6上有99.999999%的可能会完美解决。因为Verizon与电信相同,其4G语音回落方案是:iPhone采用srlte,其他机型svlte。Nexus 5之所以没办法实现电信4G回落,是因为电信没有在基站侧部署1x CSFB,而1x CSFB是美帝Sprint支持的FDD-CDMA语音回落方案。
摘录自:机友会
期待了半年的《火星救援》并没有让我感到失望。
早在今年6月份看到一段预告片之后就将这部电影加入了待看片单,等了半年,在好莱坞大片云集的11月,也没有去看任何影片只等着这一部。马特达蒙,最喜欢的演员,星际宇宙,最喜欢的题材,有这这样的组合怎能不让人期待。
终于在等了半年之后,在25号看了0点场,电影没有让我失望,当然带来的感动和震撼也并没有超出想象。或许是《地心引力》和《星际穿越》的铺垫,让我对此类讲述宇宙的电影有了最基本的感受,宇宙浩瀚的视觉体验,飞船对接的惊险,以及人类在广袤宇宙的渺小。
这部电影的剧情其实很简单,如果稍微做过一些了解,看电影之前应该就能预料到电影中发生的事情,而正是对于这样一部电影,我更加期待的是导演和演员如何在故事剧情整体都被观众了解的情况下去推动剧情的发展。这部电影由Andy Weir小说改编,虽然没有看过小说,但是经过小说的验证,剧情并不会离谱到哪里,所以在看完这部电影之后对整个剧情的设定,情节的发展都没有找到比较大的漏洞。电影基本在沿用两条线叙事,火星上马特达蒙的生存挑战,地球上的营救计划的展开,总体沿用这两条故事线,而中间也穿插了赫尔梅斯号飞船上的故事,到影片的结束,赫尔梅斯号上的故事线和马特达蒙的线合二为一。从剧情上来看,故事整体发展都很平淡,也像之前看到的一些评论说的那样,导演尽量的在克制并没有打温情牌,即使是在片尾才出现的爱情线,也只是淡淡的一笔带过,而主角的亲情戏也是一再的克制,犹记得其中的一个镜头就是马特坐在火星的高地上,镜头从背后绕到前面,而中间伴随着马特的遗言式的自白,这也是我唯一能够想到的提交亲情的戏份。而相比《星际穿越》中的亲情带来的感动,导演 [[Ridley Scott]] 一再的将电影的重心放到营救的整个过程中。
影片是和同学一同前去观看的,部分同学说故事发展太平淡,高潮不明显,其实这部片子的问题也是存在的,片子在极尽所能渲染出火星壮美的地貌的时候无意中拖慢的剧情。在开场火星风暴袭来快速的剧情推动之后,令人印象深刻的马特自救,种土豆之后故事发展就趋于平缓,用淡淡的叙事来铺开,当然最后我能感受到的高潮就是赫尔梅斯号去接马特的时候,这也是全片的最高潮,只是现在回想来,似乎感觉到来的太快,而结束的也太快。
再说到表演,这就不得不提到马特达蒙,几乎是用他一个人的演技支撑起了整部影片,早在《谍影重重》《天才雷普利》《心灵捕手》的时候就深深的喜欢上了这个个性演员,更让我震惊的是他曾经和本阿弗莱克凭借《心灵捕手》获取了奥斯卡最佳电影原创剧本奖,这样一位实力派的演员竟然能够在剧本创作上获得如此殊荣更让我对他刮目相看。而在这部影片中的表现同样没有让人失望,我甚至觉得马特可以凭借这部电影去拼一下奥斯卡最佳男主,令人印象深刻地几场戏出现在开头的自救,在风暴过后,马特被天线击中,他有条不紊的从身体中取出天线的情节实在让人无法忘怀。另外在更多的自白中自然地表现出那种自娱自乐的精神,也只有马特能够表现出来。像很多人说的那样,这就是一部靠马特自救和段子组成的电影。而说到配角,我竟然认出了《纸牌屋》中的那个死掉的记者,是纸牌屋中死掉了所以来拍电影了吗。然后那个黑人主管也看的眼熟却也无法想起在哪里见到过。而赫尔梅斯号上得中尉是杰西卡·查斯坦,这位演员在当时《星际穿越》的时候认识了,但是因为这部戏中的戏份也并不是很多,只在开头很果断的决策和结尾营救马特的时候有些表现,而其他方面只能通过马特说的音乐品味太差来侧面描写一下,所以也看不出演技的好坏。不过让我印象深刻的倒是那个呆萌呆萌的天体物理学家,虽然出场时间也并不是很多,但是却让人眼前一亮,并为之会心一笑。从第一个躺在床上的镜头,到后来开“爱隆会议”,他的表现非常的高效到位。他把那种科学家的自信气质和学术范儿用一种诙谐的方式表现出来,而他的方案也是整个拯救计划中很重要的部分。
在说到娱乐性,对我来说,娱乐性对于这部电影来说应该就算是话题效应了,如果从今年6月份算起,我已经期待这部电影超过了5个月了。对我来说,娱乐性的体现已经足够充分,而在11月份,好莱坞电影集中上映的前提下,我相信《火星救援》也还是依然能够保证充足的话题性。而从另一方面,电影创造出的火星场景来看,也足够具有话题性,从《地心引力》创造的宇宙世界观,《星际穿越》创造的黑洞,好莱坞几乎在以一年一部的速度刷新着我们的宇宙观。而今年几乎是 NASA 的新世纪元年,就在《火星救援》美上映的前几天,NASA 宣布火星发现水,这简直就是给这部影片一个巨大的广告宣传,再到 NASA 今年公布的冥王星的图片,整个世界都被宇宙震撼到了。
最后在豆瓣上我会给剧情8分,表演8分,娱乐性9分。当然这都是带有私心的评分~(≧▽≦)/~啦啦啦。
国内版删去马特达蒙光屁股一段戏。其实这里不得不吐槽一下,很多电影比这个过分的要更多,难道广电只是想刷一下存在感吗?什么都插手一脚却也并没有什么用。可是下面才是我想说的,在我告诉周围人这个删减的时候,周围人竟然说删得好,至于为什么删得好,我是无法理解的,当更重要的是或许是很多人以及习惯了这种删减的日子了吧。
书里解答了我很多观影之后的疑问,帆布的疑惑,栖息仓中的爆炸等等,还有关于火星上大气的气压等等。
当然在电影过后看书的一大缺点就是在看到角色名字的时候不知不觉会在脑海里浮想起电影中的面孔,所以在看大部分沃特尼的自述的时候会想起马特达蒙。不过对我还好,我能记住的演员也就是赫尔梅斯上得几个航天员。当然下面我还要说,其实书中对这些角色的描写我觉得更成功,甚至从几句对白中表现出来的感觉抵得上电影中的画面和情节。
电影对书中内容的改编:
两辆漫游车 书中对于漫游车的改造远远超出电影中的描述,沃特尼花费了大量的时间去改造漫游车,而这部分情节在电影上被省去了,或许是从电影表现来看并不是最佳的情节。在电影后半段时期,火星上的交代变少,更多的是展现火星神奇的地貌,而书中反而不是这样,在漫游车改造的过程中,沃特尼失去了地球的联络,只能依靠自己的知识改造漫游车。并且在之后的移动过程中是没有和 NASA 的联络的。
电影中删减了很多沃特尼去往3000+公里外的 MAV 的情节 这也是在上面说到的一点,沃特尼在前往 MAV 的过程中没有人去协助,只依靠自己的努力,小说中甚至描述了他遭遇火星沙尘暴的情节,而在电影中几乎完全没有被提及,这也导致我在观影中感受到的电影中后段故事趋于平缓,当然这可能也是为了缩减电影时长而不得已为之,但是这一段沃特尼自救的部分真是惊心动魄,既紧张又充满刺激,当然在我为沃特尼这种临危不乱的精神敬佩的时候,沃特尼用自己的聪明才智已经快到达目的地了。
小说中对配角形象的塑造更加成功 这里我不得不说,小说对这些配角的形象塑造更加生动。小说中在赫尔梅斯上得情节描述较电影多,而小说对地面 NASA 等的描述较小说少,所以从小说中能看到诙谐幽默,时常开玩笑的马丁尼兹,能看到指挥果断地刘易斯指挥官,还有搞办公室恋爱的约翰森,他们的形象,加上之前在电影中留下的记忆,共同组成他们成为一个角色的特征。
对指挥官刘易斯的改编 看过电影的人应该都知道,最后是指挥官刘易斯去营救的沃特尼,其实当时看完电影并没有感觉到什么不适,但是后来想一想,虽然航天员什么方面都会训练一下,但是指挥官并没有什么特殊的理由让自己代替另一个专业航天员去营救沃特尼,当然这也可能是电影剧本的要求吧,因为我对那个人也真没多少印象,赫尔梅斯上一共六个人,上面提到的3个加上沃特尼,剩下的两个实在是没什么印象了,所以在最后电影中换成指挥官也情有可原吧。
和其他 Version Control System 一样,git 也有方法来触发自定义脚本。
两类 hooks:
hook 脚本在 hooks
子目录下,大部分是 .git/hooks
下。在使用 git init
之后就会初始化一些 sample 脚本,在 hooks 下都以 .sample
结尾,如果要使用则需要将 .sample
后缀去掉。
pre-commit
hook 会在输入 commit message 之前被执行。
通常可以在该 hook 中检查代码是否被提交,运行 test,代码格式检查,或者其他 lint 工具检查。如果脚本返回 non-zero 值会阻断 commit。
prepare-commit-msg
hook 会在 commit message 编辑器被调用前,在默认 message 被创建后被触发。这可以使得你可以自定义默认 message。这个 hook 接受一些参数:
commit-msg
hook 接受一个参数,可以在该 hook 中检查 commit message。
在整个 commit 结束后, post-commit
hook 会执行。不接受任何参数。通常该 hook 用来发送一些通知。
在 java 中 try catch 的时候,大多数情况下是使用的 Exception,但是今天看代码有些却 catch 了 Throwable,于是总结下。
看 JDK 源码知道 Throwable 是 Exception 的超类,也同样是 Error 的超类,所以可想而知,如果 catch 了 Throwable,那么会连同 Exception 和 Error 一同 catch,这样也不会丢异常。
Error
通常是不可恢复的错误当程序发生不可控错误,抛出 Error 错误,与异常不同的是 Error 及其子类对象不应该被抛出。通常发生 Error 时需要介入处理。
功能比较强大,比较重要的几个 Plugin 都在单独的文章中做了介绍,这里单独的列举一些特定场景使用的插件,带有语法高亮等的插件,比如针对 Nginx 配置, Dockerfile 文件等等的插件。
优化 nginx 配置
Plug 'chr4/nginx.vim'
Plug 'fatih/vim-go'
Plug 'kchmck/vim-coffee-script'
" CoffeeScript
Plugin 'mtscout6/vim-cjsx'
tr 是 translate 的缩写。
tr [OPTION] SET1 [SET2]
translate SET1 to SET2
cat "abc" | tr a-z A-Z
cat "abc" | tr [:lower:] [:upper:]
echo "a b" | tr [:space:] '\t'
echo ‘{abc}’ | tr ‘{}’ ‘()’ (abc)
删除 -d
指定的字符集
echo "abc" | tr -d 'a'
bc
删除数字
➜ echo "123abc123" | tr -d [:digit:]
abc
删除连续空白
➜ echo "emmmmmmmmmm no" | tr -s [:space:] ' '
emmmmmmmmmm no %
echo "abbbbccccbd" | tr -s a-z A-Z
ABCBD
比如说想要删除除了数字之外的内容
➜ echo "my id is 123" | tr -cd [:digit:]
123%
单独使用 -c
选项则表示将 不是 SET1 中的内容,替换为 SET2 中内容
➜ echo 'abc123' | tr -c [:digit:] x
xxx123x%
You can install lua in Linux Mint/Debian/Ubuntu.. You can find all verions of lua here.
wget http://www.lua.org/ftp/lua-5.3.1.tar.gz
tar zxf lua-5.3.1.tar.gz
cd lua-5.3.1
make linux test
Finally, if test have passed, then install lua into the right place by running sudo make install
:
einverne@mint ~/Downloads/lua-5.3.1 $ sudo make install
[sudo] password for einverne:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.3 /usr/local/lib/lua/5.3
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1
According to the output, we know that lua header files are located under /usr/local/include
. And liblua.a
lib is located under /usr/local/lib
. This two paths may be used later when coding with C/C++. And most important thing executalbe file is located under /usr/local/bin
. Most of the Linux distributions are installed lua by default. But most of them don’t have liblua.a installed.
If you want to build from source code like under linux, just change make linux test
into make macosx test
. And all the following steps are the same as I mentioned in the Linux section.
If you want a more convenient way to install lua, you can download binary package here. And click next and next to finish installation.Default installation path is same as in Linux.
And id you are using Homebrew just run brew install lua
, everything is done.
And you can find more ways to install lua on lua-users.org
please see: http://lua-users.org/wiki/LuaDistributions
After installation , run lua -v
to check the lua version. Test lua by printing “hello world” using following code. Run lua
in terminal:
einverne@mint ~ $ lua
Lua 5.3.1 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> print "hello world"
hello world
Type Control+D to exit.
If you want to find a lua IDE, I highly recommend Zerobrane Studio. It is cross-platform and support different versions of lua from 5.1 to lastest 5.3. And it has a debugger build-in, which is great for debug lua code from local or remote. It is worth to have a try.