远行者

Feed Rss

密码保护:《无奈的人生》

04.20.2012, 要查看留言请输入您的密码。, 日记, by .

这是一篇受密码保护的文章。您需要提供访问密码:


1、安装samba(centos Linux):

yum install samba system-config-samba samba-client samba-common

2、创建apache账号:

groupadd apache
useradd -g apache apache
web:/usr/local/apache/htdocs/
chown -R apache:apache /usr/local/apache/htdocs/
chmod 777 /usr/local/apache/htdocs/
cat /etc/passwd | mksmbpasswd.sh> /etc/samba/smbpasswd

3、创建samba配置文件

mv -f /etc/samba/smb.conf /etc/samba/smb.conf.bak
vi /etc/samba/smb.conf

输入以下内容:

[global]
server string = Samba Server
security = user
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
 
 
[knose]
workgroup = root
netbios name = root
path = /data0/knose
browseable = yes
writeable = yes
 
[web]
workgroup = apache
netbios name = apache
path = /usr/local/apache/htdocs/
browseable = yes
writeable = yes

4、为samba用户apache、root设立一个密码:

smbpasswd -a apache
smbpasswd -a root

5、启动samba:

service smb start

CentOS 6 安装:
源:http://geekery.altervista.org/dokuwiki/doku.php

yum install git

CentOS 5 以下安装:
确保安装了以下包:

yum install curl
yum install curl-devel
yum install zlib-devel
yum install openssl-devel
yum install perl
yum install cpio
yum install expat-devel
yum install gettext-devel

下载最新的git包

wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
tar xzvf git-latest.tar.gz
cd git-2012-04-09 #注意目录日期会有不同
autoconf
./configure
make
make install

检查下安装的版本,大功告成

git --version

今天在迁移网站的过程中遇到了数据表只读的情况:table ‘[Table]stats’ is read only

经过分析尝试,得出一些经验,分享一下:

1、这个问题一般出现在迁移mysql数据库,一般来说需要先检查用户与权限的问题,比如有某一个mysql数据库为is36,我们的mysql管理用户与组均为mysql,那么我们通过命令设置它的所有者为mysql:#chown mysql.mysql is36/*

2、再设置数据库中的所有表信息为660权限,也就是所有者mysql与所在的mysql用户组可读可写:#chmod 660 is36/*

3、以上操作完成后数据库表访问权限问题应该是没有了,但是依旧会显示这个错误,那么进入phpmyadmin,尝试对这个数据表进行repair(修复)操作,如果提示修复成功,那么这个read only的问题应该是解决了,回到页面上刷新一下即可。但是在我测试的过程中,也有一些数据表提示read only,但却修复失败,那么继续往下走。

4、进入mysql的bin工具目录,执行如下命令:#./mysqladmin -u -p flush-tables 其中是你的mysql管理员用户,一般为root。执行完成这条命令,再去刷新页面,应该是正常了。

chkconfig --add httpd

报 service httpd does not support chkconfig 错误。
出错原因:apachectl 这个脚本文件缺乏 chkconfig 和 description 这两个标签说明。
解决方法:

vim /etc/rc.d/init.d/httpd

#!/bin/sh
#

下增加以下说明:

# Startup script for the Apache Web Server
#
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.
#

2345 表示LINUX需要启动的各个级别,如果一个都不想on,那就写一个横线”-”,比如:chkconfig: – 85 15
85 15 表示S和K的默认排序号.

再 chkconfig –add httpd 不会报错了,接着执行以下命令完成设置.

chkconfig httpd on
service httpd start

安装cmake:
mysql5.5以后是通过cmake来编译的

wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make
make install
cmake --version //查看cmake已安装版本

1、卸载yum或rpm安装的amp软件

rpm -qa|grep httpd
rpm -e httpd
rpm -qa|grep mysql
rpm -e mysql
rpm -qa|grep php
rpm -e php

yum -y remove httpd
yum -y remove php
yum -y remove mysql-server mysql
yum -y remove php-mysql

yum -y install yum-fastestmirror
yum -y remove httpd
yum -y update

2、禁用SeLinux

sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

3、yum安装必要工具

yum -y install gcc gcc-c++ libtool-libs autoconf freetype freetype-devel gd libjpeg libjpeg-devel libmcrypt libmcrypt-devel libpng libpng-devel libxml2 libxml2-devel ncurses ncurses-devel zlib zlib-devel zip unzip curl curl-devel

