网络选中国男人压力最大10城市 上海娶妻难居首

作者:Lightning@小宝 发布时间:December 29, 2009 分类:生活 & 职场

网络评选出的中国男人压力最大的10大城市
  恐怕没有哪个地方的男人能像城里的男人那样承受的更多,虽然也有人悠闲,但大多数男人都在各种压力下一点一点的企图更靠近城市的中心。在城市生长和扩张的兴奋中,早已掩埋了许多男人的汗水、泪水。
  1.上海——娶老婆难
  无论是上海本地人强烈的排外情绪,还是日益高涨的购房压力,足以让男人们在这个全国最大的经济中心佝偻着的背更加弯曲。
  2.北京——贫富差距
  本地人和一批高官高干、高技术人才稳稳的占据着这个城市的中心地带,艺人、明星、企业家把持着有山有水的黄金郊区,只有一小撮环线区域被奇高的房价给分成了三类九等。
  3.广州——漂泊感
  生活在这个城市的男人,60%怀着一个目的:赚了钱回家。
  4.深圳——脆弱的爱情+疯涨的房价
  这个外来人口占据一半以上的开放城市女多男少,但是对于男人来说,空虚和压力或许才是他们最好的朋友。因为4、5万一平米的房价足以让爱情变得脆弱不堪。
  5.重庆——盛产美女,但大都外销
  在这个城市的男人,工资不算高,房价却也不低,美女不少,但看上你的却没有几个。
  6.武汉——人才太多
  理工科男人云集,这就造成一种男女比例的严重失衡。
  7.天津——买不起房+生理健康
  天津旧城区污染严重,在忍受各种煎熬时还不能有效保护自己的健康。
  8.香港——各种压力
  9.台湾——面子+政治压力
  台湾男人压力不是来自于房价和赚不到钱,而是怕自己考不上好大学,找不到好职业,怕被人瞧不起。
  10.长沙——在家玩死pk外出累死=两难
  这个被称为娱乐之城的地方,住房面积和房价是除了娱乐之外最被男人们重视的问题。他们还不得不同样面临尴尬,因为长沙的工资水平不是很高,他们不得不在老死家乡和背井离乡中作出艰难的抉择。整理/记者王欢

AS3写的各种有用的类库,让你开发更简单

作者:Lightning@小宝 发布时间:December 16, 2009 分类:ActionScript3&Flex学习

1、as3ebaylib
http://code.google.com/p/as3ebaylib/

2、as3youtubelib
http://code.google.com/p/as3youtubelib/

3、as3flickrlib
http://code.google.com/p/as3flickrlib/

4、Yahoo ASTRA Flash Components
http://developer.yahoo.com/flash/astra-flash/

5、facebook-as3
http://code.google.com/p/facebook-as3/

6、as3awss3lib
http://code.google.com/p/as3awss3lib/

7、Adobe ActionScript 3:resources:apis:libraries (官方,包括corelib、FlexUnit、Flickr、Mappr、RSS and Atom libraries、Odeo、YouTube)
http://labs.adobe.com/wiki/index … rces:apis:libraries

8、Tweener 用于过渡与切换的一组动画库
http://code.google.com/p/tweener/

9、uicomponents-as3 一组轻量级的AS3 UI组件库
http://code.google.com/p/uicomponents-as3/

10、as3ds AS3的数据结构实现
http://code.google.com/p/as3ds/

11、mecheye-as3-libraries 一组主要用于Flash 游戏开发的AS3库
http://code.google.com/p/mecheye-as3-libraries/

12、XIFF 一套XMPP协议的AS3实现
http://svn.igniterealtime.org/sv … _as3_flexlib_beta1/

13、FZip 一套AS3库,可用作对ZIP压缩文件的载入、修改与创建
http://codeazur.com.br/lab/fzip/

14、FlexLib 一套开源的Flex界面组件库
http://code.google.com/p/flexlib/

15、AnimatedGIfLoader Flex Component 可载入GIF的Flex组件
http://dougmccune.com/blog/animatedgifloader-flex-component/

16、goplayground 一套轻量级的,可用创建属于你自己的AS3 动画工具的库
http://code.google.com/p/goplayground/

