无来

不管你来还是不来
我都在这里,夜夜点亮
不是为了守候
只是为了做好我自己

0%

I’m not sure exactly what you’re asking as the title talks about merging single files but the text of the question talks about single revisions. In the case of merging single revisions you need: (to merge the changes committed in revisions 100, 105, 115)

1
2
cd trunk
svn merge -c 100 -c 105 -c 115 http://..../branches/mybranch .

If you want to merge only the part of revision 100 that affects file.cpp:

1
2
cd trunk/path/to/file.cpp
svn merge -c 100 http://../branches/mybranch/path/to/file.cpp file.cpp

php CMYK to RGB

来源:http://php.net/manual/en/imagick.setimagecolorspace.php

Simlest way converting from CMYK to RGB:

1
2
3
4
5
<?php
if ($jpeg->getImageColorspace() == \Imagick::COLORSPACE_CMYK) {
$jpeg->transformimagecolorspace(\Imagick::COLORSPACE_SRGB);
}
?>

It is pretty work in current stable Image Magick (6.9.0-4).

方案一,输出到系统错误

One possibility is to set your own error handler before the call and restore the previous error handler later with restore_error_handler().

1
2
3
set_error_handler(function() { /* ignore errors */ });
dns_get_record();
restore_error_handler();

You could build on this idea and write a re-usable error handler that logs the errors for you.

1
2
3
4
set_error_handler([$logger, 'onSilencedError']);
dns_get_record();
restore_error_handler();
Turning errors into exceptions

You can use set_error_handler() and the ErrorException class to turn all php errors into exceptions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}

throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});

try {
dns_get_record();
} catch (ErrorException $e) {
// ...
}

The important thing to note when using your own error handler is that it will bypass the error_reporting setting and pass all errors (notices, warnings, etc.) to your error handler. You can set a second argument on set_error_handler() to define which error types you want to receive, or access the current setting using … = error_reporting() inside the error handler.

Suppressing the warning

Another possibility is to suppress the call with the @ operator and check the return value of dns_get_record() afterwards. But I’d advise against this as errors/warnings are triggered to be handled, not to be suppressed.

方案二: 输出到自定义函数

1
2
3
4
5
6
7
8
9
set_error_handler(function ($errno, $errstr) {
// do something
echo "\r\n~~~~~找到错误 :-D~~~~~\r\n";
echo "错误信息:($errno)$errstr \r\n";
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
echo "\r\n";
}, E_WARNING);
$dir_handle = opendir("$dir/111"); //要catch的函数
restore_error_handler();

欢迎转载,但请务必在明确位置注明文章出处! >http://johnnyshieh.github.io/python/2015/08/02/python-remove-utf8-bom/

前几天我在Windows写完一篇markdown格式的文章,上传到github page后,这个文章的页面把jekyll的YAML头信息也显示出来了,没有像我之前在ubuntu中写的文章一样正常解析YAML头信息,最后谷歌了半天发现原因是在Windows用记事本保存utf-8编码的文件时会默认加上BOM头字符。而jekyll的文档中也明确写明了如果使用UTF-8编码,那么在文件中一定不要出现BOM头字符。

所以我把如何在Windows和linux系统中去除UTF-8的BOM头的方法做个记录。

  1. UTF-8 与 UTF-8 + BOM 的区别

下面是我从网上复制过来BOM的简介:

BOM – Byte Order Mark,中文名译作“字节顺序标记”。在UCS 编码中有一个叫做 “Zero Width No-Break Space” ,中文译名作“零宽无间断间隔”的字符,它的编码是 FEFF。而 FFFE 在 UCS 中是不存在的字符,所以不应该出现在实际传输中。UCS 规范建议我们在传输字节流前,先传输字符 “Zero Width No-Break Space”。这样如果接收者收到 FEFF,就表明这个字节流是 Big-Endian 的;如果收到FFFE,就表明这个字节流是 Little- Endian 的。因此字符 “Zero Width No-Break Space” (“零宽无间断间隔”)又被称作 BOM。

UTF-8 不需要 BOM 来表明字节顺序,但可以用 BOM 来表明编码方式。字符 “Zero Width No-Break Space” 的 UTF-8 编码是 EF BB BF。所以如果接收者收到以 EF BB BF (十六进制)开头的字节流,就知道这是 UTF-8编码了。Windows 就是使用 BOM 来标记文本文件的编码方式的。

所以UTF-8 + BOM其实就是在文件的开头加上了 0xEF 0xBB 0xBF 这三个字节,而这个三个字节是一串隐藏字符。

  1. 在Linux中如何检测去除BOM头

在Linux中可以用vim很方便地检测、去除BOM头

检测是否有BOM头:

:set bomb?

去除BOM头:

:set encoding=utf-8
:set nobomb

添加BOM头也很简单:

:set encoding=utf-8
:set bomb
  1. 利用python脚本在window、linux、mac os中去除BOM头

我在Terence的BomSweeper的基础上,用python3完成了一个去除单个文件BOM或者批量去除一个文件夹内多个文件BOM的脚本。原理就是删除文件开头的BOM 3个字节。

大家可以到Github中查看下载源码,项目地址– Utf8BomRemover

在readme中我有写明脚本的使用方法,如果大家对这个脚本有什么建议欢迎留言。

将扩展名为.json的文件名添加前缀ad_

for i in `ls *.json`;do mv -f $i `echo "ad_"$i`;done

通过命令列出文件夹并输出到指定文件

ll |grep json | awk '{print "## "NR"." ,$9}' > README.md

