Sunday, February 19, 2017

记录ConfigParser在Python2.6下一坑

import ConfigParser
import codecs
import os

#category_cfg_file="category.cfg"

category_cfg = ConfigParser.ConfigParser()
with codecs.open('feature_common.config', 'r',encoding='utf-8') as configfile:
    category_cfg.readfp(configfile)
   
   
features = category_cfg.sections()


上面代码在Python2.7下,返回的features顺序和配置文件中的顺序是一样的,可是服务器用的是Python2.7,这个返回的竟然是无序的,查到了很久才查到这一块。我草快被坑死了。

http://stackoverflow.com/questions/1134071/keep-configparser-output-files-sorted
找到答案,修复方法如下

In Python 2.7, you can from collections import OrderedDict and use ConfigParser(dict_type=OrderedDict) to make the parser use an ordered dictionary. Based on a minimal amount of testing, I think this should serve you well.

Wednesday, February 15, 2017

shell传参

http://stackoverflow.com/questions/415677/how-to-replace-placeholders-in-a-text-file

https://my.oschina.net/iuranus/blog/279985

Monday, February 13, 2017

安装mysqldb

##centos 环境
sudo yum install mysql-devel
sudo pip install mysql-python


##ubuntu环境
Starting with a vanilla Lucid install [1], install pip and upgrade to the latest version:
apt-get install python-pip
pip install -U pip
Next, install the required development packages:
apt-get install python-dev libmysqlclient-dev
then
pip install MySQL-python
should complete successfully.


mac下安装
$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python

Saturday, January 7, 2017

scala 第一深坑

http://stackoverflow.com/questions/23722048/intellij-idea-13-new-scala-sbt-project-hasnt-src-directory-structure-generated


2.intellij 打开终端terminal
alt+f12

Thursday, January 5, 2017

redis-py-cluster一坑记录

按照文档例子来一发,发现错误呀,单用redis-py错误呀
>>> from rediscluster import StrictRedisCluster

>>> # Requires at least one node for cluster discovery. Multiple nodes is recommended.
>>> startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]

>>> # Note: decode_responses must be set to True when used with python3
>>> rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)

>>> rc.set("foo", "bar")
True
>>> print(rc.get("foo"))
'bar'

cluster错误如下:
ResponseError: unknown command 'CONFIG'

想死有没有,各种找不到答案
https://www.digitalocean.com/community/tutorials/how-to-secure-your-redis-installation-on-ubuntu-14-04

看到这篇文章,原来server可以选择屏蔽一些命令的,然后,搜索redis-py-cluster源码,找到这么一句

If your redis instance is configured to not have the `CONFIG ...` comannds enabled due to security reasons you need to pass this into the client object `skip_full_coverage_check=True`. Benefits is that the client class no longer requires the `CONFIG ...` commands to be enabled on the server. Downsides is that you can't use the option in your redis server and still use the same feature in this client.

加了一个skip_full_coverage_check=True搞定

Friday, December 16, 2016

WINDOWS SUBSYSTEM使用中遇到的问题


  1. sudo: unable to resolve host OPTIMISTPRIME
解决方法:http://iamnotmyself.com/2016/07/13/windows-subsystem-for-linux-error-unable-to-resolve-host-2/

编辑/etc/hosts 加入一行127.0.0.1 OPTIMISTPRIME


2.安装redis-server遇到问题如下:
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: No such file or directory

此问题基本使用subsystem都会遇到
解决方法:
This is an issue that everyone will start seeing. We need to add something on this in our official docs.
As @nuclearmistake points out, udev is something that breaks in apt-get but the errors should not cause any issues in WSL. We have reached out to Canonical on this one asking for the best solution and they recommend the following changes:
Write the following to /usr/sbin/policy-rc.d
#!/bin/sh
exit 101
chmod +x /usr/sbin/policy-rc.d
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
I have tried this one myself and it looks to work quite well.

参见https://github.com/Microsoft/BashOnWindows/issues/143

3.直接执行redis-server启动redis,起不来,使用sudo redis-server能够启动,但是redis-cli不能联通

方法如下:
执行sudo service redis-server start

参见:https://github.com/Microsoft/BashOnWindows/issues/365

jetbrains 激活

http://jetbrains.tencent.click
IntelliJ IDEA 2016.2.4


1. 到网站 http://idea.lanyus.com/ 获取注册码。
2.填入下面的license server:
  http://intellij.mandroid.cn/
  http://idea.imsxm.com/
  http://idea.iteblog.com/key.php
2017.3版本更新后2已失效,使用1吧,或者自行搭建授权服务器(1上有教程)
idea 还可以申请edu邮箱获取linsence key,有邮箱的可以尝试一下(可以尝试去注册免费的edu邮箱进行申请) https://www.jetbrains.com/zh/student/
http://idea.imsxm.com/
分类: idea