17、AlivePDF 开源的用于PDF创建的AS3库
http://www.alivepdf.org/

18、jwopitz-lib 一组开源的Flex用户界面组件
http://code.google.com/p/jwopitz-lib/

19、as3crypto AS3实现的一套加密库,包括多种加密算法
http://code.google.com/p/as3crypto/

20、flare 一套强大的可视化交互的AS3类库
http://flare.prefuse.org/

21、SWFAddress 一小而强大的库,可以为Flash和Ajax提供深链接的功能
http://www.asual.com/swfaddress/

22、SWFObject 用于嵌入Flash,Adobe官方也认可了
http://code.google.com/p/swfobject/

23、ulse Particle System 一套开源的强大的AS3动态粒子系统
http://code.google.com/p/pulse-particle/
http://www.rogue-development.com/pulseParticles.html

24、SpringGraph Flex Component
http://mark-shepherd.com/blog/springgraph-flex-component/

25、GoASAP AS3动画库
http://code.google.com/p/goasap/
http://www.goasap.org/index.html

26、asaplibrary 一套开源的Flash Actionscript3.0 RIA库
http://code.google.com/p/asaplibrary/
http://asaplibrary.org/
http://asapframework.org

27、as3mathlib 开源Flex/Actionscript数学库
http://code.google.com/p/as3mathlib/

28、as3corelib 包含一些基础功能AS3库
http://code.google.com/p/as3corelib/

29、minimalcomps 一组AS3 UI组件
http://www.bit-101.com/minimalcomps/

30、as3gif
http://code.google.com/p/as3gif/

31、queueloader-as3 一组AS3库,用来进行资源序列载入及监测
http://code.google.com/p/queueloader-as3/

32、TweenMax (AS3)
http://blog.greensock.com/tweenmaxas3/

33、Atellis Reflection Component 一款Flex反射效果组件
http://labs.atellis.com/2007/07/11/atellis-reflection-component/

34、AS3Eval 简单来说,就是用AS3实现的AS3编译器
http://eval.hurlant.com/

35、ByteArray的组件、库合集,包括liquid components、mousegesture、ASZip、GIF Player、GIF Animation Encoder、AlivePDF、Live JPEG Encoder、ScaleBitmap等
http://www.bytearray.org/?page_id=82

36、AS3C 针对AVM2虚拟机,用C#写的字节码编译器
http://code.google.com/p/as3c/

37、as3httpclientlib as3实现的http客户端
http://code.google.com/p/as3httpclientlib/

38、as3ui 一组常规的as3 ui界面库
http://code.google.com/p/as3ui/

39、as3xls 让你在flex中可以读写Excel文件
http://code.google.com/p/as3xls/

40、as3flexdb 让你的flex程序可以连接到MySQL服务器,主要是使用AMFPHP来访问PHP服务器
http://code.google.com/p/as3flexdb/
这一是一篇详细使用介绍的教程
http://itutorials.ro/viewtopic.php?f=9&t=7

41、vivisectingmedia-as3  一组AS3/Flex实用库,是作者在实践中总结出来的
http://code.google.com/p/vivisectingmedia-as3/

Actionscript 3.0 Class

1、fZip 此类可允许你载入标准的zip文件并提取里面包含的文件
http://wahlers.com.br/claus/blog/zip-it-up/

2、AS3: Layout class for Flash CS3 一组用作布局的类
http://www.senocular.com/?id=2.8

3、CSSLoader 该类允许Flex应用程序在运行时载入CSS
http://www.rubenswieringa.com/blog/cssloader

4、AS3: QueryString 一个单例类,用来获取URL地址后所带参数值对
http://evolve.reintroducing.com/ … erystring/#more-141

5、ActionScript 3 Contextual Menu Manager Class AS3关联菜单管理类
http://www.blog.noponies.com/archives/103

2D & 3D Engine

1、APE (Actionscript Physics Engine) 物理引擎
APE前身是as2版本的Flade,呼声很高,优点就是清晰简单,一共没有几个类:),目前版本alpha 0.45 ,有API文档和示例,教程有一篇quick start ,在Google Group上有一个论坛可以讨论。svn上一直在更新目前svn上的版本为0.5a

http://www.cove.org/ape/