说明:

  • ll 列出夹所有文件
  • grep json 仅显示包含 json 的文件名
  • awk ‘{print “## “NR”.” ,$9}’
    • awk 格式化grep的结果
    • 打印输出
    • ## 每一天前面添加字符串##
    • NR”.” 格式化输出行号。如 1.,2.
    • , 连接字符串
    • $9 结果的第9列数据
    • > README.md 结果输出到README.md 文件

实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
localhost:IFE8.0 json.json liuligang$ ll
total 944
-rw-r--r--@ 1 liuligang staff 510 12 12 10:39 README.md
-rw-r--r--@ 1 liuligang staff 21499 11 28 10:40 airshop.json
-rw-r--r--@ 1 liuligang staff 36993 11 28 12:17 en_culture.json
-rw-r--r--@ 1 liuligang staff 17351 11 28 12:18 en_gourmet.json
-rw-r--r--@ 1 liuligang staff 6548 11 28 12:18 en_magazines.json
-rw-r--r--@ 1 liuligang staff 25975 11 28 12:17 en_movies.json
-rw-r--r--@ 1 liuligang staff 21805 11 28 12:16 en_recommend.json
-rw-r--r--@ 1 liuligang staff 29110 11 28 12:18 en_travel.json
-rw-r--r--@ 1 liuligang staff 1082 11 28 11:43 english_menu.json
-rw-r--r--@ 1 liuligang staff 28534 11 28 11:48 ent_cars.json
-rw-r--r--@ 1 liuligang staff 29919 11 28 11:46 ent_film.json
-rw-r--r--@ 1 liuligang staff 27993 11 28 11:47 ent_finance.json
-rw-r--r--@ 1 liuligang staff 26844 11 28 11:49 ent_travel.json
-rw-r--r--@ 1 liuligang staff 5409 11 28 11:49 ent_video.json
-rw-r--r--@ 1 liuligang staff 1331 11 28 11:48 entertainment_menu.json
-rw-r--r-- 1 liuligang staff 350 12 12 10:21 file.list
-rw-r--r--@ 1 liuligang staff 7247 11 28 10:39 game.json
-rw-r--r--@ 1 liuligang staff 36349 11 28 11:49 gossip.json
-rw-r--r--@ 1 liuligang staff 8555 11 28 10:37 home.json
-rw-r--r--@ 1 liuligang staff 31678 11 28 11:50 lifestyle.json
-rw-r--r--@ 1 liuligang staff 1673 11 28 10:48 mainMenu.json
-rw-r--r--@ 1 liuligang staff 43716 11 28 11:50 recommend.json
-rw-r--r--@ 1 liuligang staff 8423 11 28 10:41 topic2.json
-rw-r--r--@ 1 liuligang staff 7047 11 28 10:40 topic4.json

输出README.md文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## 1. airshop.json
## 2. en_culture.json
## 3. en_gourmet.json
## 4. en_magazines.json
## 5. en_movies.json
## 6. en_recommend.json
## 7. en_travel.json
## 8. english_menu.json
## 9. ent_cars.json
## 10. ent_film.json
## 11. ent_finance.json
## 12. ent_travel.json
## 13. ent_video.json
## 14. entertainment_menu.json
## 15. game.json
## 16. gossip.json
## 17. home.json
## 18. lifestyle.json
## 19. mainMenu.json
## 20. recommend.json
## 21. topic2.json
## 22. topic4.json

1
2
3
4
git checkout . #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

git丢弃本地修改的所有文件(新增、删除、修改)

1
2
3
4
5
git clean -df #返回到某个节点
git clean 参数
-n 显示 将要 删除的 文件 和 目录
-f 删除 文件
-df 删除 文件 和 目录

也可以使用

1
git checkout . && git clean -xdf

如果在命终端中用svn命令操作文件名中有“@”符号的文件(ios开发的朋友应该很清楚),会遇到:

svn: E205000: Syntax error parsing peg revision ‘3x.png’

或者:

svn: E200009: ‘welcome1@3x.png': a peg revision is not allowed here

类似的错误提示,原因是因为svn命令把文件名中的@识别成有其它含义的特殊字符,导致操作失败。

解决办法:

在使用svn命令时在文件名尾部再添加一个@即可解决。
比如 要查看welcome1@3x.png文件信息:

svn info welcome1@3x.png@

站点远程同步脚本,实现数据库本地镜像。

如果源文件删除,目标文件夹也会删除。因此该脚本只能够作为镜像,不能作为备份

rsync.sh 执行脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh

path=$1

host=rsync@103.235.220.108
port=2222

dbuser=root
dbpwd=111111


#远程服务器运行dbdump.sh脚本dump数据库
echo "dump msyql"
ssh $host -p $port "~/dbdump.sh"

src=$host:/home/wwwroot/html
dst=/home/wwwroot/html
exculude=/home/wwwroot/rsync_exclude.list

echo "源:"$src/$path
echo "目标:"$dst/$path
rsync -avzO -e "ssh -p $port" --exclude-from=$exculude --delete $src/$path $dst/$path

echo ">>>更新数据库"
CurrentDate=$(date +%Y%m%d)
mysql -u$dbuser -p$dbpwd test < $dst/db/test.${CurrentDate}.sql

echo "同步完成"

rsync_exclude.list

忽略的文件,文件夹路径

1
2
3
.svn/
Upload/
logs/

dbdump.sh

1
2
3
4
5
6
#!/bin/sh
dbname=root
dbpwd=111111
CurrentDate=$(date +%Y%m%d)
dirPath=/home/wwwroot/html/db
mysqldump -u$dbname -pdbpwd test > $dirPath/test.${CurrentDate}.sql

demo

同步test文件夹

./rsync.sh test

显示进度条

添加参数--progress

rsync -av --progress  root@123.123.123.123:/root/mysql56.tar .