4、下载所需源码

wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.22.tar.gz
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.59.tar.gz/from/http://mysql.he.net/
wget -c http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
wget -c http://superb-dca2.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.5/phpMyAdmin-3.4.5-all-languages.tar.gz

5、安装apache2.2.22

./configure –prefix=/usr/local/apache/ –with-included-apr –disable-userdir –enable-so –enable-deflate=shared –enable-expires=shared –enable-rewrite=shared –enable-static-support

make
make install

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
chkconfig –add httpd
chkconfig –level 35 httpd on
cd /etc
mv httpd httpd_old
ln -s /usr/local/apache/ httpd
cd /usr/sbin/
ln -fs /usr/local/apache/bin/httpd
ln -fs /usr/local/apache/bin/apachectl
cd /var/log
rm -rf httpd/
ln -s /usr/local/apache/logs httpd
groupadd apache
useradd -g apache apache

配置httpd.conf:

1、在httpd.conf文件找到daemon,修改为apache;
2、在httpd.conf 最后一行增加:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE text/html

问题:

执行:chkconfig –add httpd
报错:service httpd does not support chkconfig
解决:
在#!/bin/sh下行添加:
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server

6、安装mysql5.1.59

groupadd mysql
useradd -g mysql mysql
cd /lamp/mysql-5.1.59
./configure –prefix=/usr/local/mysql/ –with-extra-charsets=all
make
make install

cp support-files/my-medium.cnf /etc/my.cnf
sed -i ‘s/skip-locking/skip-external-locking/g’ /etc/my.cnf
sed -i ‘s/^log-bin=mysql-bin/#log-bin=mysql-bin/g’ /etc/my.cnf
sed -i ‘s/^binlog_format=mixed/#binlog_format=mixed/g’ /etc/my.cnf
echo “skip-innodb” >> /etc/my.cnf
echo “skip-bdb” >> /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db –user=mysql
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql

/usr/local/mysql/bin/mysqld_safe –user=mysql &

cp /lamp/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig –add mysqld
chkconfig –list mysqld
chkconfig –levels 245 mysqld off
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
service mysqld start
/usr/local/mysql/bin/mysqladmin -u root password ‘新密码’

7、安装PHP5.2.17

cd /lamp/php-5.2.17
./configure –prefix=/usr/local/php/ –with-config-file-path=/usr/local/php/etc/ –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql/ –with-zlib -with-zlib-dir=/usr –with-libxml-dir=/usr –with-jpeg-dir –with-freetype-dir –with-gd –enable-gd-native-ttf –with-curl –enable-zip –with-mcrypt=/usr –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-soap –enable-mbstring=all –enable-sockets
make
make install

cp php.ini-dist /usr/local/php/etc/php.ini
sed -i ‘/\s\s*AddType.*tgz$/a\ Addtype application/x-httpd-php .php .phtml’ /etc/httpd/conf/httpd.conf
service httpd restart

GD库本身没有处理bmp的函数,所以只能自己模拟了,虽然效率不高,但至少能满足需求。。

以下2个函数,能够顺利解决bmp处理遇到的问题。。。

imagecreatefrombmp函数:

/**
 * 从BMP文件或 URL 新建一图像
 *
 * @param string $sFileName   图像资源
 * @return resource
 */
