多年以后,奥雷连诺上校站在行刑队面前,准会想起父亲带他去参观冰块的那个遥远的下午

Latest Entries

PHP: 在数组中特定位置增加一个元素

  1. $a=array('apple', 'banana', 'orange');
  2. var_dump($a);
  3. /* It will output:
  4. array(3) {
  5.   [0]=>
  6.   string(5) "apple"
  7.   [1]=>
  8.   string(6) "banana"
  9.   [2]=>
  10.   string(6) "orange"
  11. }
  12. */
  13.  
  14. array_splice($a,2,0,'grape');
  15. var_dump($a);
  16. /* It will output:
  17. array(4) {
  18.   [0]=>
  19.   string(5) "apple"
  20.   [1]=>
  21.   string(6) "banana"
  22.   [2]=>
  23.   string(5) "grape"
  24.   [3]=>
  25.   string(6) "orange"
  26. }
  27. */

PHP命名空间诞生记

提供图片一张!

我也曾如此矫情

“世界是美丽的也是丑陋的。没有人可以统一一个美与丑的标准,但我知道价值观在其中扮演着很重要的角色。”

“不管是美是丑,总得面对现实,不能逃避。”

“在那个遥远的日子,我们许下了无法实现的约定……”

2005年的我就是这个样子吗?那个虚幻的我们究竟意味着什么样的精神诉求?

http://blog.donews.com/xchange/有感而发。

我在实验室用的电脑

是不是很强大啊?

Doctrine 入门 (一)

Doctrine 是一个基于 PDO (PHP Data Objects) 数据库抽象层的 ORM (Object Relational Mapping) 解决方案,目前最新的稳定版本是 1.0.3。著名的 PHP 开发框架 Symfony 将用 Doctrine 代替原有的 Propel 对象关系模型。

1. 系统需求

PHP 版本大于等于 5.2.3,启用 PDO 扩展,并且配置好相应的 PDO 驱动模块。

2. 获取 Doctrine

获取Doctrine有以下几种方法:
从 http://www.doctrine-project.org/latest-release 下载;
用 svn co http://svn.phpdoctrine.org/branches/1.0 命令从 SVN 仓库检出;
用 pear install http://pear.phpdoctrine.org/Doctrine-0.11.0 命令从 PEAR 仓库中安装。

3. 创建数据库

Doctrine 经过配置后可以应用于已经存在的数据表,也可以直接利用 Doctrine 创建我们所需要的数据表。

Doctrine 创建数据表的第一步是构造 Model,在 Doctrine 中是 Doctrine_Record 子类以提供足够的信息。该类包含了数据表中的列以及和其他表的关系。生成 Doctrine_Record 的子类有两种方法,一是直接编写 PHP 代码,一种是编写 YAML 格式的配置文件。

假定我们需要创建一个用户表保存网站用户的登录名、昵称、密码和电子邮件地址,那么可以用如下的 YAML 配置文件描述数据结构:

[ user.yml ]

  1. User:
  2.     columns:
  3.         name:
  4.             type: string(24)
  5.         nick:
  6.             type: string(24)
  7.         password:
  8.             type: string(32)
  9.         email:
  10.             type: string(100)

很明显,这里定义了一个 User 表,同时定义了表中的四个数据列: name、nick、password 和 email,这些列都是 string 类型,并且有不同的长度。从这样的配置文件出发,由如下的 PHP 命令可以生成 model 代码:

  1. <?php
  2. Doctrine::generateModelsFromYaml('/path/to/user.yml', '/path/to/models');
  3. ?>

注:这不是完整的可运行的 PHP 代码,因为它缺少很多必要的组成部分。

上述命令将在 models 目录下生成 User.php 和 generated 目录,generated 目录下有 BaseUser.php。