2、Away3D
http://code.google.com/p/away3d/

3、Papervision3D
http://code.google.com/p/papervision3d/

4、Sandy 开源3D库
http://www.flashsandy.org/versions/3.0

5、FORM 一套AS3完成的用于2D刚性物体的物理引擎
http://code.google.com/p/foam-as3/

6、Five3D 基于矢量的Flash 3D 交互动画创建
http://five3d.mathieu-badimon.com/

7、Flade (Flash Dynamics Engine) 一套开源的2D物理引擎,AS2实现
http://www.cove.org/flade/

8、Box2DFlashAS3 2D物理引擎,AS3实现,基于强大的Box2D C++物理库
http://box2dflash.sourceforge.net/

9、Paradox 基于Flash的第一称3D引擎
http://animasinteractive.com/propaganda/

10、ND3D AS3 3D Engine  一款简单的AS3开源3D引擎,编译后的引擎大小仅约10K
http://code.google.com/p/nd3d/
http://www.nulldesign.de/nd3d-as3-3d-engine/

11、motor2 基于Box2d的AS3刚体引擎,也是2D的.
作者就是 AS3数据结构的作者,2007年最后一天发布
作者主页:http://lab.polygonal.de/motor_physics/
代码:http://code.google.com/p/motor2/

12、WOW-Engine 法国人写的,基于Sandy library的算法 3D物理引擎
http://seraf.mediabox.fr/wow-eng … -engine-wow-engine/

FrameWorks

1、Cairngorm Adobe官方出的Flex框架
http://labs.adobe.com/wiki/index.php/Cairngorm

2、PureMVC 纯AS3框架,也有其它语言的实现
http://www.puremvc.org/

3、ASWing AS3 一套开源的AS3 GUI框架
http://www.aswing.org/

4、EasyMVC 由事件驱动的MVC框架
http://projects.simb.net/easyMVC/

5、Mate 基于Tag及事件驱动的Flex框架
http://mate.asfusion.com/

6、ARP 基于模式(Pattern)的RIA框架,Flash平台,支持AS2和AS3
http://osflash.org/projects/arp

7、Gaia 开源的Flash前端框架,支持AS2和AS3,用于快速开发
http://www.gaiaflashframework.com/

8、flest Actionscript3.0/Flex应用程序框架,用来开发企业级的RIA
http://code.google.com/p/flest/

9、Gugga Flash Framework 更新至AS3
http://www.gugga.com/flashblog/

10、Prana 另一个提供了IOC反转控制的框架,类似著名的Spring框架
http://www.pranaframework.org/

11、OpenFlux 开源的Flex组件框架,让开发Flex组件更加快速容易
http://code.google.com/p/openflux/

12、Degraf a 声明式的Flex图形框架,允许以MXML标签的方式绘制图形、创建皮肤,还包括对CSS的支持
http://code.google.com/p/degraf a/
(不良信息过滤问题,请自行删除Degraf a中间的空格)

13、FlexMVCs 针对AS3和Flex的应用程序框架,基于PureMVC,作了些修正和精简
http://code.google.com/p/flexmvcs/

Flash & Flex Tools、Servers

1、FlexUnit Flex/Actionscript3.0单元测试框架
http://code.google.com/p/as3flexunitlib/

2、Visual FlexUnit 增强的FlexUnit,支持“可视化断言”
http://code.google.com/p/visualflexunit/

3、RED bug debug调试控制器,让Flash、Flex、AIR应用程序更加容易
http://www.realeyesmedia.com/redbug/

4、reflexutil 可在运行时对Flex组件进行调试
http://code.google.com/p/reflexutil/

5、FxSpy 当Flex应用程序运行时可以检测和动态的改变可视化组件属性值
http://code.google.com/p/fxspy/

6、ThunderBolt 基于Firefox的Firebug插件的日志扩展,支持AS2及AS3
http://code.google.com/p/flash-thunderbolt/

7、FlashTracer Firefox扩展,可以以侧栏的方式将Flash中trace()的结果显示

8、RIALogger 另一款Flex/AIR的Debug工具
http://renaun.com/blog/flex-components/rialogger/

9、Alcon 一款轻量级的AS2及AS3的Debug工具,AIR方式将Debug信息展示出来
http://blog.hexagonstar.com/alcon/