function imagecreatefrombmp( $sFileName )
{
   if( !$binResources = fopen( $sFileName, "rb" ) )
   {
		return false;   
   }
 
   $FILE = unpack( "vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread( $binResources, 14 ) );
 
   if( $FILE['file_type'] != 19778 ) 
   {
		return false;
   }
 
   $BMP = unpack( 'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
                 '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
                 '/Vvert_resolution/Vcolors_used/Vcolors_important', fread( $binResources, 40 ) );
   $BMP['colors'] = pow( 2,$BMP['bits_per_pixel'] );
   if( $BMP['size_bitmap'] == 0 ) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
   $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
   $BMP['bytes_per_pixel2'] = ceil( $BMP['bytes_per_pixel'] );
   $BMP['decal'] = ( $BMP['width'] * $BMP['bytes_per_pixel']/4 );
   $BMP['decal'] -= floor( $BMP['width'] * $BMP['bytes_per_pixel']/4 );
   $BMP['decal'] = 4-( 4*$BMP['decal'] );
   if( $BMP['decal'] == 4 ) $BMP['decal'] = 0;
 
   $PALETTE = array();
   if( $BMP['colors'] < 16777216 )
   {
	   $PALETTE = unpack( 'V'.$BMP['colors'], fread( $binResources, $BMP['colors']*4 ) );
   }
 
   $IMG = fread($binResources,$BMP['size_bitmap']);
   $VIDE = chr(0);
 
   $res = imagecreatetruecolor( $BMP['width'], $BMP['height'] );
   $P = 0;
   $Y = $BMP['height']-1;
	while ( $Y >= 0 )
	{
		$X=0;
		while ( $X < $BMP['width'] )
		{
			if ( $BMP['bits_per_pixel'] == 24 )
				$COLOR = unpack( "V", substr( $IMG, $P, 3 ).$VIDE );
			elseif ( $BMP['bits_per_pixel'] == 16 )
			{ 
				$COLOR = unpack( "n", substr( $IMG, $P, 2 ) );
				$COLOR[1] = $PALETTE[$COLOR[1]+1];
			}
			elseif ( $BMP['bits_per_pixel'] == 8 )
			{ 
				$COLOR = unpack( "n", $VIDE.substr( $IMG, $P, 1 ) );
				$COLOR[1] = $PALETTE[$COLOR[1]+1];
			}
			elseif ( $BMP['bits_per_pixel'] == 4 )
			{
				$COLOR = unpack( "n", $VIDE.substr( $IMG, floor($P), 1 ) );
			if ( ( $P * 2 ) % 2 == 0 ) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
				$COLOR[1] = $PALETTE[$COLOR[1]+1];
			}
			elseif ( $BMP['bits_per_pixel'] == 1 )
			{
				$COLOR = unpack( "n", $VIDE.substr( $IMG, floor($P), 1 ) );
			if     (($P*8)%8 == 0) $COLOR[1] =  $COLOR[1]        >>7;
			elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
			elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
			elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
			elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
			elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
			elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
			elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
				$COLOR[1] = $PALETTE[$COLOR[1]+1];
			}
			else
				return false;
				imagesetpixel( $res, $X, $Y, $COLOR[1] );
				$X++;
				$P += $BMP['bytes_per_pixel'];
			}
		$Y--;
		$P+=$BMP['decal'];
	}
   fclose( $binResources );
   return $res;
}

imagebmp函数:

/**
 * 创建bmp格式图片
 *
 * @param resource $im          图像资源
 * @param string   $filename    如果要另存为文件,请指定文件名,为空则直接在浏览器输出
 * @param integer  $bit         图像质量(1、4、8、16、24、32位)
 * @param integer  $compression 压缩方式,0为不压缩,1使用RLE8压缩算法进行压缩
 * @return integer
 */
function imagebmp(&$im, $filename = '', $bit = 8, $compression = 0)
{
    if ( !in_array( $bit, array( 1, 4, 8, 16, 24, 32 ) ) )
    {
        $bit = 8;
    }
    else if ( $bit == 32 ) 
    {
        $bit = 24;
    }
 
    $bits = pow( 2, $bit );
 
    // 调整调色板
    imagetruecolortopalette( $im, true, $bits );
    $width  = imagesx( $im );
    $height = imagesy( $im );
    $colors_num = imagecolorstotal( $im );
 
    if ( $bit <= 8 )
    {
        // 颜色索引
        $rgb_quad = '';
        for ( $i = 0; $i < $colors_num; $i ++ )
        {
            $colors = imagecolorsforindex( $im, $i );
            $rgb_quad .= chr( $colors['blue']) . chr($colors['green']) . chr($colors['red'] ) . "\0";
        }
 
        // 位图数据
        $bmp_data = '';
 
        // 非压缩
        if ( $compression == 0 || $bit < 8 )
        {
            if ( !in_array( $bit, array( 1, 4, 8 ) ) )
            {
                $bit = 8;
            }
 
            $compression = 0;
 
            // 每行字节数必须为4的倍数,补齐。
            $extra = '';
            $padding = 4 - ceil( $width / ( 8 / $bit ) ) % 4;
            if ( $padding % 4 != 0 )
            {
                $extra = str_repeat( "\0", $padding );
            }
 
            for ( $j = $height - 1; $j >= 0; $j -- )
            {
                $i = 0;
                while ( $i < $width )
                {
                    $bin = 0;
                    $limit = $width - $i < 8 / $bit ? ( 8 / $bit - $width + $i ) * $bit : 0;
 
                    for ( $k = 8 - $bit; $k >= $limit; $k -= $bit )
                    {
                        $index = imagecolorat( $im, $i, $j );
                        $bin |= $index << $k;
                        $i ++;
                    }
 
                    $bmp_data .= chr( $bin );
                }
 
                $bmp_data .= $extra; 
            }
        }
        // RLE8 压缩
        else if ( $compression == 1 && $bit == 8 )
        {
            for ( $j = $height - 1; $j >= 0; $j-- )
            {
                $last_index = "\0";
                $same_num   = 0;
                for ( $i = 0; $i <= $width; $i ++ )
                {
                    $index = imagecolorat( $im, $i, $j );
                    if ( $index !== $last_index || $same_num > 255 )
                    {
                        if ( $same_num != 0 )
                        {
                            $bmp_data .= chr( $same_num ) . chr( $last_index );
                        }
 
                        $last_index = $index;
                        $same_num = 1;
                    }
                    else
                    {
                        $same_num ++;
                    }
                }
 
                $bmp_data .= "\0\0";
            }
 
            $bmp_data .= "\0\1";
        }
 
        $size_quad = strlen( $rgb_quad );
        $size_data = strlen( $bmp_data );
    }
    else
    {
        // 每行字节数必须为4的倍数,补齐。
        $extra = '';
        $padding = 4 - ( $width * ( $bit / 8 ) ) % 4;
        if ( $padding % 4 != 0 )
        {
            $extra = str_repeat( "\0", $padding );
        }
 
        // 位图数据
        $bmp_data = '';
 
        for ( $j = $height - 1; $j >= 0; $j -- )
        {
            for ( $i = 0; $i < $width; $i ++ )
            {
                $index  = imagecolorat( $im, $i, $j );
                $colors = imagecolorsforindex( $im, $index );
 
                if ( $bit == 16 )
                {
                    $bin = 0 << $bit;
 
                    $bin |= ( $colors['red'] >> 3 ) << 10;
                    $bin |= ( $colors['green'] >> 3 ) << 5;
                    $bin |= $colors['blue'] >> 3;
 
                    $bmp_data .= pack( "v", $bin );
                }
                else
                {
                    $bmp_data .= pack( "c*", $colors['blue'], $colors['green'], $colors['red'] );
                }
 
                // todo: 32bit; 
            }
 
            $bmp_data .= $extra;
        }
 
        $size_quad = 0;
        $size_data = strlen( $bmp_data );
        $colors_num = 0;
    }
 
    // 位图文件头
    $file_header = "BM" . pack( "V3", 54 + $size_quad + $size_data, 0, 54 + $size_quad );
 
    // 位图信息头
    $info_header = pack( "V3v2V*", 0x28, $width, $height, 1, $bit, $compression, $size_data, 0, 0, $colors_num, 0 );
 
    // 写入文件
    if ( $filename != '' )
    {
        $fp = fopen( $filename, "wb" );
 
        fwrite( $fp, $file_header );
        fwrite( $fp, $info_header );
        fwrite( $fp, $rgb_quad );
        fwrite( $fp, $bmp_data );
        fclose( $fp );
 
        return 1;
    }
 
    // 浏览器输出
    header( "Content-Type: image/bmp" );
    echo $file_header . $info_header;
    echo $rgb_quad;
    echo $bmp_data;
 
    return 1;
}

测试demo:

$im = imagecreatefrombmp( 'test.bmp' ); //load bmp image
imagebmp( $im ); //print bmp $im

如果要将bmp转为jpg或png,只需要用imagecreatefrombmp载入bmp,用相关函数输出指定格式图像即可:

imagejpeg( $im ); //print jpeg $im
imagepng( $im ); //print png $im'
<?php
/**
 * 短URL算法
 *
 * @author cnAkill 2011-12-30 12:14
 * @param string $sUrl
 * @param int $iGroup
 * @return string
 **/
function getShortUrl( $sUrl, $iGroup = 0 ) {
 
	$aBase62 = array ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5' , '6', '7', '8', '9' );
 
	$sHex = md5( $sUrl );
	$sHexLen = strlen( $sHex );
	$subHexLen = $sHexLen/8;
	$aOutput = array();
 
	for ( $i = 0; $i < $subHexLen; $i++ ) {
		$subHex = substr( $sHex, $i * 8, 8 );
		$int = 0x3FFFFFFF & ( 1*( '0x' . $subHex ) );
		$out = '';
 
		for ( $j = 0; $j < 6; $j++ ) {
			$val = 0x0000003D & $int;
			$out .= $aBase62[$val];
			$int = $int >> 5;
		}
		$aOutput[] = $out;
	}
 
	return $aOutput[$iGroup];
 
}
 
//data demo
$sUrl = 'http://www.trends.com.cn/column/critics/yfy/2011-12/367552.shtml';
 
//print
print_r( getShortUrl( $sUrl ) ); //vSfGTj

废话:

Zend Studio 在国内的销售价格太贵了。。

所以,只能选择D版。。

Zend Studio 9.0.0 beta官方下载地址(未包含IBM i edition下载)

windows版:http://downloads.zend.com/studio-eclipse/9.0.0/ZendStudio-9.0.0-BETA.msi
linux版(32位):http://downloads.zend.com/studio-eclipse/9.0.0/ZendStudio-9.0.0-BETA-x86.tar.gz
linux版(64位):http://downloads.zend.com/studio-eclipse/9.0.0/ZendStudio-9.0.0-BETA-x86_64.tar.gz
Mac_OS_X的DMG安装格式:http://downloads.zend.com/studio-eclipse/9.0.0/ZendStudio-9.0.0-BETA.dmg

Zend Studio 8 注册码(适用于7.0以上所有版本)
Username: zendstudio.net
Serial Number: 3727234F6095F72034F6095F

Zend Studio 9 注册破解

第一步:如果已经安装过Zend Studio 9.0的,请打开Zend Studio
9.0,在菜单中“help>Unregister”,如果显示是灰的跳过此步退出Zend
Studio。如果显示可以点击的请点击,这时Zend Studio会重启,重启到要求你填注册码时点“QUIT”按钮

第二步:下载com.zend.php.core_9.0.0.201111081531.jar文件,下载成功后复制到你安装Zend Studio 9.0的plugins目录下,覆盖同名文件

第三步:启动Zend Studio 9.0,输入如下注册码License key:

34E606CF10C3E4CF202ABCEAA9B0B7A64DD2C5862A514B944AAAB38E3EB8A5F2CD735A2AB4CF9B952590EFA62BA0AB2B3E5D99C33C55309EE143165AC7F1817D626574615F3B32312F31312F323031313B392E303B3030313B313B3330

注意:没有空格也没有换行

第四步:查看是否注册成功,在菜单中“help>About Zend Studio ”, 显示如下图。过期时间9999年12月31日说明注册破解成功完成。

Zend Studio 9汉化方法

官方在线下载语言包:help->Install new software->add 添加网址
http://download.eclipse.org/technology/babel/update-site/R0.9.0/helios

出现padding…字样,等待个几分钟,看网速度然后选择简体中文(注意在勾选简体中文的时候点一下checkbox框等待一下 有点卡。)

【Python 各个框架工具介绍】

[Web开发框架]
Tornado:推荐,官网:http://www.tornadoweb.org/
Bottle:一般,官网:http://bottlepy.org/docs/dev/
Flask:一般,官网:http://flask.pocoo.org/

相关文档:http://feilong.me/2011/01/talk-about-python-web-framework

[Web模板引擎]
jinja 2: 推荐,速度快,语法易用,官网:http://jinja.pocoo.org/docs/,http://jinja.pocoo.org/
mako:一般,速度看,语法不易用,官网:http://www.makotemplates.org/

相关文档:http://jasongreen.iteye.com/blog/356412

[开发工具]
PyCharm:容易用
PyCharm官网:http://www.jetbrains.com/pycharm/
PyCharm相关:http://developer.51cto.com/art/201104/252810.htm

[后端开发库]
gevent: 异步事件epoll封装 官网:http://www.gevent.org/
boost-python: C++ Boost 的Python封装,官网:http://www.boost.org/doc/libs/1_48_0/libs/python/doc/ 参考:http://www.cnblogs.com/msopengl/archive/2011/08/30/2159336.html、http://edyfox.codecarver.org/html/boost_python.html

Twisted:http://twistedmatrix.com/trac/,Python高性能的网络编程框架
[消息系统]
Beanstalkd:
Beanstalkd官网:http://kr.github.com/beanstalkd/
Beanstalkd PHP客户端:http://beanstalk.sourceforge.net/
Beanstalkd Ruby客户端http://beanstalk.rubyforge.org/
Beanstalkd介绍:http://developer.51cto.com/art/201109/290930.htm

来源:黑夜路人

据jQuery官方博客11月3日的最新消息,jQuery 1.7 正式版已经可以下载使用具体更新如下, 翻译自jquery官方博客:http://blog.jquery.com

 

jQuery CDN (via Media Temple)

Microsoft CDN (Also supports SSL via HTTPS)

Google Ajax API CDN (Also supports SSL via HTTPS)

 

1.7 更新内容

 

API 网站上的 Version 1.7tag 是了解新功能的最佳方式. 以下列出的是1.7中作出较大改变或在文档中尚未提及的内容.

新的API: .on() and .off()

新的 .on() 和 .off() 接口囊括的了所有的事件绑定方式,  更加易于书写

$(elements).on( events [, selector] [, data] , handler );

$(elements).off( [ events ] [, selector] [, handler] );

.on() 和.delegate()非常相似, 将为使用选择器筛选出来的对象绑定事件. 当没有提供selector或selector为null的时候.on()就跟.bind()相似. 有一点需要注意:如果data变量是一个字符串, 则一定要指定selector或将selector设为null,来防止jquery将data变量误解为选择器. 推荐使用object,作为data变量.

 

1.7 以前版本中的事件绑定还可以使用,但推荐在新的项目里使用.on()以适应日后的发展.

 

以下是一些新旧api的使用比较:

$(‘a’).bind(‘click’, myHandler);

$(‘a’).on(‘click’, myHandler);

$(‘form’).bind(‘submit’, { val: 42 }, fn);

$(‘form’).on(‘submit’, { val: 42 }, fn);

$(window).unbind(‘scroll.myPlugin’);

$(window).off(‘scroll.myPlugin’);

$(‘.comment’).delegate(‘a.add’, ‘click’,addNew);

$(‘.comment’).on(‘click’, ‘a.add’, addNew);

$(‘.dialog’).undelegate(‘a’,'click.myDlg’);

$(‘.dialog’).off(‘click.myDlg’, ‘a’);

$(‘a’).live(‘click’, fn);

$(document).on(‘click’, ‘a’, fn);

$(‘a’).die(‘click’);

$(document).off(‘click’, ‘a’);

 

提高了委派事件的性能

 

随 着网页越来越大也越来越封复杂, 事件委派也变得越来越重要. 像Backbone, JavaScriptMVC, 和Sproutcore 框架,用了大量的事件委派. 考虑到这些, jquery 1.7 进行了相应的重构, 使得很多委派事件速度更快, 尤其是一些常用的.

 

为 了优化最的常用的selector形式, 我们从google codesearch 作了调查. 在.live()和.delegate()方法中大约2/3的选择器形式为tag#id.class–使用了一个或多个tag,id,class      在时间被绑定时解析这些简单的选择器, 通过这种方式,在选择器相关的事件分发上,我们甚至可以超越浏览器本地代码.其他更加复杂的选择器我们依然使用Sizzle 引擎, 所有现在的代码都可以继续使用

 

最终 , 关于事件委派的测试报告表明,1.7比1.6.4要快一半以上.

 

在IE6/IE7/IE8中更好地支持HTML5

 

任 何在IE6/7/8中使用过html5标签诸如section都会遇到问题, 因为这些浏览器实际会将标签从document中移除. 在1.7版中, 在诸如.html()的函数帮助下,旧本版IE可以支持HTML5.这种支持和之前的 innerShiv 相似.你还是必须在头部引入 html5shiv (or Modernizr)  更多支持: The Story of the HTML5 Shiv.

 

toggle动画修正

 

在先前的版本中, 当动画相互覆盖并且前一个动画被用.stop()中止后,.slideToggle() or .fadeToggle() 不能正常工作. 在1.7中这个现象被修复, 系统会自动记录元素的初始值,当一toggle动画过早被终止时重新复位元素值.

 

Asynchronous Module Definition (AMD)

 

JQUERY 现在支持 AMD API. 注意jquery1.7本身不是一个script loader;它与 AMD-compliant loaders 比如 RequireJS 或者 curl.js 一起工作时,它就能被动态地加载,已经就绪的事件也可以被loader控制. 现在 AMD-compliant loader 可以通过Google’s 或 Microsoft’s CDN服务器来加载一个未经修改的JQUERY1.7.感谢 James Burke (@jrburke) 提交补丁和测试, 并耐心地等待我们认真处理.

 

jQuery.Deferred

 

1.7使用新的进程句柄和调用句柄的通知函数来扩展jQuery.Deferred 对象. 使其不必响应或拒绝请求就可以通知进程响应.并且, 新的state()方法会返回deferred的当前状态, 对于调试非常有帮助.

 

Deferreds 现在使用 一种新的jQuery.Callbacks 功能来实现,这是一种排列和触发一系列句柄的广义的途径.尽管deferreds 和事件子系统为这种类型的功能,提供一个高级接口, 但是该特性对于插件作者还是相当有用

 

jQuery.isNumeric()

 

在jquery中我们经常需要判断是不是数字, 或者转化后是不是数字. 因为这是将成为一个有用的功能,所以我们决定编写 jQuery.isNumeric(),并提交交了文档 . 传入一个任意的值, 它就会给出true或false.

 

移除功能

 

event.layerX 和 event.layerY: 我们已经移除了没有实际意义的属性. 我们本应当认真起草一份关于废除的最终申明, 但是chrome 16 生成了大量的警告信息.所以我们选择了立即移除它们. 在支持这些属性的平台上 可以用 event.originalEvent.layerX 和 event.originalEvent.layerY来访问.

 

jQuery.isNaN(): 这个尚未加入文档的功能已被废除.这个函数具有歧义, 因为它跟javascript内置的函数同名,但却有着不同的意义. 新版本中的是jQuery.isNumeric()是被正式文档化的, 可以用来作为替代函数. 尽管isNaN()未被文档化, 在github上依然有部分工程在使用.我们已经联系过相关作者,建议他们停止使用,并寻找其他方案

 

jQuery.event.proxy(): 这个尚未加入文档并被废弃功能已被正式删除. 用户应当调用jQuery.proxy()来代替.

第一步:下载PHP的源码;

wget http://www.php.net/get/php-5.2.17.tar.bz2/from/jp.php.net/mirror
tar -xjvf php-5.2.17.tar.bz2

第二步:建立扩展骨架;

cd php-5.2.17/ext/
./ext_skel --extname=test

第三步:修改编译参数;

cd /php-5.2.17/ext/test/
vi config.m4

去掉

PHP_ARG_ENABLE(test, whether to enable test support
[--enable-test Enable test support])

两行前边的dnl;

第四步:编写代码;

vi php_test.h
在 PHP_FUNCTION(confirm_test_compiled); 后
增加:PHP_FUNCTION(test);  
 
vi test.c
在 PHP_FE(confirm_laiwenhui_compiled,NULL) 后
增加:PHP_FE(test,    NULL)

在文件最后增加:

PHP_FUNCTION(test)
{
	char *arg = "This is my first extention test!";
	int  len;
	char *strg;
	len = spprintf(&amp;strg, 0, "%s\n", arg);
	RETURN_STRINGL(strg, len, 0);
}

第五步:编译代码;

cd /php-5.2.17/ext/test/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

最后会生成一个编译后的文件:

/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/test.so

第六步:编辑PHP配置php.ini,并添加扩展;

vi /etc/php.ini

在[PHP]模块下增加:

extension = test.so

将extension_dir修改为:

/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

第七步:检查安装结果

service httpd restart
/usr/local/php/bin/php -m

第八步:执行代码测试

cd /home/wwwroot/default/
vi test.php

输入:

<?php echo test();?>;

执行结果:

This is my first extention test!

参考来源:http://www.laruence.com/2009/04/28/719.html

tar

-c: 建立压缩档案
-x:解压
-t:查看内容
-r:向压缩归档文件末尾追加文件
-u:更新原压缩包中的文件

这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选
的。

-z:有gzip属性的
-j:有bz2属性的
-Z:有compress属性的
-v:显示所有过程
-O:将文件解开到标准输出

下面的参数-f是必须的

-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。

# tar -cf all.tar *.jpg
这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。

# tar -rf all.tar *.gif
这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。

# tar -uf all.tar logo.gif
这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。

# tar -tf all.tar
这条命令是列出all.tar包中所有文件,-t是列出文件的意思

# tar -xf all.tar
这条命令是解出all.tar包中所有文件,-x是解开的意思

压缩

tar –cvf jpg.tar *.jpg //将目录里所有jpg文件打包成tar.jpg

tar –czf jpg.tar.gz *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为

jpg.tar.gz

tar –cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为

jpg.tar.bz2

tar –cZf jpg.tar.Z *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名

为jpg.tar.Z

rar a jpg.rar *.jpg //rar格式的压缩,需要先下载rar for linux

zip jpg.zip *.jpg //zip格式的压缩,需要先下载zip for linux

解压

tar –xvf file.tar //解压 tar包

tar -xzvf file.tar.gz //解压tar.gz

tar -xjvf file.tar.bz2 //解压 tar.bz2

tar –xZvf file.tar.Z //解压tar.Z

unrar e file.rar //解压rar

unzip file.zip //解压zip

总结

1、*.tar 用 tar –xvf 解压

2、*.gz 用 gzip -d或者gunzip 解压

3、*.tar.gz和*.tgz 用 tar –xzf 解压

4、*.bz2 用 bzip2 -d或者用bunzip2 解压

5、*.tar.bz2用tar –xjf 解压

6、*.Z 用 uncompress 解压

7、*.tar.Z 用tar –xZf 解压

8、*.rar 用 unrar e解压

9、*.zip 用 unzip 解压

<?php
/**
 * 快速排序算法
 *
 * @author cnAkill 2011-11-1 13:11
 * @param array $aData
 * @return array
 **/
 
function quickSort( $aData )
{
    $iDataCount = count( $aData );
 
    if( $iDataCount <= 1 )
    {
        return $aData;
    }
 
    $iKey       = $aData[0];
    $aLeftData  = array();
    $aRightData = array();
 
    for ( $i = 1; $i < $iDataCount; $i++ )
    {
        if ( $aData[$i] <= $iKey )
        {
            $aLeftData[]  = $aData[$i];
        }
        else
        {
            $aRightData[] = $aData[$i];
        }
    }
 
    $aLeftData  = quickSort( $aLeftData );
    $aRightData = quickSort( $aRightData );
 
    return array_merge( $aLeftData, array($iKey), $aRightData );
}
 
//test data
for( $i=0; $i < 10; $i++ )
{
    $aData[] = rand( 0, 10 );
}
 
$aStr = '';
for ($i = 0; $i < 90; $i++) {
    $aStr.= '-';
}
$aStr = '<br>'.$aStr.'<br>';
 
//print
debug_zval_dump( quickSort( $aData ) );
echo $aStr;
 
var_export( quickSort( $aData ) );
echo $aStr;
 
var_dump( quickSort( $aData ) );
 
?>
<?php
/**
 * 二分搜索算法
 *
 * @author cnAkill 2011-11-1 14:58
 * @param array $aData
 * @param int $iMinKey
 * @param int #iMaxKey
 * @param int $iValue
 * @return boolean
 **/
 
function binarySearch( $aData, $iMinKey, $iMaxKey, $iValue )
{
    if ( $iMinKey <= $iMaxKey ) {
        $iKey = intval( ($iMinKey+$iMaxKey)/2 );
        if ( $aData[$iKey] == $iValue ) {
            return true;
        }
        elseif ( $iValue < $aData[$iKey] )
        {
            return binarySearch( $aData, $iMinKey, $iKey-1, $iValue );
        }
        else
        {
            return binarySearch( $aData, $iKey+1, $iMaxKey, $iValue );
        }
    }
    else
    {
        return false;
    }
}
 
//test data
for ( $i = 0; $i < 100000; $i++ ) {
     $aData[] = rand( 0, 100 );
}
$iValue  = 100;
$iMinKey = min( array_keys( $aData ) );
$iMaxKey = max( array_keys( $aData ) );
 
//print
var_dump( binarySearch( $aData, $iMinKey, $iMaxKey, $iValue ) );
?>