Java中Infinity和NaN

i == i + 1

一个数字永远不会等于它自己加1?Java 强制要求使用IEEE 754 浮点数算术运算[IEEE 754],它可以让你用一个double 或float来表示无穷大。正如我们在学校里面学到的,无穷大加1还是无穷大。

你可以用任何被计算为无穷大的浮点算术表达式来初始化i,例如:

1
double i = 1.0 / 0.0;

不过,你最好是能够利用标准类库为你提供的常量:

1
double i = Double.POSITIVE_INFINITY;

More

Java中mutable对象和immutable对象的区别

mutable对象这个概念,维基百科定义如下:

“In object-oriented and functional programming, an immutable object (unchangeable[1] object) is an object whose state cannot be modified after it is created.[2] This is in contrast to a mutable object (changeable object) , which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change but the object’s state appears to be unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.”

在面向对象和函数式编程中,一个immutable对象(不可变对象)是指一旦创建之后状态不可改变的对象。mutable对象(可变对象)是指创建之后也可以修改的对象。在有些情况下,对象也被认为是不可变的(immutable),即,一个对象包含的内部使用的属性改变了,但从外部看对象的状态并没有改变。例如,一个使用memoization来缓存复杂计算结果的对象仍然被看作是不可变(immutable)对象. 在面向对象编程中,String 以及其他的具体对象都被看作是不可变(immutable)对象,以提高可读性和运行效率。

More

常见的游戏分类

游戏类型主要分为:ACT、FTG、STG、FPS、SLG、RTS、RTT、RPG、AVG、SIM、SPG、RAC、PUZ、MUG、LVG、CAG、ETC等其他类型。

缩写 全写 分类
ACT Action Game 动作过关类
ARPG 动作角色扮演类
AVG 冒险类
ETC 其它类
FTG Fight Technology Game 格斗类
FREE 完全反射视点类
MUG 音乐类
PUZ 方块类
RAC 赛车类
RPG 角色扮演类
SLG 策略模拟类
SRPG 战略角色扮演类
SPT 体育类
STG 射击类
TAB 桌面类
MMORPG Massively Multiplayer Online 网络游戏(大型多人在线角色扮演游戏)
TRPG Table Role Playing Game (纸上角色扮演游戏)指没有电脑成分,玩家靠纸,笔进行的最古老的角色扮演游戏。

More

C++11中多线程thread详解

参考: http://en.cppreference.com/w/cpp/thread/thread

joinable

Check if joinable Returns whether the thread object is joinable.
返回线程对象是否是joinable的。

A thread object is not joinable in any of these cases:
下列任一情况都是非joinable

if it was default-constructed.
默认构造器构造的。

if it has been moved from (either constructing another thread object, or assigning to it).
通过移动构造获得的。

if either of its members join or detach has been called.
调用了join或者detach方法的。

我们来看源码,实际上该函数就是判断当前线程的id是否为0

源码如下:

More

浏览器排版引擎

KHTML是HTML网页排版引擎之一,由KDE所开发。

KDE系统自KDE2版起,在档案及网页浏览器使用了KHTML引擎。该引擎以C++编程语言所写,并以LGPL授权,支援大多数网页浏览标准。由于微软的Internet Explorer的占有率相当高,不少以FrontPage制作的网页均包含只有IE才能读取的非标准语法,为了使KHTML引擎可呈现的网页达到最多,部分IE专属的语法也一并支援。

More

浏览器内核

Trident(IE内核):该内核程序在1997年的IE4中首次被采用,是微软在Mosaic代码的基础之上修改而来的,并沿用到IE11,也被普遍称作”IE内核”。Trident实际上是一款开放的内核,其接口内核设计的相当成熟,因此才有许多采用IE内核而非IE的浏览器(壳浏览器)涌现。

由于IE本身的“垄断性”(虽然名义上IE并非垄断,但实际上,特别是从Windows 95年代一直到XP初期,就市场占有率来说IE的确借助Windows的东风处于“垄断”的地位)而使得Trident内核的长期一家独大,微软很长时间都并没有更新Trident内核,这导致了两个后果——一是Trident内核曾经几乎与W3C标准脱节(2005年),二是Trident内核的大量 Bug等安全性问题没有得到及时解决,然后加上一些致力于开源的开发者和一些学者们公开自己认为IE浏览器不安全的观点,也有很多用户转向了其他浏览器,Firefox和Opera就是这个时候兴起的。非Trident内核浏览器的市场占有率大幅提高也致使许多网页开发人员开始注意网页标准和非IE浏览器的浏览效果问题。

More

AOT和JIT比较

AOT (Ahead-Of-Time - 预先编译) 也称静态编译

内存占用低,启动速度快,可以无需 runtime 运行,直接将 runtime 静态链接至最终的程序中,但是无运行时性能加成,不能根据程序运行情况做进一步的优化

JIT (Just-In-Time - 实时编译) 也称动态编译

吞吐量高,有运行时性能加成,可以跑得更快,并可以做到动态生成代码等,但是相对启动速度较慢,并需要一定时间和调用频率才能触发 JIT 的分层机制

More

Ansible内置主机变量

Ansible内置主机变量

字段 名称
ansible_ssh_host ansible通过ssh连接的IP或者FQDN
ansible_ssh_port SSH连接端口
ansible_ssh_user 默认SSH连接用户
ansible_ssh_pass SSH连接的密码(这是不安全的,ansible极力推荐使用–ask-pass选项或使用SSH keys)
ansible_sudo_pass sudo用户的密码
ansible_connection SSH连接的类型:local,ssh,paramiko,在ansible 1.2之前默认是paramiko,后来智能选择,优先使用基于ControlPersist的ssh(支持的前提)
ansible_ssh_private_key_file SSH连接的公钥文件
ansible_shell_type 指定主机所使用的shell解释器,默认是sh,你可以设置成csh, fish等shell解释器
ansible_python_interpreter 用来指定python解释器的路径
ansible_*_interpreter 用来指定主机上其他语法解释器的路径,例如ruby,perl等

More

Ansible文件模块

文件模块

序号 模块名 英文解释 中文说明
1 acl Sets and retrieves file ACL information -
2 archive Creates a compressed archive of one or more files or trees 压缩文件
3 assemble Assembles a configuration file from fragments -
4 blockinfile Insert/update/remove a text block surrounded by marker lines -
5 copy Copies files to remote locations 拷贝文件
6 fetch Fetches a file from remote nodes 从远程节点拉取一个文件
7 file Sets attributes of files 给文件设置属性
8 find Return a list of files based on specific criteria -
9 ini_file Tweak settings in INI files -
10 iso_extract Extract files from an ISO image -
11 lineinfile Ensure a particular line is in a file, or replace an existing line using a back-referenced regular expression
12 patch Apply patch files using the GNU patch tool -
13 replace Replace all instances of a particular string in a file using a back-referenced regular expression -
14 stat Retrieve file or file system status -
15 synchronize A wrapper around rsync to make common tasks in your playbooks quick and easy -
16 tempfile Creates temporary files and directories -
17 template Templates a file out to a remote server -
18 unarchive Unpacks an archive after (optionally) copying it from the local machine 解压一个从本地拷贝的文件
19 xattr set/retrieve extended attributes -
20 xml Manage bits and pieces of XML files or strings -

More