10、GDS (Granite Data Services) 开源,提供了Adobe LiveCycle Data Services类似功能的服务器
http://www.graniteds.org/

Flex Explorers (大部分为Flex2版本,但同样适用于Flex3)

1、Flex3 Component Explorer Flex各类组件示例
http://examples.adobe.com/flex3/componentexplorer/explorer.html

2、Resize ManagerFX Explorer (此为商业作品,要收费的)
http://www.teotigraphix.com/expl … agerFXExplorer.html

3、Flex3 Style Explorer
http://examples.adobe.com/flex3/ … 3StyleExplorer.html

4、Flex2 Style Explorer(添加了Kuler功能)Flex UI组件风格定制并可输出为CSS
http://www.maclema.com/content/sek/

5、Flex2 Style Explorer(Adobe 原始的版本)
http://examples.adobe.com/flex2/ … 2StyleExplorer.html

6、Flex2 Filter Explorer 查看各类滤镜效果并可进行设置
http://merhl.com/flex2_samples/filterExplorer/
http://merhl.com/?p=40 (AIR版本)

7、Flex2 Primitive Explorer 在Flex中创建各种简单形状
http://www.flexibleexperiments.c … mitiveExplorer.html

php性能与技巧总结一

作者:Lightning@小宝 发布时间:December 11, 2009 分类:php经验技巧

<?php
error_reporting(E_ALL);
$_beforeMemory = memory_get_usage();
function testFunc($aa){
    return $aa;
}

$_startTime = microtime(1);
for ($i=0; $i<10000; $i++) 
{
    $a = 'aaaaaaaaaaaaaaa';
    testFunc($a);
}

$_breakpointTime_1 = microtime(1);
echo '变量传递所用Time: ', round($_breakpointTime_1 - $_startTime, 7)." s", "\n";
echo '内存使用量: ', ($_breakpointMemory_1 = memory_get_usage()) - $_beforeMemory, 
    " bytes", "\n";
for ($i=0; $i<10000; $i++) {
    testFunc('aaaaaaaaaaaaaaa');
}

echo '变量传递所用Time: ', round(microtime(1) - $_breakpointTime_1, 7)." s", "\n";
echo '内存使用量: ', memory_get_usage() - $_breakpointMemory_1, " bytes", "\n";

/*
这只是个大概值,但已经能得到想要的测试结果。
Results:
    变量传递所用Time: 0.3503728 s
    内存使用量: 832 bytes
    变量传递所用Time: 0.2680891 s
    内存使用量: 136 bytes

*/
?>

Fastcgi的简易实现[Python版本]备忘录

作者:Lightning@小宝 发布时间:December 10, 2009 分类:Python/Java/Erlang学习

python代码实现简易的fastcgi请求

#!/usr/bin/env python

import os
import sys
import select
import string
import socket
import errno
import cgi
import thread
from cStringIO import StringIO
import struct

# Maximum number of requests that can be handled
FCGI_MAX_REQS = 50
FCGI_MAX_CONNS = 50
FCGI_VERSION_1 = 1
# Can this application multiplex connections?
FCGI_MPXS_CONNS = 0

# Record types
FCGI_BEGIN_REQUEST = 1
FCGI_ABORT_REQUEST = 2
FCGI_END_REQUEST = 3
FCGI_PARAMS = 4
FCGI_STDIN = 5
FCGI_STDOUT = 6
FCGI_STDERR = 7
FCGI_DATA = 8
FCGI_GET_VALUES = 9
FCGI_GET_VALUES_RESULT = 10
FCGI_UNKNOWN_TYPE = 11
FCGI_MAXTYPE = FCGI_UNKNOWN_TYPE

# Types of management records
KNOWN_MANAGEMENT_TYPES = [FCGI_GET_VALUES]

FCGI_NULL_REQUEST_ID = 0

# Masks for flags component of FCGI_BEGIN_REQUEST
FCGI_KEEP_CONN = 1

# Values for role component of FCGI_BEGIN_REQUEST
FCGI_RESPONDER = 1
FCGI_AUTHORIZER = 2
FCGI_FILTER = 3

