无来

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

0%

1
2
3
4
5
root@docker:~/drupal# docker inspect drupal_mysql | grep MYSQL_ROOT_PASSWORD
"MYSQL_ROOT_PASSWORD=test",
root@docker:~/drupal# docker exec -it drupal_mysql mysql -u root -p
Enter password: test
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I’ve gratuitously rebuilt, recreated, --no-cache'd, --force-recreate'd.. nothing is working. I’ve also tried putting the environment variable directly in a mysql Dockerfile and as an “environment” argument in my docker-compose.yml.

The only thing that IS working is passing -e ‘MYSQL_ROOT_PASSWORD=test’ in a docker run statement.

我使用crontab同步一个文件夹时,发现一个问题,我在crontab中设置的1分钟运行一次.但当那个文件夹的内容改变时。1分钟不一定能同步完,但这时第二个rsync进行又起来了。

这个就产生一个问题,二个rsync一起处理相同的文件,这样会出问题。如下

* * * * /usr/bin/rsync -avlR /data/files    172.16.xxx.xxx:/data

本来想写个脚本来解决,但太麻烦。所以用了个linux下的锁。。呵呵,象下面这个.

1 * * * * flock -xn /var/run/rsync.lock -c "rsync -avlR /data/files    172.16.xxx.xxx:/data"

这样,使用flock的-x参数先建一个锁文件,然后-n指定,如果锁存在,就等待。直到建成功锁在会运行-c后面的命令。这样第一个进程没有运行完前,锁文件都会存在。这样就不会二个rsync同时并发处理一个东西了

来源: http://www.cnblogs.com/cmsd/p/3697049.html

需求: 同步某个目录下所有的图片(.jpg),该目录下有很多其他的文件,但只想同步.jpg的文件。

rsync 有一个–exclude 可以排除指定文件,还有个–include选项的作用正好和–exclude相反。
那直接使用–include=”*.jpg”是否可以呢?

rsync -av –include=”*.jpg” /src/ /des/

实验证明,这样是不对的。

而正确的答案是
rsync -av –include=”.jpg” –exclude= /src/ /des/

MySQL导出的SQL语句在导入时有可能会非常非常慢,经历过导入仅45万条记录,竟用了近3个小时。在导出时合理使用几个参数,可以大大加快导 入的速度。

  • -e 使用包括几个VALUES列表的多行INSERT语法;
  • -max_allowed_packet=XXX 客户端/服务器之间通信的缓存区的最大大小;
  • --net_buffer_length=XXX TCP/IP和套接字通信缓冲区大小,创建长度达net_buffer_length的行。

注意:max_allowed_packet和net_buffer_length不能比目标数据库的设定数值 大,否则可能出错。

首先确定目标库的参数值

1
2
mysql>show variables like 'max_allowed_packet';
mysql>show variables like 'net_buffer_length';

根据参数值书写mysqldump命令,如:

E:\eis>mysqldump -uroot -p eis_db goodclassification -e --max_allowed_packet=1048576 --net_buffer_length=16384 >good3.sql

之前2小时才能导入的sql现在几十秒就可以完成了。

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