python numpy/matplotlib绘制生物节律曲线

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

import datetime
import math

def daysnow(birthdate):
return (datetime.date.today() – birthdate).days

def clockwise(days, p):
return math.sin(2*math.pi *(days % p) / p)

def clockwise_2(date, birthdate, p):
return math.sin(2*math.pi*((date – birthdate).days % p) / p)

base = datetime.date.today()
birthdate = datetime.date(年, 月, 日)
datelist = [base + datetime.timedelta(days=x) for x in range(-15, 15)]

dla = np.array(datelist)
dlb = np.array([clockwise_2(x, birthdate, 23) for x in datelist])
dlc = np.array([clockwise_2(x, birthdate, 28) for x in datelist])
dld = np.array([clockwise_2(x, birthdate, 33) for x in datelist])

plt.plot(dla, dlb, dla, dlc, dla, dld)
plt.show()

java/ruby unzip

http://www.java2s.com/Tutorial/Java/0180__File/UnzipusingtheZipInputStream.htm

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class MainClass {

public static void main(String[] args) throws IOException {

for (int i = 0; i < args.length; i++) { FileInputStream fin = new FileInputStream(args[i]); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } zin.close(); } } } http://www.kodejava.org/examples/334.html package org.kodejava.example.util.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; public class UnzipDemo { public static void main(String[] args) { String zipname = "data.zip"; try { FileInputStream fis = new FileInputStream(zipname); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; // // Read each entry from the ZipInputStream until no more entry found // indicated by a null return value of the getNextEntry() method. // while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); int size; byte[] buffer = new byte[2048]; FileOutputStream fos = new FileOutputStream(entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } } http://www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/ require 'rubygems' require 'zip/zip' def unzip_file (file, destination) Zip::ZipFile.open(file) { |zip_file| zip_file.each { |f| f_path=File.join(destination, f.name) FileUtils.mkdir_p(File.dirname(f_path)) zip_file.extract(f, f_path) unless File.exist?(f_path) } } http://stackoverflow.com/questions/856891/unzip-zip-tar-tag-gz-files-with-ruby http://www.anyang-window.com.cn/tag/ava-zip/page/3/ http://www.iteye.com/topic/626705

Python 2.7.9+gevent

Python 2.7.9+gevent会出问题。
如果你使用gevent 1.0 ,比如你使用Ubuntu 14.10,使用apt-get安装的缺省版本就是它,报的错误是:global name SSLContext not defined.这个路线我现在还没有分析。
如果你使用gevent 1.0.1,同样在Ubuntu 14.10,使用sudo easy_install -U gevent,安装的版本是目前gevent的最新版本1.0.1。提示的错误是:global name sslwrap not defined。

根据Debian的bug report,这个问题已经出现好长时间了。

Google的解决方案如下:
1. https://gist.github.com/ellimilial/5ef1d1917e00970d4457

sudo apt-get install python-dev cython git python-pip
sudo pip install git+git://github.com/ellimilial/gevent.git@master

not work。因为网络的原故,从github直接这么安装着实是慢得要死。

2. https://github.com/gevent/gevent/issues/477
这里面提供的代码经过测试是好用的,前提是使用gevent的最新1.0.1版本。

gist地址:https://gist.github.com/zz/af7d9efa539999757950

代码如下:

# Re-add sslwrap to Python 2.7.9
import inspect
__ssl__ = __import__('ssl')

try:
    _ssl = __ssl__._ssl
except AttributeError:
    _ssl = __ssl__._ssl2

def new_sslwrap(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=__ssl__.CERT_NONE,  ssl_version=__ssl__.PROTOCOL_SSLv23, ca_certs=None, ciphers=None):
    context = __ssl__.SSLContext(ssl_version)
    context.verify_mode = cert_reqs or __ssl__.CERT_NONE
    if ca_certs:
        context.load_verify_locations(ca_certs)
    if certfile:
        context.load_cert_chain(certfile, keyfile)
    if ciphers:
        context.set_ciphers(ciphers)

    caller_self = inspect.currentframe().f_back.f_locals['self']
    return context._wrap_socket(sock, server_side=server_side, ssl_sock=caller_self)

if not hasattr(_ssl, 'sslwrap'):
    _ssl.sslwrap = new_sslwrap

考虑到使用方便,可以使用下面代码(因为这条import当时忘记了,结果又重新修改了一下)

# Re-add sslwrap to Python 2.7.9
import inspect

def new_sslwrap(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=__ssl__.CERT_NONE,  ssl_version=__ssl__.PROTOCOL_SSLv23, ca_certs=None, ciphers=None):
    context = __ssl__.SSLContext(ssl_version)
    context.verify_mode = cert_reqs or __ssl__.CERT_NONE
    if ca_certs:
        context.load_verify_locations(ca_certs)
    if certfile:
        context.load_cert_chain(certfile, keyfile)
    if ciphers:
        context.set_ciphers(ciphers)

    caller_self = inspect.currentframe().f_back.f_locals['self']
    return context._wrap_socket(sock, server_side=server_side, ssl_sock=caller_self)

if not hasattr(_ssl, 'sslwrap'):
    _ssl.sslwrap = new_sslwrap

加到这段代码之下:

try:
    _ssl = __ssl__._ssl
except AttributeError:
    _ssl = __ssl__._ssl2

修改文件的位置:/usr/local/lib/python2.7/dist-packages/gevent-1.0.1-py2.7-linux-x86_64.egg/gevent
文件名:ssl.py

记得Ubuntu下使用gksu来应用权限。

此记。
———-
为什么会遇到这个问题:之前一篇文章说使用gevent速度会快些。已经加上了,速度什么的没有体会,反倒让这个问题折腾了,太喜爱技术的问题,以后还是少点发散吧。

update-alternatives bug?

这两天学习SCRUM之后,感觉还真是不错,有的时候自己看书啊,自己想策略啊什么的是不如这个方式快。
好久没碰代码,今天心血来潮,试试Play 2.0,自从用了Play 1.x,2.0出来很久了都没有碰过。2.0改成了Scala是比较感兴趣的。

但是create hello后run的时候发生了一个很奇怪的错误。
参见:java.lang.ExceptionInInitializerError when trying to run Play Application

第一感觉是path不对?不能啊,以前没改过java的设置。
想起以前用过update-alternatives配置过java,因为另一个用java的SweetHome3D在Linux 64bit上经常闪退,切换过OpenJDK和Oracle JDK,还有1.6/1.7的切换。

验证之下
java 1.7
javac 1.6

用update-alternatives切换成7,javac还是1.6
ls /usr/bin/javac发现它是链接在/etc/alternatives/javac上的,手工改成7的就好了。

当然,问题继续存在,参考了stackover的答案。
见:JNotify Linux support</>
到Linux的root用户下修改

echo 32000 > /proc/sys/fs/inotify/max_user_watches

一切OK。