WordPress 4.2版本之后,查看网页源代码你会发现WordPress会自动在加载一段用于支持emjo表情的脚本(JS+CSS)。对于大部分人来说,这个是十分鸡肋的功能,反而影响加载速度,仔细观察一下就会发现,这部分功能引入了非常多的脚本以及代码,实际上绝大部分人从来不使用这部分功能,另外这部分加载脚本在Internet Explorer 11 + HTTPS的时候,会出现警告访问不安全的内容,原因就在于emjo加载脚本在HTTPS的情况下依旧会使用HTTP去请求数据。
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。
python直接下载图片到内存
1. 使用requests(推荐)
|
1 2 3 4 |
from PIL import Image from StringIO import StringIO import requests Image.open(StringIO(requests.get(url, stream=True).raw.read())) |
2. 使用StringIO
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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
|
1 2 3 4 5 6 7 |
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) |
参考链接
Ubuntu 14.04下MySQL监控工具—mytop
安装
mytop的项目页面为:http://jeremy.zawodny.com/mysql/mytop/
Ubuntu 14.04上的安装非常简单,命令如下:
|
1 |
$ sudo apt-get install mytop |
安装完成后,执行如下命令启动(本机数据库的情况):
|
1 |
$ sudo mytop -uroot -ppassword |
启动后的界面如下图:
获取当前Python中site-packages的具体存放路径
很多时候,我们系统上安装了好几个版本的Python, 此时,我们往往没办法确定通过pip安装的包会存放到那个目录下的site-packages中,可以通过如下代码获取:
|
1 |
$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" |
在Ubuntu 16.04 LTS系统上,这个输出是存在问题的,执行命令后输出的目录是:
|
1 |
/usr/lib/python2.7/dist-packages |
实际上,通过pip命令安装的目录有很大一部分被安装到了
|
1 |
/usr/local/lib/python2.7/dist-packages |
目录下。
使用Git Submodule管理子模块
git submodule使得我们可以把他人的项目作为我们自己的子项目来进行管理,当对方修改后,一个简单的同步命令就可以完成代码的自动同步,方便我们的开发。添加一个项目到我们的工程中,比如:|
1 |
$ git submodule add git@github.com:jjz/pod-library.git pod-library |
检出主工程代码后,初始化子模块(需要手工执行)
|
1 |
$ git submodule update --init --recursive |
更新同步子模块的代码:
|
1 |
$ git submodule update --recursive --remote |
删除子模块的代码:
|
1 2 3 4 5 |
$ git submodule deinit pod-library $ git rm -f pod-library $ rm -rf .git/modules/pod-library |
参考链接
ubuntu 14.04 LTS关闭873端口
最近在使用百度统计的网站安全功能的时候,被报告存在873端口被打开的情况,刚开始以为是被入侵了,后来发现是在测试功能的时候无意安装了rsync导致的rsyncd在873端口进行监听。
解决方法就是卸载rsync即可:
|
1 2 3 4 |
$ 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中,使用如下配置即可:
|
1 2 3 4 5 6 |
#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声明:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#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中的声明如下:
|
1 |
<div id="progress" style="text-align: center; margin-left: auto; margin-right: auto;"></div> |
需要动态修改CSS的width属性。
由于是伪元素样式,并不属于DOM对象,因此,我们没有办法直接通过JQuery来修改。
比较完美的解决方法如下:
定义如下函数,对样式表遍历,根据名称获取我们指定的样式对象
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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)); } |
使用时候的代码如下:
|
1 2 3 4 |
var afterRule = getRuleWithSelector("#progress::after"); if (true != isNull(afterRule)){ afterRule.style.width = '20%'; } |