# Values for protocolStatus component of FCGI_END_REQUEST
FCGI_REQUEST_COMPLETE = 0     # Request completed ok
FCGI_CANT_MPX_CONN = 1        # This app cannot multiplex
FCGI_OVERLOADED = 2           # Too busy
FCGI_UNKNOWN_ROLE = 3         # Role value not known

# Struct format types
FCGI_BeginRequestBody = "!HB5x"
FCGI_Record_header = "!BBHHBx"
FCGI_UnknownTypeBody = "!B7x"
FCGI_EndRequestBody = "!IB3x"

class Record:
    """Class representing FastCGI records"""
    def __init__(self):
        self.version = FCGI_VERSION_1
        self.rec_type = FCGI_UNKNOWN_TYPE
        self.req_id   = FCGI_NULL_REQUEST_ID
        self.content = ""

        # Only in FCGI_BEGIN_REQUEST
        self.role = None
        self.flags = None
        self.keep_conn = 0

        # Only in FCGI_UNKNOWN_TYPE
        self.unknownType = None

        # Only in FCGI_END_REQUEST
        self.appStatus = None
        self.protocolStatus = None

    def read_pair(self, data, pos):
        namelen = struct.unpack("!B", data[pos])[0]
        if namelen & 128:
            # 4-byte name length
            namelen = struct.unpack("!I", data[pos:pos+4])[0] & 0x7fffffff
            pos += 4
        else:
            pos += 1

        valuelen = struct.unpack("!B", data[pos])[0]
        if valuelen & 128:
            # 4-byte value length
            valuelen = struct.unpack("!I", data[pos:pos+4])[0] & 0x7fffffff
            pos += 4
        else:
            pos += 1

        name = data[pos:pos+namelen]
        pos += namelen
        value = data[pos:pos+valuelen]
        pos += valuelen

        return (name, value, pos)

    def write_pair(self, name, value):
        namelen = len(name)
        if namelen < 128:
            data = struct.pack("!B", namelen)
        else:
            # 4-byte name length
            data = struct.pack("!I", namelen | 0x80000000L)

        valuelen = len(value)
        if valuelen < 128:
            data += struct.pack("!B", value)
        else:
            # 4-byte value length
            data += struct.pack("!I", value | 0x80000000L)

        return data + name + value
        
    def readRecord(self, sock):
        data = sock.recv(8)
        if not data:
            # No data recieved. This means EOF. 
            return None
        
        fields = struct.unpack(FCGI_Record_header, data)
        (self.version, self.rec_type, self.req_id,
         contentLength, paddingLength) = fields
        
        self.content = ""
        while len(self.content) < contentLength:
            data = sock.recv(contentLength - len(self.content))
            self.content = self.content + data
        if paddingLength != 0:
            sock.recv(paddingLength)
        
        # Parse the content information
        if self.rec_type == FCGI_BEGIN_REQUEST:
            (self.role, self.flags) = struct.unpack(FCGI_BeginRequestBody,
                                                    self.content)
            self.keep_conn = self.flags & FCGI_KEEP_CONN

        elif self.rec_type == FCGI_UNKNOWN_TYPE:
            self.unknownType = struct.unpack(FCGI_UnknownTypeBody, self.content)

        elif self.rec_type == FCGI_GET_VALUES or self.rec_type == FCGI_PARAMS:
            self.values = {}
            pos = 0
            while pos < len(self.content):
                name, value, pos = self.read_pair(self.content, pos)
                self.values[name] = value
        elif self.rec_type == FCGI_END_REQUEST:
            (self.appStatus,
             self.protocolStatus) = struct.unpack(FCGI_EndRequestBody,
                                                  self.content)

        return 1

    def writeRecord(self, sock):
        content = self.content
        if self.rec_type == FCGI_BEGIN_REQUEST:
            content = struct.pack(FCGI_BeginRequestBody, self.role, self.flags)

        elif self.rec_type == FCGI_UNKNOWN_TYPE:
            content = struct.pack(FCGI_UnknownTypeBody, self.unknownType)

        elif self.rec_type == FCGI_GET_VALUES or self.rec_type == FCGI_PARAMS:
            content = ""
            for i in self.values.keys():
                content = content + self.write_pair(i, self.values[i])

        elif self.rec_type == FCGI_END_REQUEST:
            content = struct.pack(FCGI_EndRequestBody, self.appStatus,
                                  self.protocolStatus)

        # Align to 8-byte boundary
        clen = len(content)
        padlen = ((clen + 7) & 0xfff8) - clen
        
        hdr = struct.pack(FCGI_Record_header, self.version, self.rec_type,
                          self.req_id, clen, padlen)
        
        try:
            sock.sendall(hdr + content + padlen*"\x00")
        except socket.error:
            # Write error, probably broken pipe. Exit thread. 
            thread.exit()


