linux

POSIX ACL详解

一、 为什么要使用ACL

先让我们来简单地复习一下Linux的文件权限。
在 linux下,对一个文件(或者资源)可以进行操作的对象被分为三类: file owner(文件的拥有者),group(组,注意不一定是文件拥有者所在的组), other (其他)而对于每一类别又分别定义了read, write and execute/search 权限 (这里不讨论SUID, SGID以及Sticky bit的设置)通过ls -l命令就我们就可以列出一个文件的权限

代码:

[leonard@localhost ~]$ ls -l
-rw-rw---- 1 leonard admin 0 Jul 3 20:12 test.txt

在这里说明了对于test.txt这个文件leonard用户(由是file owner)拥有read & write权限. 所有属于admin 组的用户(group)拥有read & write 权限. 其他任何用户(other)
对于文件没有任何的权限

如果我们现在希望john这个用户也可以对test.txt文件进行读写操作. 我自己大概会想到
以下几种办法 (这里假设john不属于admin group)

1. 给文件的other类别增加读和写的权限. 这样由于john会被归为other类别,那么他也将拥有读写的权限。
2. 将john加入到admin group. 那么john会被归为group类别,那么他将拥有读写的权限。
3. 设置sudo, 使john能够以leonard的身份对test.txt进行操作,从而获得读写权限。
  • 第一种做法的问题在于所有用户都将对test.txt拥有读写操作,显然这种做法不可取。

  • 第二种做法的问题在于john被赋予了过多的权限.所有属于admin组的文件,john都可以拥
    有其等同的权限了。

  • 第三种做法虽然可以达到只限定john用户一人拥有对test.txt文件的读写权限.但是需要
    对sudoers文件进行严格的格式控制. 而且当文件数量和用户很多的时候,这种方法就相当
    地不灵活了。看来好像都没有一个很好的解决方案. 其实问题就出在Linux 文件权限里面,对于other的定义过于广泛,以至于很难把权限限定于一个不属于file owner和group的用户身上. 那Access Control List (ACL)就是用来帮助我们解决这个问题的。

简单地来说ACL就是可以设置特定用户或者用户组对于一个文件/文件夹的操作权限. 需要
掌握的命令也只有三个: getfacl, setfacl, chacl

在接下去讨论之前大家可以先安装上ACL的RPM包
代码:

# rpm -ivh libacl-2.2.39-1.1 acl-2.2.39-1.1.i386.rpm

如果配置好了yum可以直接安装这两个包

# yum -y install libacl acl

另外还需要磁盘分区的支持永久启用acl。我这里以自己的分区/data为例

# vi /etc/fstab
LABEL=/data /data ext3 defaults,acl 1 2

在启用了acl参数之后重新加载/data分区

# mount -o remount /data
# cat /etc/mtab | grep /data
/dev/sda5 /data ext3 rw,acl 0 0

出现上面的信息代表分区的acl功能已经正常加载

 

二、ACL的名词定义

先来看看在ACL里面每一个名词的定义.这些名词我大多从man page上摘下来虽然有些枯燥,
但是对于理解下面的内容还是很有帮助的

ACL 是由一系列的Access Entry所组成的. 每一条Access Entry定义了特定的类别可以对
文件拥有的操作权限. Access Entry有三个组成部分: Entry tag type, qualifier
(optional), 权限

我们先来看一下最重要的Entry tag type, 它有以下几个类型

  • ACL_USER_OBJ: 相当于Linux里file_owner的权限
  • ACL_USER: 定义了额外的用户可以对此文件拥有的权限
  • ACL_GROUP_OBJ: 相当于Linux里group的权限
  • ACL_GROUP: 定义了额外的组可以对此文件拥有的权限
  • ACL_MASK: 定义了ACL_USER, ACL_GROUP_OBJ和ACL_GROUP的最大权限 (这个我下面还会专门讨论)
  • ACL_OTHER: 相当于Linux里other的权限

让我们来据个例子说明一下. 下面我们就用getfacl命令来查看一个定义好了的ACL文件

代码:

[root@zyq-server data]# getfacl test.txt
# file: test.txt
# owner: root
# group: family
user::rw-
user:zyq:rw-
group::rw-
group:jackuser:rw-
mask::rw-
other::---

前面三个以#开头的定义了文件名,文件所有者和文件拥有组. 这些信息没有太大的作用,我
们可以用 –omit-header来省略掉
user::rw- 定义了ACL_USER_OBJ, 说明file owner拥有读和写的权限

user:zyq:rw- 定义了ACL_USER,这样用户zyq就拥有了对文件的读写权限,实现了我们一开始要达到的目的

group::rw- 定义了ACL_GROUP_OBJ,说明文件的group拥有read和write 权限

group: jackuser:rw- 定义了ACL_GROUP,使得jackuser组拥有了对文件的read 和write权限

mask::rw- 定义了ACL_MASK的权限为read and write

other::— 定义了ACL_OTHER的没有任何权限操作此文件

从这里我们就可以看出ACL提供了我们可以定义特定用户和用户组的功能. 那么接下来我们就来
看一下如何设置一个文件的ACL

 

三、 如何设置ACL文件

首先我们还是要讲一下设置ACL文件的格式. 从上面的例子中我们可以看到每一个Access Entry都是由三个被:号分隔开的字段所组成. 第一个就是Entry tag type

user 对应了ACL_USER_OBJ和ACL_USER
group 对应了ACL_GROUP_OBJ和ACL_GROUP
mask 对应了ACL_MASK
other 对应了ACL_OTHER

第二个字段称之为qualifier.也就是上面例子中的zyq和jackuser组.它定义了特定用户和用户组,对于文件的权限.这里我们也可以发现只有user和group才有qualifier,其他的都为空.
第三个字段就是我们熟悉的权限了. 它和Linux的权限一样定义,这里就不多讲了
下面我们就来看一下怎么设置test.txt这个文件的ACL让它来达到我们上面的要求

一开始文件没有ACL的额外属性

代码:

[root@zyq-server data]# ll test.txt
-rw-r--r-- 1 root root 0 12-27 22:55 test.txt
[root@zyq-server data]# getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@zyq-server data]# getfacl -c test.txt
user::rw-
group::r--
other::r--

我们先让用户zyq拥有对test.txt文件的读写权限

代码:

[root@zyq-server data]# setfacl -m u:zyq:rw test.txt
[root@zyq-server data]# getfacl -c test.txt
user::rw-
user:zyq:rw-
group::r--
mask::rw-
other::r--

这时我们就可以看到zyq用户在ACL里面已经拥有了对文件的读写权限. 这个时候如果我们
查看一下linux的权限我们还会发现一个不一样的地方

代码:

[root@zyq-server data]# ll test.txt
-rw-rw-r--+ 1 root root 0 12-27 22:55 test.txt