[ BaseUser.php]

  1. <?php
  2. /**
  3. * This class has been auto-generated by the Doctrine ORM Framework
  4. */
  5. abstract class BaseUser extends Doctrine_Record
  6.     {
  7.         public function setTableDefinition()
  8.             {
  9.                 $this->setTableName('user');
  10.                 $this->hasColumn('name', 'string', 24, array('type' => 'string', 'length' => '24'));
  11.                 $this->hasColumn('nick', 'string', 24, array('type' => 'string', 'length' => '24'));
  12.                 $this->hasColumn('password', 'string', 32, array('type' =>'string', 'length' => '32'));
  13.                 $this->hasColumn('email', 'string', 100, array('type' => 'string', 'length' => '100'));
  14.             }
  15.     }
  16.  
  17. ?>

BaseUser.php 定义了一个继承自 Doctrine_Record 的抽象,描述了 User 表的数据结构。

[ User.php ]

  1. <?php
  2. /**
  3. * This class has been auto-generated by the Doctrine ORM Framework
  4. */
  5.     class User extends BaseUser
  6.         {
  7.         }
  8. ?>

User.php 很简单地从 BaseUser 继承而来,开发人员可以有针对性地增加所需的内容。

如果直接编写 model 的代码,也可以不采用这样的继承机制,直接从 Doctrine 派生子类。

[ User.php ]

  1. <?php
  2. class User extends Doctrine_Record
  3.     {
  4.         public function setTableDefinition()
  5.             {
  6.                 $this->setTableName('user');
  7.                 $this->hasColumn('name', 'string', 24, array('type' => 'string', 'length' => '24'));
  8.                 $this->hasColumn('nick', 'string', 24, array('type' => 'string', 'length' => '24'));
  9.                 $this->hasColumn('password', 'string', 32, array('type' => 'string', 'length' => '32'));
  10.                 $this->hasColumn('email', 'string', 100, array('type' => 'string', 'length' => '100'));
  11.             }
  12.     }
  13. ?>

然后用

  1. <?php
  2. Doctrine::createTablesFromArray(array('User'));
  3. ?>

在数据库中创建真实的数据表。

以上过程完整的代码如下:

[ createUserTable.php ]

  1. <?php
  2. // 载入 Doctrine
  3. include_once('/path/to/Doctrine/lib/Doctrine.php');
  4.  
  5. // 注册自动载入函数
  6. spl_autoload_register(array('Doctrine', 'autoload'));
  7.  
  8. // 连接数据库
  9. $conn=Doctrine_Manager::connection('mysql://user:password@host/demo');
  10.  
  11. // 设定字符集
  12. $conn->setCharset('utf8');
  13.  
  14. // 生成 model 代码
  15. Doctrine::generateModelsFromYaml('/path/to/user.yml', '/path/to/models');
  16.  
  17. // 载入 model 代码
  18. include_once('/path/to/models/User.php');
  19. include_once('/path/to/models/generated/BaseUser.php');
  20.  
  21. // 创建数据表
  22. Doctrine::createTablesFromArray(array('User'));
  23.  
  24. ?>

从这里可以看出,要能够正确地利用 Doctrine 进行开发,需要在代码中进行一些必要的配置。注册 Doctrine::autoload() 为全局的 __autoload() 是必须的。连接数据库的参数和 PDO 的完全一致,你甚至可以直接把一个 PDO 连接作为参数传递给 Doctrine_Manager::connection()。

细心的读者一定会注意到,我们对 User 表的描述缺少了一个重要的组成部分即主键,这是因为 Doctrine 会帮助我们自动生成一个 id 主键。如果需要自己定义主键,可以给需要的列加上 primary : true 属性。

复杂的海平面变化

通常的想法是晚更新世的末次盛冰期 ( 30000 到 19000 年前) 之后,海平面就开始上升。但是实际上海平面的变化是一个十分复杂的过程,研究表明某些地方的海平面并没有上升,反而下降了。

一般认为地球是一个刚性的球体,不考虑它的形变。于是冰川消融之后,海水的总体积大为增加,海平面便上升了许多。实际上,地球并非一成不变,坚硬的地壳下面是可塑性很强的地幔。当北方的广大土地被冰川覆盖后,这些地区便承载了巨大的冰川重量,并引起了地面的下陷。一旦冰川融化,这些重量就转移到了海洋之中。失去了压迫的地面会重新反弹回原来的高度,而海洋底部的地面则因为承载了更多的重量而下陷。同时,地球表面这种大规模的质量转移,会对重力场的分布产生影响。这些的因素综合起来便产生了目前看到的多种多样的海平面变化格局。