class Request:
    """A request, corresponding to an accept():ed connection and
    a FCGI request. 
    """
    def __init__(self, conn, req_handler):
        self.conn = conn
        self.req_handler = req_handler
        
        self.keep_conn = 0
        self.req_id = None

        # Input
        self.env = {}
        self.env_complete = 0
        self.stdin = StringIO()
        self.stdin_complete = 0
        self.data = StringIO()
        self.data_complete = 0

        # Output
        self.out = StringIO()
        self.err = StringIO()

        self.have_finished = 0

    def run(self):
        while 1:
            if self.conn.fileno() < 1:
                # Connection lost
                return

            select.select([self.conn], [], [])
            rec = Record()
            if rec.readRecord(self.conn):
                self._handle_record(rec)
            else:
                # EOF, connection closed. Break loop, end thread. 
                return
                
    def getFieldStorage(self):
        self.stdin.reset()
        return cgi.FieldStorage(fp=self.stdin, environ=self.env,
                                keep_blank_values=1)

    def _flush(self, stream):
        stream.reset()

        rec = Record()
        rec.rec_type = FCGI_STDOUT
        rec.req_id = self.req_id
        data = stream.read()

        if not data:
            # Writing zero bytes would mean stream termination
            return
        
        while data:
            chunk, data = self.getNextChunk(data)
            rec.content = chunk
            rec.writeRecord(self.conn)
        # Truncate
        stream.reset()
        stream.truncate()

    def flush_out(self):
        self._flush(self.out)

    def flush_err(self):
        self._flush(self.err)

    def finish(self, status=0):
        if self.have_finished:
            return

        self.have_finished = 1

        # stderr
        self.err.reset()
        rec = Record()
        rec.rec_type = FCGI_STDERR
        rec.req_id = self.req_id
        data = self.err.read()
        while data:
            chunk, data = self.getNextChunk(data)
            rec.content = chunk
            rec.writeRecord(self.conn)
        rec.content = ""
        rec.writeRecord(self.conn)      # Terminate stream

        # stdout
        self.out.reset()
        rec = Record()
        rec.rec_type = FCGI_STDOUT
        rec.req_id = self.req_id
        data = self.out.read()
        while data:
            chunk, data = self.getNextChunk(data)
            rec.content = chunk
            rec.writeRecord(self.conn)
        rec.content = ""
        rec.writeRecord(self.conn)      # Terminate stream

        # end request
        rec = Record()
        rec.rec_type = FCGI_END_REQUEST
        rec.req_id = self.req_id
        rec.appStatus = status
        rec.protocolStatus = FCGI_REQUEST_COMPLETE
        rec.writeRecord(self.conn)
        if not self.keep_conn:
            self.conn.close()
            thread.exit()
    
    #
    # Record handlers
    #
    def _handle_record(self, rec):
        """Handle record"""
        if rec.req_id == FCGI_NULL_REQUEST_ID:
            # Management record            
            self._handle_man_record(rec)
        else:
            # Application record
            self._handle_app_record(rec)

    def _handle_man_record(self, rec):
        """Handle management record"""
        rec_type = rec.rec_type
        if rec_type in KNOWN_MANAGEMENT_TYPES:
            self._handle_known_man_types(rec)
        else:
            # It's a management record of an unknown
            # type. Signal the error.
            rec = Record()
            rec.rec_type = FCGI_UNKNOWN_TYPE
            rec.unknownType = rec_type
            rec.writeRecord(self.conn)

    def _handle_known_man_types(self, rec):
        if rec.rec_type == FCGI_GET_VALUES:
            reply_rec = Record()
            reply_rec.rec_type = FCGI_GET_VALUES_RESULT

            params = {'FCGI_MAX_CONNS' : FCGI_MAX_CONNS,
                      'FCGI_MAX_REQS' : FCGI_MAX_REQS,
                      'FCGI_MPXS_CONNS' : FCGI_MPXS_CONNS}

            for name in rec.values.keys():
                if params.has_key(name):
                    # We known this value, include in reply
                    reply_rec.values[name] = params[name]

            rec.writeRecord(self.conn)

    def _handle_app_record(self, rec):
        if rec.rec_type == FCGI_BEGIN_REQUEST:
            # Discrete
            self._handle_begin_request(rec)
            return
        elif rec.req_id != self.req_id:
            #print >> sys.stderr, "Recieved unknown request ID", rec.req_id
            # Ignore requests that aren't active
            return
        if rec.rec_type == FCGI_ABORT_REQUEST:
            # Discrete
            rec.rec_type = FCGI_END_REQUEST
            rec.protocolStatus = FCGI_REQUEST_COMPLETE
            rec.appStatus = 0
            rec.writeRecord(self.conn)
            return
        elif rec.rec_type == FCGI_PARAMS:
            # Stream
            self._handle_params(rec)
        elif rec.rec_type == FCGI_STDIN:
            # Stream
            self._handle_stdin(rec)
        elif rec.rec_type == FCGI_DATA:
            # Stream
            self._handle_data(rec)
        else:
            # Should never happen. 
            #print >> sys.stderr, "Recieved unknown FCGI record type", rec.rec_type
            pass

        if self.env_complete and self.stdin_complete:
            # Call application request handler. 
            # The arguments sent to the request handler is:
            # self: us. 
            # req: The request.
            # env: The request environment
            # form: FieldStorage.
            self.req_handler(self, self.env, self.getFieldStorage())

    def _handle_begin_request(self, rec):
        if rec.role != FCGI_RESPONDER:
            # Unknown role, signal error.
            rec.rec_type = FCGI_END_REQUEST
            rec.appStatus = 0
            rec.protocolStatus = FCGI_UNKNOWN_ROLE
            rec.writeRecord(self.conn)
            return

        self.req_id = rec.req_id
        self.keep_conn = rec.keep_conn
        
    def _handle_params(self, rec):
        if self.env_complete:
            # Should not happen
            #print >> sys.stderr, "Recieved FCGI_PARAMS more than once"
            return
        
        if not rec.content:
            self.env_complete = 1

        # Add all vars to our environment
        self.env.update(rec.values)

    def _handle_stdin(self, rec):
        if self.stdin_complete:
            # Should not happen
            #print >> sys.stderr, "Recieved FCGI_STDIN more than once"
            return
        
        if not rec.content:
            self.stdin_complete = 1

        self.stdin.write(rec.content)

    def _handle_data(self, rec):
        if self.data_complete:
            # Should not happen
            #print >> sys.stderr, "Recieved FCGI_DATA more than once"
            return

        if not rec.content:
            self.data_complete = 1
        
        self.data.write(rec.content)

    def getNextChunk(self, data):
        chunk = data[:8192]
        data = data[8192:]
        return chunk, data