在文件权限的最后多了一个+号. 当任何一个文件拥有了ACL_USER或者ACL_GROUP的值以后我
们就可以称它为ACL文件.这个+号就是用来提示我们的
我们还可以发现当一个文件拥有了ACL_USER或者ACL_GROUP的值时ACL_MASK同时也会被定义

接下来我们来设置jackuser组拥有read 权限

代码:

[root@zyq-server data]# ll test.txt
-rw-rw-r--+ 1 root root 0 12-27 22:55 test.txt
[root@zyq-server data]#
[root@zyq-server data]# setfacl -m g:jackuser:r test.txt
[root@zyq-server data]# getfacl -c test.txt
user::rw-
user:zyq:rw-
group::r--
group:jackuser:r--
mask::rw-
other::r--

[root@zyq-server data]# ll test.txt
-rw-rw-r--+ 1 root root 0 12-27 22:55 test.txt

到这里就完成了我们上面讲到的要求.是不是很简单呢

 

四、ACL_MASK 和 Effective 权限

这里需要重点讲一下ACL_MASK, 因为这是掌握ACL的另一个关键,在Linux 文件权限里面大家都知道比如对于rw-rw-r–来说, 第二组中的那个rw-是指文件组的权限. 但是在ACL里面这种情况只是在ACL_MASK不存在的情况下成立. 如果文件有ACL_MASK值,那么当中那个rw-代表的就是mask值而不再是group 权限了

让我们来看下面这个例子

代码:

[root@zyq-server data]# ll test.sh
-rwxrw-r-- 1 root family 0 12-27 23:04 test.sh

 

 

这里说明test.sh文件只有file owner: root拥有read, write, execute/search 权限. Family组只有读和写的权限。现在我们想让用户zyq也对test.sh具有和root一样的权限。

代码:

[root@zyq-server data]# setfacl -m u:zyq:rwx test.sh
[root@zyq-server data]# getfacl -c test.sh
user::rwx
user:zyq:rwx
group::rw-
mask::rwx
other::r--

这里我们看到zyq已经拥有了rwx的权限. mask值也被设定为rwx.那是因为它规定了ACL_USER,ACL_GROUP和ACL_GROUP_OBJ的最大值现在我们再来看test.sh的Linux 权限, 它已经变成了

代码:

[root@zyq-server data]# ll test.sh
-rwxrwxr--+ 1 root family 0 12-27 23:04 test.sh

 

 

那么如果现在family组的用户想要执行test.sh的程序会发生什么情况呢? 它会被权限 deny.原因在于实际上family组的用户只有读和写的权限.这里当中显示的rwx是ACL_MASK的值而不是group的权限,所以从这里我们就可以知道,如果一个文件后面有+标记,我们都需要用getfacl来确认它的权限,以免发生混淆

下面我们再来继续看一个例子
假如现在我们设置test.sh的mask为read only,那么family组的用户还会有write 权限吗?

代码:

[root@zyq-server data]# setfacl -m mask::r test.sh
[root@zyq-server data]# getfacl -c test.sh
user::rwx
user:zyq:rwx #effective:r--
group::rw- #effective:r--
mask::r--
other::r--

这时候我们可以看到ACL_USER和ACL_GROUP_OBJ旁边多了个#effective:r–, 这是什么意思呢?让 我们再来回顾一下ACL_MASK的定义. 它规定了ACL_USER, ACL_GROUP_OBJ和ACL_GROUP的最大权限.那么在我们这个例子中他们的最大权限也就是read only.虽然我们这里给ACL_USER和ACL_GROUP_OBJ设置了其他权限,但是他们真正有效果的只有read权限.
这时我们再来查看test.sh的Linux 文件权限时它的group 权限也会显示其mask的值(i.e. r–)

代码:

[root@zyq-server data]# ll test.sh
-rwxr--r--+ 1 root family 0 12-27 23:04 test.sh

 

 

五、 Default ACL

上面我们所有讲的都是Access ACL, 也就是对文件而言. 下面我简单讲一下Default ACL. Default ACL是指对于一个目录进行Default ACL设置,并且在此目录下建立的文件都将继承此目录的ACL.同样我们来做一个试验说明比如现在leonard用户建立了一个dir目录

代码:

[root@zyq-server data]$ mkdir mydir

我希望所有在此目录下建立的文件都可以被smbuser用户所访问. 那么我们就应该对mydir目录设置Default ACL.我先利用root用户在/data/创建一个mydir的文件夹,然后将这个文件夹的default user权限设置为smbuser可以rw- 以root身份在mydir目录下创建一个test.txt的文件。其他的不做限制,然后切换到smbuser。发现smbuser用户可以修改 test.txt文件中的内容但是无法在mydir目录中创建和删除文件/文件夹

代码:

[root@zyq-server data]# id
uid=0(root) gid=0(root) groups=0(root)
[root@zyq-server data]# ll mydir/
总计 0
[root@zyq-server data]# getfacl mydir/
# file: mydir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@zyq-server data]# setfacl -m d:smbuser:rw mydir/
[root@zyq-server data]# getfacl mydir/
# file: mydir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:smbuser:rw-
default:group::r-x
default:mask::rwx
default:other::r-x

[root@zyq-server data]# cd mydir/
[root@zyq-server mydir]# touch test.txt
[root@zyq-server mydir]# su - smbuser
[smbuser@zyq-server ~]$ cd /data/mydir/
[smbuser@zyq-server mydir]$ touch a
touch: 无法创建 “a”: 权限不够
[smbuser@zyq-server mydir]$ rm test.txt
rm: 无法删除 “test.txt”: 权限不够
[smbuser@zyq-server mydir]$ echo hello world>>test.txt
[smbuser@zyq-server mydir]$ cat test.txt
hello world

这里我们可以看到ACL定义了default选项, smbuser用户拥有了default的read, write, excute/search 权限.但是却无法删除和创建文件。经过试验,发现还必须将mydir目录的ACL_USER修改为smbuser后,切换到smbuser用户才能够在 mydir目录中创建和删除文件/文件夹

[root@zyq-server data]# setfacl -m u:smbuser:rwx mydir/
[root@zyq-server data]# getfacl -c mydir/
user::rwx
user:smbuser:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:smbuser:rw-
default:group::r-x
default:mask::rwx
default:other::r-x

[root@zyq-server data]# su - smbuser
[smbuser@zyq-server ~]$ cd /data/mydir/
[smbuser@zyq-server mydir]$ touch a
[smbuser@zyq-server mydir]$ ll
总计 4
-rw-rw-r--+ 1 smbuser family 0 12-27 23:43 a
-rw-rw-r--+ 1 root root 19 12-27 23:33 test.txt
[smbuser@zyq-server mydir]$ rm * -rf
[smbuser@zyq-server mydir]$

 

 

