WordPress 4.7.5改善Twenty Fifteen主题在Internet Explorer 11上的兼容显示问题

WordPress 4.7.5使用Twenty Fifteen主题的时候,在Internet Explorer 11上存在兼容问题,页面的左边的侧边栏经常会不绘制,出现空白,这个问题是由于Internet Explorer 11使用的Trident引擎导致的,我们可以通过强制Internet Explorer 11使用Internet Explorer 9引擎来改善问题,注意: 是改善,暂时还没办法彻底解决

继续阅读WordPress 4.7.5改善Twenty Fifteen主题在Internet Explorer 11上的兼容显示问题

阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS

ubuntu 16.04.2 LTS版本提供了PHP 7.0,这个版本的PHP拥有更好的性能,更低的资源开销,考虑了很久,终于决定还是把目前的ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS

继续阅读阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS

python直接下载图片到内存

1. 使用requests(推荐)

from PIL import Image
from StringIO import StringIO
import requests
Image.open(StringIO(requests.get(url, stream=True).raw.read()))

2. 使用StringIO

from PIL import Image
from StringIO import StringIO
import requests

r = requests.get("http://a/b/c")
im = Image.open(StringIO(r.content))
im.size

# =======================

from PIL import Image
import urllib2 as urllib
from StringIO import StringIO

fd = urllib.urlopen("http://a/b/c")
im = Image.open(StringIO(fd.read()))
im.size

3. 使用io.BytesIO

from PIL import Image
import urllib2 as urllib
import io

fd = urllib.urlopen("http://a/b/c")
image_file = io.BytesIO(fd.read())
im = Image.open(image_file)

参考链接


python直接下载图片到内存

Ubuntu 14.04下MySQL监控工具—mytop

安装


mytop的项目页面为:http://jeremy.zawodny.com/mysql/mytop/

Ubuntu 14.04上的安装非常简单,命令如下:

$ sudo apt-get install mytop

安装完成后,执行如下命令启动(本机数据库的情况):

$ sudo mytop -uroot -ppassword

启动后的界面如下图:

继续阅读Ubuntu 14.04下MySQL监控工具—mytop

获取当前Python中site-packages的具体存放路径

很多时候,我们系统上安装了好几个版本的Python, 此时,我们往往没办法确定通过pip安装的包会存放到那个目录下的site-packages中,可以通过如下代码获取:

$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Ubuntu 16.04 LTS系统上,这个输出是存在问题的,执行命令后输出的目录是:

/usr/lib/python2.7/dist-packages

实际上,通过pip命令安装的目录有很大一部分被安装到了

/usr/local/lib/python2.7/dist-packages

目录下。

使用Git Submodule管理子模块

我们经常会引用第三方的开源项目或者其他人的项目到自己的项目中来,如果直接拷贝代码,那么就需要每次他人修改后,手工同步代码,导致整个的工作量非常大。git submodule使得我们可以把他人的项目作为我们自己的子项目来进行管理,当对方修改后,一个简单的同步命令就可以完成代码的自动同步,方便我们的开发。添加一个项目到我们的工程中,比如:

$ git submodule add git@github.com:jjz/pod-library.git pod-library

检出主工程代码后,初始化子模块(需要手工执行)

$ git submodule update --init --recursive

更新同步子模块的代码:

$ git submodule update --recursive --remote

删除子模块的代码:

$ git submodule deinit pod-library
 
$ git rm -f pod-library

$ rm -rf .git/modules/pod-library

参考链接


ubuntu 14.04 LTS关闭873端口

最近在使用百度统计的网站安全功能的时候,被报告存在873端口被打开的情况,刚开始以为是被入侵了,后来发现是在测试功能的时候无意安装了rsync导致的rsyncd873端口进行监听。

解决方法就是卸载rsync即可:

$ sudo apt-get purge --auto-remove rsync

#需要重启机器,否则端口可能出现长时间仍然开放的状态
$ sudo reboot

Ubuntu 14.04服务器利用Apache 2.4的.htaccess文件阻止对wp-config.php.bak的访问

最近在分析请求链接的时候发现有对wp-config.php.bak的下载请求,被吓了一跳。在WordPress的某些升级操作中,会特意备份wp-config.php方便出现问题后的回退。如果有人恶意下载这个文件,会导致数据库密码以及配置信息的泄漏,后果影响很大。

对于使用Apache 2.4的服务器来说,比较简单,只要在.htaccess中,使用如下配置即可:

#reject all .bak,.old file download because wordpress upgrade may rename 
#wp-config.php to wp-config.php.bak 
<FilesMatch (.*)\.(bak|old)>
        Order allow,deny
        deny from all
</FilesMatch>

JavaScript修改伪元素样式(pseudo element styles)

类似如下的CSS声明:

#progress {
    background: #333;
    border-radius: 13px;
    height: 10px;
    width: 300px;
    padding: 3px;
}

#progress:after {
    content: '';
    display: block;
    background: orange;
    width: 0%;
    height: 100%;
    border-radius: 9px;
}

HTML中的声明如下:

<div id="progress" style="text-align: center; margin-left: auto; margin-right: auto;"></div>

需要动态修改CSSwidth属性。
由于是伪元素样式,并不属于DOM对象,因此,我们没有办法直接通过JQuery来修改。

比较完美的解决方法如下:

定义如下函数,对样式表遍历,根据名称获取我们指定的样式对象

function getRuleWithSelector(selector) {
    var numSheets = document.styleSheets.length;
    var numRules;
    var sheetIndex;
    var ruleIndex;
    // Search through the style sheets.
    for (sheetIndex = 0; sheetIndex < numSheets; sheetIndex += 1) {
        numRules = document.styleSheets[sheetIndex].cssRules.length;
        for (ruleIndex = 0; ruleIndex < numRules; ruleIndex += 1) {
            if (document.styleSheets[sheetIndex].cssRules[ruleIndex].selectorText === selector) {
                return document.styleSheets[sheetIndex].cssRules[ruleIndex];
            }
        }
    }
    return null;
}

function isNull(arg) {
    return ((undefined == arg) || (null == arg) ||('' == arg));
}

使用时候的代码如下:

var afterRule = getRuleWithSelector("#progress::after");
if (true != isNull(afterRule)){
	afterRule.style.width = '20%';
}

参考链接


modify pseudo select :after in javascript

Ubuntu 16.04 LTS上使用Python3版本的PIP

Ubuntu 16.04 LTS上使用Python2Python3是共存的,而且默认使用Python2,如果使用Python3则需要明确指定。

1.安装Python3版本的PIP

$ sudo apt-get install python3-pip

$ sudo pip3 install --upgrade pip

2.安装Python3版本的NumPy

$ pip3 install numpy

3.安装Python3版本的OpenCV

$ sudo pip3 install opencv-python

注意,目前的Python3版本的OpenCV是不支持cv2.imshow()的,具体查看https://pypi.python.org/pypi/opencv-python,可以看到如下信息:

**Q: Why I can't open GUI windows (``cv2.imshow()``) on GNU/Linux distribution X or on macOS?**

A: Like above, OpenCV was not compiled against GTK or Carbon. Support for these might be added in the future.