class THFCGI:
    def __init__(self, req_handler, fd=sys.stdin):
        self.req_handler = req_handler
        self.fd = fd
        self._make_socket()

    def run(self):
        """Wait & serve. Calls request handler in new
        thread on every request.
        """
        self.sock.listen(5)
        
        while 1:
            (conn, addr) = self.sock.accept()
            thread.start_new_thread(self.accept_handler, (conn, addr))

    def accept_handler(self, conn, addr):
        self._check_good_addrs(addr)
        req = Request(conn, self.req_handler)
        req.run()

    def _make_socket(self):
        """Create socket and verify FCGI environment"""
        try:
            s = socket.fromfd(self.fd.fileno(), socket.AF_INET,
                              socket.SOCK_STREAM)
            s.getpeername()
        except socket.error, (err, errmsg):
            if err != errno.ENOTCONN: 
                raise "No FastCGI environment"

        self.sock = s
        
    def _check_good_addrs(self, addr):
        # Apaches mod_fastcgi seems not to use FCGI_WEB_SERVER_ADDRS. 
        if os.environ.has_key('FCGI_WEB_SERVER_ADDRS'):
            good_addrs = string.split(os.environ['FCGI_WEB_SERVER_ADDRS'], ',')
            good_addrs = map(string.strip, good_addrs) # Remove whitespace
        else:
            good_addrs = None
        
        # Check if the connection is from a legal address
        if good_addrs != None and addr not in good_addrs:
            raise "Connection from invalid server!"