下面的试验我们看到在mydir下建立的文件或文件夹都自动的加上了default的权限

[root@zyq-server mydir]# su - smbuser
[smbuser@zyq-server ~]$ cd /data/mydir/
[smbuser@zyq-server mydir]$ ll

总计 0

-rw-rw-r--+ 1 root root 0 12-27 23:48 a
-rw-rw-r--+ 1 root root 0 12-27 23:48 test.tt
[smbuser@zyq-server mydir]$ rm * -rf
[smbuser@zyq-server mydir]$ touch test.txt
[smbuser@zyq-server mydir]$ ll

总计 0

-rw-rw-r--+ 1 smbuser family 0 12-27 23:48 test.txt
[smbuser@zyq-server mydir]$ getfacl -c test.txt
user::rw-
user:smbuser:rw-
group::r-x #effective:r--
mask::rw-
other::r--

[smbuser@zyq-server mydir]$ mkdir smbuserdir
[smbuser@zyq-server mydir]$ getfacl -c smbuserdir/
user::rwx
user:smbuser:rw-
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:smbuser:rw-
default:group::r-x
default:mask::rwx
default:other::r-x

[smbuser@zyq-server mydir]$ ll
总计 4
drwxrwxr-x+ 2 smbuser family 4096 12-27 23:49 smbuserdir
-rw-rw-r--+ 1 smbuser family 0 12-27 23:48 test.txt

六、 ACL 相关命令

前面的例子中我们都注意到了getfacl命令是用来读取文件的ACL, setfacl是用来设定文件的Acess ACL. 这里还有一个chacl是用来改变文件和目录的Access ACL and Default ACL. 它的具体参数大家可以去看man page. 我只想提及一下chacl -B. 它可以彻底删除文件或者目录的ACL属性(包括Default ACL). 比如你即使用了setfacl -x删除了所有文件的ACL属性,那个+号还是会出现在文件的末尾.所以正确的删除方法应该是用chacl -B.
用cp来复制文件的时候我们现在可以加上-p选项.这样在拷贝文件的时候也将拷贝文件的ACL属性.对于不能拷贝的ACL属性将给出警告.mv命令将会默认地移动文件的ACL属性. 同样如果操作不允许的情况下会给出警告

 

七. 需要注意的几点

如果你的文件系统不支持ACL的话,你也许需要重新mount你的file system

mount -o remount, acl [mount point]

如果用chmod命令改变Linux 文件权限的时候相应的ACL值也会改变.反之改变ACL的值,相应的文件权限也会改变

八. 参考资料

    1. man acl 个人感觉man page已经讲的比较详细,只是上面名词比较多看起来会比较繁琐
    1. http://www.suse.de/~agruen/acl/linux-acls/online/ 如果你英语不错的话可以看一下这篇关于POSIX ACL的介绍,上面有许多不错的例子
programming \ java \ programming \ php

java vs php

小编最近经心情不大好,写一篇博文解解闷

在搞清楚java vs php前,我们需要熟悉一些基本概念才能很好的理解下面的对比,否则看了都感觉不知道什么意思

基本概念

1,并发 vs 并行

并发和并行进行区分还是挺简单的,用erlang之父Joe Armstrong画的一张图说明一下:

parallel_vs_concurency

并发是两个队列交替使用一台咖啡机,并行是两个队列同时使用两台咖啡机,如果串行,一个队列使用一台咖啡机,如果前面那个人接好咖啡一直不离开,会导致后面的人都没有咖啡喝.就像程序中一个独享资源被占用,其他线程就处于等待中一样,但是并发通过某种机制,比如时间分片等,规定每个人只能使用咖啡机30秒钟,那么1分钟当中,并发就可以做到2次,所以并发的大小和占用资源的时间是负相关的,资源占用时间短才能够做到高并发

2.吞吐率(Requests per second)

这个比较好理解,每秒能够处理的请求数,越大越好,说白了这个跟发动机功率一样,越大代表性能越强
计算公式:
Request per second = Complete requests / Time taken for tests

3,用户平均请求等待时间Time per request

计算公式:
处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数)
Time per request = Time taken for tests /( Complete requests / Concurrency Level)

4,服务器平均请求等待时间(Time per request: across all concurrent requests)

计算公式:
处理完成所有请求数所花费的时间 / 总请求数
Time taken for / testsComplete requests

php vs java

了解完了上面的这些基本概念,下面我们把PHP和java进行比较,本次实验条件说明(都在小编的电脑上,MacBook Pro Intel Core i7 2.2 GHz memory 16 GB,java和php都没有进行优化,php采用lnmp架构,java采用spring内嵌服务器,都输出一个相同json字符串接口)

对比一
ab -n 100 -c 10 http://192.168.200.299:8080/greeting?name=desheng