冰川的融化一直持续到 7000 年前,之后海平面就稳定在现在的水平,直到温室效应的显著结果出现。

Archlinux安装Lighttpd并配置PHP

首先确认自己有 root 权限,然后执行如下命令安装 Lighttpd 和 FastCGI 支持:

$pacman -S lighttpd fcgi

然后安装 PHP

$pacman -S php

修改 /etc/lighttpd/lighttpd.conf,去掉 mod_fastcgi 行的 # 符号以开启 FastCGI 模块。增加如下内容:

fastcgi.server = ( “php” => ((

“socket” => “/tmp/php-fcgi.socket”

“bin-path” => “/usr/bin/php-cgi”

))

)

再运行

$/etc/rc.d/lighttpd start

即可。

想要开机自动运行,在 /etc/rc.conf 中的 DAEMON 段加入lighttpd。Lighttpd 的默认网站目录是 /srv/http。

Parameters in isolation with migration (IM) model

Parameters

Description

N1

Effective size of population 1

N2

Effective size of population 2

NA

Effective size of ancestral population

θ1 = 4N1u

Population mutation rate for population 1

θ2 = 4N2u

Population mutation rate for population 2

θA = 4NAu

Population mutation rate for ancestral population

u

The neutral mutation rate for the entire sequence per generation

m1

Migration rate per gene per generation from population 2 to population 1 in the conventional sense of time moving forwards or from population 1 to population 2 in the coalescent

m2

Migration rate per gene per generation from population 1 to population 2 in the conventional sense of time moving forwards or from population 2 to population 1 in the coalescent

m1 = m1 / u

Migration rate per mutation from population 2 to population 1

m2 = m2 / u

Migration rate per mutation from population 1 to population 2

t

The time (generation) since ancestral population split into two population

t = t u

The number of mutations since ancestral population split into two population

2N1m1

The effective number of gene migrants into population 1 per generation

2N2m2

The effective number of gene migrants into population 2 per generation

It is important to distinguish m1 and m1. Some people use M instead of m.

Normally, IM program estimated θ1 (q1), θ2 (q2), θA (qA), t, m1 and m2. If ‘-p4’ and ‘-u’ is provided in the command line, parameters N1, N2, NA, t, m1, and m2 will be estimated. At this time, mutation rate for the entire sequence per year should be include in the input file, and ‘-u’ should be used to provide the generation time in years.

Mutation rate of mtDNA

If d is the genetic distance between two species, and T is the their divergence time, the mutation rate per site per year (λ) can be calibrated as:

λ = d / 2T

In some papers, d / T was used to estimate the divergence time from existent genetic distance. This is not mutation rate but divergence rate.

If tg is the generation time, the mutation rate per site per generation is:

μ = λtg

If m is sequence length (bp), the mutation rate per sequence per generation is:

υ =

The symbols of these rates were different in different papers, so we should know which rate they used for their analyses.

我回来了

快要有一年时间没有写blog了,却觉得并没有什么不妥,看来世界上也许真的没有什么能让我放不下的东西。不过对于回归Wordpress之后有些什么事情可做,我却毫无想法。

既然如此我也只能回顾一下这接近一年的时间里所做的一些微不足道的小事。首先呢,PHP基本上是完全荒废掉了,没有写过几行代码,也没有关注技术动态,只有5.3版本开始alpha测试的时候小兴奋了一下。然后呢,开始学习Python这个好玩的东东,并且愉快地应用于工作中。用Python编写的一些小脚本确实对我有很大的帮助,省却了很多重复的体力劳动。这一切都要归功于BioPython这个好东东啊。再然后呢,看了一点Django的入门,不过对它的机制还处于两眼一抹黑状态。