要学会淡定!

作者:Lightning@小宝 发布时间:December 9, 2009 分类:生活 & 职场

淡定是一种境界,是人生应该追求的一种生活和理想的境界。
    生活在这个世界中,总有太多的抱怨,太多的不平衡,太多的不满足,当你不抱怨了可能也该闭上眼睛了。每个人犹如一个被宠坏的公主,总是向生活不断索取着。越是拥有,越是担心失去。生活中的很多东西一旦失去,便不容我们找寻。有时幸福就像手心里的沙,握得越紧,失去得越快。有时幸福就像隔岸的花朵,隐约可见,却无法触摸。淡定了生活,就不会那么戾气、躁动了,凡事都能追求个心平气和了。事儿在心平气和中进行了,还能有什么不能解决的了呢?淡定了名利,就不必急急行走在江湖场上,不必再为名为利攻于心计了,不必为名利奔波劳碌了。淡定,并不等同于不思进取,不等同于堕落享乐!淡定的人,依然可以有自己的努力目标,依然可以为自己的目标而不停努力。但淡定的人,不需再为金钱而疲于奔命。淡定的人,可以在自己劳累的时候劝解自己,停下来歇会儿。淡定的人,在失利的时候,便可做到平心静气。所以,做一个淡定的人甚好!
   俗话说的好:不能让钱财累了身,不能让智慧累了心。何尝不是一种追求淡定的人生态度。
   最近的生活状态确实需要好好让自己冷却下来,让自己的心灵能够学会淡定,学会从容与豁达,学会凡事都能看开点,学会快乐的生活。
   想的太多,活的太累,只会成为前进的包袱,背着过重包袱的人肯定无法登的高,走的远,行的快。学会为自己减压,学会让自己轻装上阵。
   积极的工作,快乐的生活。

--------------------------------------------------------------------------

淡定是一种境界,是一种超然世外的意识。只有修养达到一定阶段,才能产生并拥有。拥有了淡定,就拥有了风度。于是淡定便成了一种气质,让我辈无论如何努力和奋斗,始终难望其项背。
淡定要有海纳百川有容乃大的胸怀,也要有壁立千仞无欲则刚的度 量,更要有沉着冷静泰然自若的应变能力。
     淡定首先是豁达。豁达首先是思想通达,想通了,才豁达。这就需要讲道理而不认死理。小道理服从大道理,软道理服从硬道理,旧道理服从新道理。坚持对的放弃错的校正过的创造新的。从教条主义经验主义以及传统观念和习惯思维的桎梧中走出去。豁达也是伦理的通达。少私心,才通达。这就需要树立正确的人生观价值观名利关,履行社会责任和法律义务。知荣辱,重诚信,保操守。从拜金主义享乐主义极端个人主义的囚笼中走出去。豁达需要顾全大局健全人格。潘岳《西征赋》说:“观夫汉高之兴也,非徒聪明神武,豁达大度而已也”。黄元吉《流行马》有句:“大度豁达义深,决胜千里辨输赢”。事业成败,关键在人。成事之人,重在容人。一切豁达之士,都以辽阔视野天下胸怀和恢宏气度看待一切。心胸如海托起百舸争流千帆竞发......
    淡定是一种真,更是一种善;淡定是一种美,更是一种崇高;淡定是一种成熟,更是一种升华;淡定是一种形象显现,更是一种身心和谐。淡定需要时间和实践的积淀和净化,是一种拨云见日,是一种豁然开朗!
    君子坦荡荡,小人长戚戚。愿我们除了自卑多了自由,少了忙乱多了从容,去了怨恨多了温煦,戒了偏激多了沉着。一切在淡定中发展,在淡定中凯旋。

  1. 页码:
  2. 1
我要报警