item java php
Concurrency Level 10 10
Time taken for tests 0.068 seconds 0.108 seconds
Complete requests 100 100
Failed requests 10 91
Total transferred 15604 bytes 19292 bytes
HTML transferred 3704 bytes 3592 bytes
Requests per second 1477.76 [#/sec] (mean) 922.77 [#/sec] (mean)
Time per request(user) 6.767 [ms] (mean) 10.837 [ms] (mean)
Time per request(server) 0.677 [ms] (mean, across all concurrent requests) 1.084 [ms] (mean, across all concurrent requests)
Transfer rate 225.19 [Kbytes/sec] received 173.85 [Kbytes/sec] received

总结:

  • 从发现Time per request(server)这个指标中,我们可以看出java处理效率比php高,脚本语言不敌伪编译,可以预想的到,如果改成c/c++可能效率提升更加的大
  • 从Requests per second指标中可以看出,java采用的是多线程,php采用的是多进程,java线程可以轻轻松松上千,php只能望洋兴叹了

对比二

ab -n 100 -c 100 http://www.yunying.com/?name=desheng

item java php
Concurrency Level 100 100
Time taken for tests 0.043 seconds 0.130 seconds
Complete requests 100 100
Failed requests 0 90
Total transferred 15700 bytes 19288 bytes
HTML transferred 3800 bytes 3588 bytes
Requests per second 2346.70 [#/sec] (mean) 768.95 [#/sec] (mean)
Time per request(user) 42.613 [ms] (mean) 130.047 [ms] (mean)
Time per request(server) 0.426 [ms] (mean, across all concurrent requests) 1.300 [ms] (mean, across all concurrent requests)
Transfer rate 359.80 [Kbytes/sec] received 144.84 [Kbytes/sec] received

总结:

  • 对比一 vs 对比二中的Time per request(server),java居然越跑越快,php只会越跑越慢,这是因为java开启了JIT,对执行代码进行了优化,但是php没有开启opcahe,所以越来越慢了.
  • 对比Requests per second数据,发现php死活超不了一千的槛,

对比三

ab -n 1000000 -c 1000 http://192.168.200.229:8080/greeting?name=desheng

item java php
Concurrency Level 1000
Time taken for tests 302.511 seconds
Complete requests 1000000
Failed requests 991501
Total transferred 159894503 bytes
HTML transferred 40894503 bytes
Requests per second 3305.66 [#/sec] (mean)
Time per request(user) 30.251 [ms] (mean)
Time per request(server) 0.303 [ms] (mean, across all concurrent requests)
Transfer rate 516.17 [Kbytes/sec] received

总结:

  • java还能跑,但是php已经被压挂了(pr_socket_recv: Connection reset by peer (104)),已经连接不上了

终结:

虽然我很喜欢php简单明了的设计理念,快速并且灵活开发应用,实现功能可以依托大神开发的扩展,但是如果对性能有要求的领域,php就不那么合适了.PHP官网是这么说PHP的:

“PHP is a popular general-purpose scripting language that is especially suited to web development.Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.”

从上面这句话中我们就能感觉到php并没有提到高性能,由此我们彻底的明白了,php面对巨大的编程市场,没有和java一样选择大而全的布局,而是希望有那么一群人,他们希望web编程的成本足够的低,开发的周期足够的短,但是完全能满足日常普通用户的访问需求.就像polo,普通版高尔夫,飞度等车型一样,他只能满足你日常代步的需求,但是你想让他上赛道比赛,输的命运很难改写.所以在创办企业选择编程语言的时候,先看看自己的预算,再看看自己的目标,差不多答案就有了.顺便回答一下facebook为什么用PHP,那是因为facebook刚开始没钱,而且没想到自己有这么火.今天就说到这里吧.时间不早了,洗洗睡吧

文档信息

版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)

本文出自 “richardtumas”的博客,请务必保留此

发表日期: 2017年8月11日

邮件: joy@richardtumas.com

诺诺是我侄女

编码详解

 

小编最近经常被字符编码的事情搞得头都大了,翻阅了各种文档,最后终于理解了,毫无保留分享一下.

1 概念

首先需要搞明白一件事情,什么是字符,字符集,字符编码,搞清楚之后那么理解起来就会非常的顺利了.

字符;说白了就是符号,比如,”你”,”y”,”?”,就是你能在计算机能看到的符号,图片和视频不算符号.数据结构不一样

字符集:是 字符 集合,说白了就是一群符号.比如GBK,UNICODE等,如果某一个符号不在这个字符集中,打死计算机都表示不出来.就像给你生僻字,”嚋”,你的脑袋里没有影响,你就不认得了.计算机也是同理的.字符集决定计算机能表达什么东西

编码:计算机的全部数据都是二进制.怎么用二进制表示上面的这些符号,(最小的存储单位是byte,8位二进制),就是编码要做的事情.

2 ASCII码

ascii码是计算机刚开始出现的时候使用的字符集.只能表示英文字符,标点符号,控制字符.
由于需要表示的字符不是很多采用一个byte就足以.第一个bit其实没有利用起来,规定都为0,其他低7位才是真正用来表示编码,2^7=128,总共表示128个字符,每个字符对应一个二进制值,这就是它的编码方式,非常简单

  0xxx xxxx
 
  例如:
  0101 0101
  表示U

单字节字符串使用一个字节存放一个字符(SBCS)。比如,”Bob123″ 在内存中为:(16进制)

  42  6F  62  31  32 33  00
 
  B   o   b   1   2   3  \0

此时计算机是表示不来中文的.说白了,老外就没有打算给我们用.随着计算机在全球各个国家越来越流行,很多语言都想在计算机上被显示出来,ascii已经满足不来需求了

3 ANSI码

ansi码被发明了,用来解决ascii码解决不了的问题.一般的设计方法采用2个byte的编码方式来表示编码方式,因为要表示更多字符,所以一个byte 8位根本不够用,全部用了2^8=256个字符,对我们天朝而言,简直就是笑话.2^16=65536,这个才能基本覆盖天朝的日常用字.注意ansi码不是具体的编码方式,是一类相似的编码方式的统称,其中比较有代表性的就是GB2312,BIG5,JIS.都是使用两个字节存储编码
其中0-127(00–7F)采用和ascii相同处理方式,一个byte就够了,超出127(0111 1111)范围的采用2个byte表示(1000 0000 0000 0000),中间加空格是为了方便你阅读,没有别的意思.2^15 = 32768个除ascii码外可以表示的字符数.(1000 0000 0000 0000-1111 1111 1111 1111)但现实是没有全部利用上.
每个字符使用一个字节或多个字节来表示(MBCS),因此,这种方式存放的字符也被称作多字节字符。比如,”中文123″ 在中文 Windows 95 内存中为7个字节,每个汉字占2个字节,每个英文和数字字符占1个字节:

  D6    D0    CE    C4    31    32    33    00
 
  中    文    1    2    3    \0

不过随着国际间交流越来越多,很多时候一份文档中既有中文又有日文.这下子麻烦了,如果编码方式改成gbk2312的话,日文就全部乱码,编码方式改成日文的JIS,那么中文的就全部乱码了,你说蛋疼不蛋疼?

4 UNICODE码

这个时候UNICODE被发明了出来,再也不会出现ansi码的蛋疼事情了.

计算机存放字符串时,改为存放每个字符在 UNICODE 字符集中的序号。目前计算机一般使用 2 个字节(16 位)来存放一个序号(DBCS),因此,这种方式存放的字符也被称作宽字节字符。比如,字符串 “中文123” 在 Windows 2000 下,内存中实际存放的是 5 个序号:

  2D    4E    87    65    31    00    32    00    33    00    00    00
  中           文           1           2           3         \0     
  一共占 10 个字节。

unicode采用16位来存放一个字符,号称能存下地球上的全部字符.有人就说不可能
2^16=65536个字符,怎么可能存下地球上的全部字符?就我大天朝全部的字都够你喝一壶的了.其实是你不了解unicode的编码特性.unicode表示的字符数是有限制的,但是并不是65536,而是000000-10ffff个(2^16)*17 =1114112个,这个我相信已经非常多了,存下我天朝的字还是没有压力的,据说unicode要把甲骨文编码进来,我捻了一把汗,会不会有些人拿他来装B?
谈unicode之前先搞清楚,Unicode和utf-8 ,utf-16等的关系,对理解上面问题有非常好的帮助.Unicode是字符集,也就是说unicode负责收入地球上的各种符号,每个符号给一个唯一的unsigned int类型的数字而已,并不关心我用2个字节还是用4个字节来编码.编码的事情由utf来负责(unicode transformation format).utf-8,utf-7,utf-16就是负责将具体的unsigned int类型的数字用二进制表示在计算机中的.所以为什么unicode采用16位来存放一个字符能存下地球上的全部字符,其实只是说对了一半,0号平面就是16位bit表示的整数来表示BMP(Basic Multilingual Plane,即基本多文种平面,包含我们最经常使用的符号,多国的经常使用的字符和符号,其他不适经常使用的没有放到0号平面中),当然一般使用都是没有问题.但是其他经常不使用的字符放到2-17号平面中,其中的需要的bit数就不止16位了,最多需要20位,具体参考下面的Unicode字符平面映射.如果不懂得话,这里已经写得非常好了,请看wiki请参考Unicode字符平面映射,utf8

5 UTF编码:utf8和utf16

utf8与utf16的不同之处之一就是utf8兼容ascii编码,而utf-16不具备向后兼容的特性.
utf8每个范围采用不同字节数,

十六进制 UTF-8 二进制/十六进制 注释
000000 – 00007F 128个代码 0zzzzzzz(00-7F ASCII字符范围,字节由零开始
000080 – 0007FF 1920个代码 110zzzzz(C0-DF) 10zzzzzz(80-BF) 第一个字节由110开始,接着的字节由10开始
000800 – 00D7FF 00E000 – 00FFFF 61440个代码 1110zzzz(E0-EF) 10zzzzzz 10zzzzzz 第一个字节由1110开始,接着的字节由10开始
010000 – 10FFFF 1048576个代码 11110zzz(F0-F7) 10zzzzzz 10zzzzzz 10zzzzzz 将由11110开始,接着的字节由10开始

这么看你可能不是很明白,

单字节: 1xxxxxxx

2个字节: 110xxxxx 10xxxxxx

3个字节: 1110xxxx 10xxxxxx 10xxxxxx

4个字节: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

发现规律了吧,底层实现通过第一个字节的1的个数来判断后面几个字节是否是属于同一个字符,这种设计的专业术语叫做”自同步”(self synchronization),但是对比utf-16就会发现,utf-8兼容ascii码和节省常用二进制位数做的非常好,但是对于除ascii编码外的字符,要使用2-4个字节,而utf-16一般是2个字节,少数生僻的需要4个字节,所以到底采用utf-8还是utf-16,取决于你的文本内容的到底是英文或常用字多还是生僻字符多,如果是生僻字符多,选择utf-16可能更节省空间一些.一般情况下建议utf-8编码

utf-16通常采用16位或2个16位来表示一个字符,一个16位bit取了个专业术语叫”码元”,这里顺便说一下,ucs-2编码是utf-16的子集,ucs-2采用一个16位bit表示一个字符,,所以最多2^16=65536个字符,也就是0号平面的全部字符,和utf-16一模一样,但是它对1-17号平面的字符表示吃不消.ucs-2基本已经淘汰使用了.因为这个缺陷

问题来了,ucs-2不能表示的1-17号unicode映射平面,utf-16是怎么做到的?

utf-16 从U+D800到U+DFFF之间的码位区块是永久保留不映射到Unicode字符,

0xD800 1101 1000 0000 0000

0xDFFF 1101 1111 1111 1111

这就是秘密,给你举个🌰,

如果要表示U+1F416编码一头猪(🐖)怎么做呢?下面一步一步详细说明一下

字符编码详解

如果还是看不懂,请参考下面给出的wiki连接

5 讨论一下emoji表情为什么用utf8mb4存储,不用utf8在mysql中

在MySQL中,utf8采用的是3个byte来存储字符串,因为绝大多数的字符都可以得到很好的满足,也是就unicode中的0号平面(基本多文种平面,BMP)
但是emoji表情属于1号平面的字符,所以MySQL在存储的时候会报错或者装换成???,要想正常的保存必须使用utf8mb4,采用4个字节存储.
除了这个之外顺便说一下创建mysql连接的时候,需要指定charset=utf8mb4,否则是没有用的哦,表结构或者某个字段的字符编码也需要指定为utf8mb4,
例如:”
name varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

文档信息

版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)

本文出自 “richardtumas”的博客,请务必保留此

发表日期: 2017年7月21日

邮件: joy@richardtumas.com

参考文档:

[1]unicode emoji表情

[2]unicode 平面映射 wiki

[3]utf-16 wiki

[4]utf-8 wiki

[5]utf8 difference between utf8 and utf8mb4

[6]编码推荐阅读

[7]ascii wiki

 

default

Regular expression metacharacters

Metacharacters are the building blocks of regular expressions. Characters in RegEx are understood to be either a metacharacter with a special meaning or a regular character with a literal meaning.

The following are some common RegEx metacharacters and examples of what they would match or not match in RegEx.

Metacharacter Description Examples
\d Whole Number 0 – 9

\d\d\d = 327

\d\d = 81

\d = 4

—————————————–

\d\d\d ≠  24631

\d\d\d doesn’t return 24631 because 24631 contains 5 digits.  \d\d\d only matches for a 3-digit string.

 

\w Alphanumeric Character

\w\w\w = dog

\w\w\w\w = mule

\w\w = to

—————————————–

\w\w\w = 467

\w\w\w\w = 4673

—————————————–

\w\w\w ≠  boat

\w\w\w doesn’t return boat because boat contains 4 characters.

—————————————–

\w ≠  !

\w doesn’t return the exclamation point ! because it is a non-alphanumeric character.

 

\W Symbols

\W = %

\W = #

\W\W\W = @#%

—————————————–

\W\W\W\W ≠  dog8

\W\W\W\W doesn’t return dog8 because d, o, g, and 8 are alphanumeric characters.

 

[a-z]

[0-9]

Character set, at least one of which must be a match, but no more than one unless otherwise specified.

The order of the characters does not matter.

pand[ora] = panda

pand[ora] = pando

—————————————–

pand[ora] ≠  pandora

pand[ora] doesn’t bring back pandora because it is implied in pand[ora] that only 1 character in [ora] can return.

 

(Quantifiers that allow pand[ora] to match for pandora is discussed below.)

 

(abc)

(123)

Character group, matches the characters abc or 123 in that exact order.

pand(ora) = pandora

pand(123) = pand123

—————————————–

pand(oar) ≠  pandora

pand(oar) does not match for pandora because it’s looking for the exact phrase pandoar.

 

| Alternation – allows for alternate matches. | operates like the Boolean OR. pand(abc|123) = pandora OR pand123
? Question mark matches when the character preceding ? occurs 0 or 1 time only, making the character match optional.

colou?r = colour (u is found 1 time)

colou?r = color (u is found 0 times)

 

*

Asterisk matches when the character preceding * matches 0 or more times.

 

Note: * in RegEx is different from * in dtSearch.  RegEx * is asking to find where the character (or grouping) preceding * is found ZERO or more times.  dtSearch * is asking to find where the string of characters preceding * or following * is found 1 or more times.

tre*= tree (e is found 2 times)

tre* = tre (e is found 1 time)

tre* = tr (e is found 0 times)

—————————————–

tre* ≠  trees

tre* doesn’t match the term trees because although “e” is found 2 times, it is followed by “s”, which is not accounted for in the RegEx.

+ Plus sign matches when the character preceding + matches 1 or more times. The + sign makes the character match mandatory.

tre+ = tree (e is found 2 times)

tre+ = tre (e is found 1 time)

—————————————–

tre+ ≠  tr (e is found 0 times)

tre+ doesn’t match for tr because e is found zero times in tr.

 

. (period) The period matches any alphanumeric character or symbol.

ton. = tone

ton. = ton#

ton. = ton4

—————————————–

ton. ≠  tones

ton. doesn’t match for the term tones because . by itself will only match for a single character, here, in the 4th position of the term.  In tones, s is the 5th character and is not accounted for in the RegEx.

.*

 

 

Combine the metacharacters . and *, in that order .* to match for any character 0 or more times.

 

NOTE:  .* in RegEx is equivalent to dtSearch wildcard * operator.

 

 

tr.* = tr

tr.* = tre

tr.* = tree

tr.* = trees

tr.* = trough

tr.* = treadmill

 

RegEx quantifiers

RegEx use quantifiers to indicate the scope of a search string. You can use multiple quantifiers in your search string. The following table gives examples of the quantifiers you can use in your RegEx:

Quantifier Description Examples
{n} Matches when the preceding character, or character group, occurs n times exactly.

\d{3} = 836

\d{3} = 139

\d{3} = 532

—————————————–

pand[ora]{2} = pandar

pand[ora]{2} = pandoo

pand(ora){2} = pandoraora

—————————————–

pand[ora]{2} ≠  pandora

pand[ora]{2} doesn’t match for pandora because the quantifier {2} only allows for 2 letters from the character set [ora].

 

{n,m} Matches when the preceding character, or character group, occurs at least n times, and at most m times.

\d{2,5} = 97430

\d{2,5} = 9743

\d{2,5} = 97

—————————————–

\d{2,5} ≠  9

9 does not match because it is 1 digit, thus outside of the character range.

 

Escaping RegEx Metacharacters

When using RegEx to search for a character that is a reserved metacharacter, use the backslash \ to escape the character so it can be recognized. The following table gives an example on how to escape a reserved metacharacter when searching.

Search For RegEx Match Results

UK phone number

 

\+[0-9]{11}

+14528280001

+38119930978

—————————————–

If the + sign is not escaped with a backslash, RegEx treats + as a quantifier instead of the literal plus sign character.

 

programming \ php

realpath()

mkdir mian
cd main
touch main.php

add below code to main.php

<!--?php include("./sub/sub.php");//whether or not require or include a file change can't change execute path echo "\n" echo realpath("./"); ?-->
mkdir sub;
touch sub.php

add below code to sub.php

<!--?php //chdir("/usr/local/bin");//chdir can change execute path echo realpath("./"); ?-->


conclusion :
execute path can’t changed whether or not is executed in require and include or main php file

programming \ java \ programming

java中的import和package

由于java这门语言没有走正常的路,其他语言采用namespace这个关键字,但是java另辟蹊径,采用package 机制,一个jar包,就是一个相关功能模块的大类,命名方式就是模仿因特网的域名机制,每一个类在本域名下是独一无二的。如果要使用某一个类的就要使用import+域名+类名+方法名,这种语法,支持通配符*。未完待补充

package demo.first;

/**
 * Created by joy on 4/10/2017.
 */
public class Test2 {

    public static void main(String[] args){
        System.out.print("helloworld");
    }

}

 

default

a basic git tutorial

DVCS (such as Git, Mercurial, Bazaar or Darcs)

Git was written by Linus Torvalds on the first version,He described the tool as “the stupid content tracker”,So don’t be afraid of Git.

It is a good idea to introduce yourself to Git with your name and
public email address before doing any operation. The easiest
way to do so is:

$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com

Initialized empty Git repository in .git/

git init

 

git add .

Git tracks content not files
—————————-

Many revision control systems provide an `add` command that tells the
system to start tracking changes to a new file. Git’s `add` command
does something simpler and more powerful: ‘git add’ is used both for new
and newly modified files, and in both cases it takes a snapshot of the
given files and stages that content in the index, ready for inclusion in
the next commit.

This snapshot is now stored in a temporary staging area which Git calls
the “index”. You can permanently store the contents of the index in the
repository with ‘git commit’:

 

git commit

A note on commit messages: Though not required, it’s a good idea to
begin the commit message with a single short (less than 50 character)
line summarizing the change, followed by a blank line and then a more
thorough description. The text up to the first blank line in a commit
message is treated as the commit title, and that title is used
throughout Git. For example, linkgit:git-format-patch[1] turns a
commit into email, and it uses the title on the Subject line and the
rest of the commit in the body.

 git commit -a

which will automatically notice any modified (but not new) files, add
them to the index, and commit, all in one step.

git add file1 file2 file3

You are now ready to commit. You can see what is about to be committed
using ‘git diff’ with the –cached option:

git diff --cached

 

$ git status

 

git log

If you also want to see complete diffs at each step, use

git log -p

 

git branch

 

git checkout 'your_branch'

 

git merge 'some one branch'

If the changes don’t conflict, you’re done. If there are conflicts,
markers will be left in the problematic files showing the conflict;

git diff

will show a nice graphical representation of the resulting history.

gitk

At this point you could delete the experimental branch with

git branch -d 'your_branch'

 

git clone /home/alice/project myrepo

The “pull” command thus performs two operations: it fetches changes
from a remote branch, then merges them into the current branch

local changes committed before
initiating this “pull”.

git pull /home/bob/myrepo master
git fetch /home/bob/myrepo master
git log -p HEAD..FETCH_HEAD
gitk HEAD..FETCH_HEAD
git difftool
git difftool --tool-help
git rm
git rm --cached
git commit --amend

 

git checkout -- <file>
git remote add pb https://github.com/paulboone/ticgit
 git push [remote-name] [branch-name]
git remote show [remote-name]
git remote rename
git remote rm paul
git tag
git checkout -b version2 v2.0.0

permanently delete remote ref

git push --delete rep ref
git push rep :ref
eg..git push --delete origin dev  is equivalent to git push origin :dev

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

software

vim shortcut

 

Operation Modes:

While working with vi editor you would come across following two modes:

  1. Command mode: This mode enables you to perform administrative tasks such as saving files, executing commands, moving the cursor, cutting (yanking) and pasting lines or words, and finding and replacing. In this mode, whatever you type is interpreted as a command.
  2. Insert mode: This mode enables you to insert text into the file. Everything that’s typed in this mode is interpreted as input and finally it is put in the file .

The vi always starts in command mode. To enter text, you must be in insert mode. To come in insert mode you simply type i. To get out of insert mode, press the Esc key, which will put you back into command mode.

Hint: If you are not sure which mode you are in, press the Esc key twice, and then you’ll be in command mode. You open a file using vi editor and start type some characters and then come in command mode to understand the difference.

Getting Out of vi:

The command to quit out of vi is :q. Once in command mode, type colon, and ‘q’, followed by return. If your file has been modified in any way, the editor will warn you of this, and not let you quit. To ignore this message, the command to quit out of vi without saving is :q!. This lets you exit vi without saving any of the changes.

The command to save the contents of the editor is :w. You can combine the above command with the quit command, or :wq and return.

The easiest way to save your changes and exit out of vi is the ZZ command. When you are in command mode, type ZZ and it will do the equivalent of :wq.

You can specify a different file name to save to by specifying the name after the :w. For example, if you wanted to save the file you were working as another filename called filename2, you would type :w filename2 and return. Try it once.

Moving within a File:

To move around within a file without affecting your text, you must be in command mode (press Esc twice). Here are some of the commands you can use to move around one character at a time:

Command Description
k Moves the cursor up one line.
j Moves the cursor down one line.
h Moves the cursor to the left one character position.
l Moves the cursor to the right one character position.

There are following two important points to be noted:

  • The vi is case-sensitive, so you need to pay special attention to capitalization when using commands.
  • Most commands in vi can be prefaced by the number of times you want the action to occur. For example, 2j moves cursor two lines down the cursor location.

There are many other ways to move within a file in vi. Remember that you must be in command mode (press Esc twice). Here are some more commands you can use to move around the file:

Command Description
0 or | Positions cursor at beginning of line.
$ Positions cursor at end of line.
w Positions cursor to the next word.
b Positions cursor to previous word.
( Positions cursor to beginning of current sentence.
) Positions cursor to beginning of next sentence.
E Move to the end of Blank delimited word
{ Move a paragraph back
} Move a paragraph forward
[[ Move a section back
]] Move a section forward
n| Moves to the column n in the current line
1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file
fc Move forward to c
Fc Move back to c
H Move to top of screen
nH Moves to nth line from the top of the screen
M Move to middle of screen
L Move to botton of screen
nL Moves to nth line from the bottom of the screen
😡 Colon followed by a number would position the cursor on line number represented by x

Control Commands:

There are following useful command which you can use along with Control Key:

Command Description
CTRL+d Move forward 1/2 screen
CTRL+d Move forward 1/2 screen
CTRL+f Move forward one full screen
CTRL+u Move backward 1/2 screen
CTRL+b Move backward one full screen
CTRL+e Moves screen up one line
CTRL+y Moves screen down one line
CTRL+u Moves screen up 1/2 page
CTRL+d Moves screen down 1/2 page
CTRL+b Moves screen up one page
CTRL+f Moves screen down one page
CTRL+I Redraws screen

Editing Files:

To edit the file, you need to be in the insert mode. There are many ways to enter insert mode from the command mode:

Command Description
i Inserts text before current cursor location.
I Inserts text at beginning of current line.
a Inserts text after current cursor location.
A Inserts text at end of current line.
o Creates a new line for text entry below cursor location.
O Creates a new line for text entry above cursor location.

Deleting Characters:

Here is the list of important commands which can be used to delete characters and lines in an opened file:

Command Description
x Deletes the character under the cursor location.
X Deletes the character before the cursor location.
dw Deletes from the current cursor location to the next word.
d^ Deletes from current cursor position to the beginning of the line.
d$ Deletes from current cursor position to the end of the line.
D Deletes from the cursor position to the end of the current line.
dd Deletes the line the cursor is on.

As mentioned above, most commands in vi can be prefaced by the number of times you want the action to occur. For example, 2x deletes two character under the cursor location and 2dd deletes two lines the cursor is on.

I would highly recommend to exercise all the above commands properly before proceeding further.

Change Commands:

You also have the capability to change characters, words, or lines in vi without deleting them. Here are the relevant commands:

Command Description
cc Removes contents of the line, leaving you in insert mode.
cw Changes the word the cursor is on from the cursor to the lowercase w end of the word.
r Replaces the character under the cursor. vi returns to command mode after the replacement is entered.
R Overwrites multiple characters beginning with the character currently under the cursor. You must use Esc to stop the overwriting.
s Replaces the current character with the character you type. Afterward, you are left in insert mode.
S Deletes the line the cursor is on and replaces with new text. After the new text is entered, vi remains in insert mode.

Copy and Past Commands:

You can copy lines or words from one place and then you can past them at another place using following commands:

Command Description
yy Copies the current line.
yw Copies the current word from the character the lowercase w cursor is on until the end of the word.
p Puts the copied text after the cursor.
P Puts the yanked text before the cursor.

Advanced Commands:

There are some advanced commands that simplify day-to-day editing and allow for more efficient use of vi:

Command Description
J Join the current line with the next one. A count joins that many lines.
<< Shifts the current line to the left by one shift width.
>> Shifts the current line to the right by one shift width.
~ Switch the case of the character under the cursor.
^G Press CNTRL and G keys at the same time to show the current filename and the status.
U Restore the current line to the state it was in before the cursor entered the line.
u Undo the last change to the file. Typing ‘u’ again will re-do the change.
J Join the current line with the next one. A count joins that many lines.
:f Displays current position in the file in % and file name, total number of file.
:f filename Renames current file to filename.
:w filename Write to file filename.
:e filename Opens another file with filename.
:cd dirname Changes current working directory to dirname.
:e # Use to toggle between two opened files.
:n In case you open multiple files using vi, use :n to go to next file in the series.
:p In case you open multiple files using vi, use :p to go to previous file in the series.
:N In case you open multiple files using vi, use :N to go to previous file in the series.
:r file Reads file and inserts it after current line
:nr file Reads file and inserts it after line n.

Word and Character Searching:

The vi editor has two kinds of searches: string and character. For a string search, the / and ? commands are used. When you start these commands, the command just typed will be shown on the bottom line, where you type the particular string to look for.

These two commands differ only in the direction where the search takes place:

  • The / command searches forwards (downwards) in the file.
  • The ? command searches backwards (upwards) in the file.

The n and N commands repeat the previous search command in the same or opposite direction, respectively. Some characters have special meanings while using in search command and preceded by a backslash (\) to be included as part of the search expression.

Character Description
^ Search at the beginning of the line. (Use at the beginning of a search expression.)
. Matches a single character.
* Matches zero or more of the previous character.
$ End of the line (Use at the end of the search expression.)
[ Starts a set of matching, or non-matching expressions.
< Put in an expression escaped with the backslash to find the ending or beginning of a word.
> See the ‘<‘ character description above.

The character search searches within one line to find a character entered after the command. The f and F commands search for a character on the current line only. f searches forwards and F searches backwards and the cursor moves to the position of the found character.

The t and T commands search for a character on the current line only, but for t, the cursor moves to the position before the character, and T searches the line backwards to the position after the character.

Set Commands:

You can change the look and feel of your vi screen using the following :set commands. To use these commands you have to come in command mode then type :set followed by any of the following options:

Command Description
:set ic Ignores case when searching
:set ai Sets autoindent
:set noai To unset autoindent.
:set nu Displays lines with line numbers on the left side.
:set sw Sets the width of a software tabstop. For example you would set a shift width of 4 with this command: :set sw=4
:set ws If wrapscan is set, if the word is not found at the bottom of the file, it will try to search for it at the beginning.
:set wm If this option has a value greater than zero, the editor will automatically “word wrap”. For example, to set the wrap margin to two characters, you would type this: :set wm=2
:set ro Changes file type to “read only”
:set term Prints terminal type
:set bf Discards control characters from input

Running Commands:

The vi has the capability to run commands from within the editor. To run a command, you only need to go into command mode and type :! command.

For example, if you want to check whether a file exists before you try to save your file to that filename, you can type :! ls and you will see the output of ls on the screen.

When you press any key (or the command’s escape sequence), you are returned to your vi session.

Replacing Text:

The substitution command (:s/) enables you to quickly replace words or groups of words within your files. Here is the simple syntax:

:s/search/replace/g

The g stands for globally. The result of this command is that all occurrences on the cursor’s line are changed.

IMPORTANT:

Here are the key points to your success with vi:

  • You must be in command mode to use commands. (Press Esc twice at any time to ensure that you are in command mode.)
  • You must be careful to use the proper case (capitalization) for all commands.
  • You must be in insert mode to enter text.

NOTE:

ctrl+v 进入列编辑模式,向下或向上移动光标,把需要注释的行的开头标记起来,然后按大写的I(shift+i),再插入注释符,比如”//”,再按Esc,就会全部注释了

批量去掉注释

ctrl+v,进入列编辑模式,横向选中列的个数(如”//”注释符号,需要选中两列),然后按d, 就会删除注释符号

 

1、用vim打开一个文件,例如:a.cpp

2、在普通模式下,输入:”:sp”(不含引号)横向切分一个窗口,或者”:vsp”纵向切分一个窗口,敲入命令后,你将看到两个窗口打开的是同一个文件

3、在普通模式下,输入:”:e b.cpp”,在其中一个窗口里打开另一个文件

4、切换到含有源文件(a.cpp)的窗口,在普通模式下,把光标移到你需要复制内容的起始行,然后输入你想复制的行的数量(从光标所在行往下计算),在行数后面接着输入yy,这样就将内容复制到临时寄存器里 了(在 普通模式下ctrl+w,再按一下w,可以在两个窗口之间切换)

5、切换到目标文件( b.cpp )窗口,把光标移到你接收复制内容的起始行,按一下p,就完成复制了。

default

xdebug config

zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so;
xdebug.auto_trace=1;
xdebug.collect_assignments=1;
xdebug.collect_params=1;
xdebug.collect_return=1;
xdebug.remote_enable=1;
xdebug.remote_host=192.168.3.103;
xdebug.remote_port=9000;
xdebug.idekey=phpstorm;
xdebug.collect_vars=1;
;xdebug.profiler_aggregate=1;
;xdebug.profiler_append=1;
;xdebug.profiler_enable=1;
;xdebug.profiler_enable_trigger=1;
;xdebug.show_error_trace=1;
;xdebug.show_exception_trace=1;
xdebug.show_local_vars=1;
xdebug.remote_autostart=1;
;xdebug.trace_enable_trigger=1;

programming \ php

Some important options maybe useful when compile php from source code

As we know install php 7 in ubuntu can’t use apt-get install php directly,Because official source haven’t updated until now(2016/8/21),but we can compile it from source code ,here I provide some useful options that maybe helpful for your to use php 7,

./configure  '--prefix=/usr/' '--with-config-file-path=/etc/php' '--enable-fpm' '--with-fpm-user=joy' '--with-fpm-group=joy' '--enable-mysqlnd' '--with-mysqli' '--with-pdo-mysql' '--with-iconv-dir' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--enable-intl' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-opcache' '--with-xsl'

Please remember instead DIR with the directory where software are install ed ,If you don’t know where is the path that software installed.you can use which command,Just like below

joy@ubuntu:~/php-7.0.4$ which mysql
/usr/bin/mysql
joy@ubuntu:~/php-7.0.4$ which curl
/usr/bin/curl
joy@ubuntu:~/php-7.0.4$ which openssl
/usr/bin/openssl

If you still can’t compile php 7 because specified error path for configure.then you can leave DIR alone,Just like this

./configure  --with-openssl --with-curl --with-pdo-mysql --with-mysqli= --enable-mbstring

./configure will find default path for you

good luck to you!

 

 

programming \ php

try catch php Exception

Today i met a interesting thing that parent exception can catch sub exception,for example

<?php

class testException extends Exception{
}
class myException extends testException{
}
try{
  try{ 
      try{
         throw new myException();
      }catch(myException $e){
           echo "hello world";
           throw $e;
      }
    }catch(testException $e){
        echo "hello world";
        throw $e;
    }
 }catch(Exception $e){
     echo "hello world";
}
?>

//final result “hello worldhello worldhello world”

you can see subclass exception will be catched by parent class,but subclass exception do not catch parent class exception,blow is example

<?php
class testException extends Exception{

}
class myException extends testException{
 
}
try{
    try{
       throw new Exception();
    }catch(myException $e){
        echo "hello world";
        throw $e;
     }
}catch(testException $e){
    echo "hello world";
}

?>

//result “PHP Fatal error:  Uncaught Exception”

I hope this  may helpful to you.

software

clion keymap

shortcut Description

Ctrl+Space

The CodeCompletion feature allows you to quickly complete different kinds of statements in the code.

For example, you can start typing a class member name and press Ctrl+Space to complete it. When multiple choices are available, they are shown in the lookup list.

 

Ctrl+Shift+I

 

Use Ctrl+Shift+I (View | Quick Definition), to quickly review definition or content of the symbol at the caret, without opening it in the editor

   
   
   
   
   
programming

ASCII Table

ASCII Table and Description

ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as ‘a’ or ‘@’ or an action of some sort. ASCII was developed a long time ago and now the non-printing characters are rarely used for their original purpose. Below is the ASCII character table and this includes descriptions of the first 32 non-printing characters. ASCII was actually designed for use with teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in ASCII format, all this means is they want ‘plain’ text with no formatting such as tabs, bold or underscoring – the raw format that any computer can understand. This is usually so they can easily import the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as ‘text only’

 

Ascii Table

 

Extended ASCII Codes

EBCDIC and IBM Scan Codes