Author Archives: wenbin

h5py FutureWarning 问题修复

h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
h5py 和 numpy 版本冲突,h5py 官方已修复合并到 master 分支,但是还没发新版,在发版之前可以用降级 numpy 的方法跳过这个问题。降级命令如下:
pip install numpy==1.13.0
referece:
https://stackoverflow.com/questions/48340392/futurewarning-conversion-of-the-second-argument-of-issubdtype-from-float-to

sklearn cross_validation 过时问题解决

网上看的有些教程比较老,有跑起来报如下错误的:
/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
问题修复
将 from sklearn.cross_validation import train_test_split
改成 from sklearn.model_selection import train_test_split
即可

matplotlib python is not installed as a framework 问题修复

python import matplotlib.pyplot as plt 的时候报如下错误
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of ‘python’ with ‘pythonw’. See ‘Working with Matplotlib on OSX’ in the Matplotlib FAQ for more information.
解决方法是 在 ~/.matplotlib/matplotlibrc 中加入 backend: TkAgg
reference:
https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python

mac 安装 tensorflow

1、打开终端
2、sudo easy_install pip,有可能会报错 ImportError: cannot import name ContextualZipFile,原因大概是 setuptools 有问题。需要调整 setuptools 版本。我的机子装过 pip,通过 sudo python -m pip install –upgrade –force pip 命令强制升级到最新版。
3、pip install –upgrade virtualenv 安装虚拟环境
4、创建虚拟环境,mac 下默认 python 为2.x 版本,创建2.x 虚拟环境用 virtualenv –system-site-packages targetDirectory 命令。如果想安装 3.x 虚拟环境,需要先安装 python3。可以使用 brew install python 安装 python3.然后再执行 virtualenv –system-site-packages -p python3 targetDirectory 创建 python3 的虚拟环境。targetDirectory 可以使用官方推荐的 ~/tensorflow ,也可以自己定义。
5、进入 targetDirectory 目录 cd targetDirectory,执行 source ./bin/activate 激活虚拟目录。如果用的是 csh or tcsh ,命令为 source ./bin/activate.csh。
6、虚拟环境里安装和升级 pip easy_install -U pip,保证 pip 版本大于8.1。
7、安装和升级 tensorflow 。pip install –upgrade tensorflow,如果创建的是 python3虚拟环境,pip 和 pip3其实都是指向 pip3 的,所以不需要像官方文档里一样执行 pip3 install –upgrade tensorflow。
8、如果上面安装 tensorflow 执行失败,可以通过 pip3 install –upgrade tensorflow path 安装。tensorflow path 通过 https://www.tensorflow.org/install/install_mac#the_url_of_the_tensorflow_python_package 查找。
9、到这里已经安装完成啦,开始愉快的使用 tensorflow 吧
10、使用完后 执行 deactivate 退出虚拟环境。
11、如果想卸载的话可以使用 rm -r ~/tensorflow 。
看上面的过程是不是有点繁琐。所以建议使用 docker 来使用 tensorflow。比较简单,只有一个步骤。
1、docker run -it -p 8888:8888 tensorflow/tensorflow bash
不过为了保证这行命令的执行。还需要一波的操作来安装 docker,并配置好加速服务等。好在都是值得的,学会用 docker 好处多多。

vue for 循环中使用 input 无法连续输入问题

vue 的 for 循环中如果使用了 input,input 的值又为循环对象中的值,那么修改 input 的值的时候,会重新刷新 for 循环节点,导致 input 输入框失去焦点。处理方法也比较简单,在 input 的 change 事件里,添加 vue.$nextTick 注册下次刷新的时候重新获取 input 焦点即可。

nginx 代理超时时间设置

在公司维护的一个系统内部有提供接口代理转发功能。今天有使用方找过来说自己有个接口,由于依赖的服务有问题,且暂时性的无法修复,返回数据非常慢,要一两分钟才能返回。现在这个接口在我的系统里做转发,每次请求超过一分钟就会提示接口超时。
首先先了下转发逻辑,转发逻辑底层使用 Nodejs 的 http.request,默认没有超时时间。
再看了下 Nodejs Server 的默认超时时间是 120 秒。
加断点看了下,服务内部已经拿到了转发数据,但是在拿到转发数据之前,浏览器中就显示了超时。这样子看起来不是应用逻辑的问题。
上网搜了下 nginx 的默认超时,发现 nignx 好多不同的超时设置,并且默认都是 1 分钟。
看起来问题就在这里。找公司运维重新配置了下超时时间。在对应 nginx 代理设置中加入

proxy_connect_timeout 120s;
proxy_read_timeout 120s;
proxy_send_timeout 120s;

问题完美解决。

服务器 git 命令免输密码配置

背景:
在公司负责一个前端服务化项目,底层使用一个特权 git 账户进行项目的创建和发布等工作。最开始的时候服务器上 git 相关的配置是另外一个同事配的。
最近公司公司服务器机房迁移,因为不是标准化的项目,需要自己手动进行迁移。这就需要完全重新配置服务器环境。
一切迁移妥当后,测试发现 git 相关的脚本都无法跑通。打 log 发现是因为 git 命令无法免密执行,被交互的账号密码输入逻辑拦截了。

Continue reading

手机浏览器直接唤起微信方案调研

背景

双十二前一天半夜,正准备睡觉,公司运营打电话过来,说发现第三方公司有页面可以访问直接唤起微信。说完在公司的聊天工具里发来一段连接,叫我调研一下能不能实现,如果能实现,双十二马上可以用起来。

【梦梦家】双12倒计时啦!来就送10元券,http://t.cn/RTqAzl8 领10元券戳 回N退订。没有自己的流量池 就落后挨打 人家在第一时间已经用了 就等你来找我了,微信引流黑科技

分析

连接是个微博短链: http://t.cn/RTqAzl8。放浏览器里访问,解析出完整的地址
http://r.jpwx.kim/wb/0e7d51958ac79557b5ecafc582ab62d0.html。打开调试器看了下,页面中除了百度统计代码外,核心代码如下

Continue reading