Archive for 04月, 2009

Ruby:Timezone synchronization function(跨时区同步时间方法)

Apr 30 2009 Published by Tony under Ruby

方法是:首先取得客户端的时区,之后得到服务器的本地时区,之后取得两个时区的差值,计算出相应的时间。
输入:服务器时间
输出:相应的客户端对应的时间
上代码:

#时间同步方法
  #clint_timezone:client timezone
  def formate_date_to_client_time_zone(clint_timezone,time)
    diff=(clint_timezone-get_server_time_zone)
    unless(clint_timezone.nil?)
      time=time+diff*3600
    end
    return time
  end
  #获得本地时区
  #return the server timezone
  def get_server_time_zone
    return Time.now.gmtoff/3600
  end

No responses yet

Ruby:string to date Or date to string

Apr 29 2009 Published by Tony under Ruby

Ruby:string to date Or date to string

#string to date
str="2009-02-02"
date=Date.strptime(str,"%Y-%m-%d")
#date to string:<br />date=Date.new(2009,2,2)
str=date.strftime("%Y-%m-%d")

No responses yet

超炫的flex特效,UI做到这份上,应该说无敌了。

Apr 28 2009 Published by Tony under Flex

Efflex 是一组由 Stephen Downs (aka “Tink”)开发的 Flex特效。
留个纪念,慢慢看
这里是demo

No responses yet

正则表达式验证邮箱地址

Apr 28 2009 Published by Tony under Javascript

定义以下模式为有效的:

  1. john@hotmail.com
  2. john.doe@somewhere.com
  3. John Doe<john.doe@somewhere.com>

javascript的正则表达式为
var reEmail=/^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;

No responses yet

Flex:浅谈Flex事件机制

Apr 27 2009 Published by Tony under Flex

一直对RIA技术非常感兴趣,研究了一下Flex的事件机制,发现Flex的事件机制和Javascript很像,只不过更加严格。在Flex的事件机制中有一个比较重要的概念dispatchEvent,基本原理就是事件所在的容器类初始化的时候注册其事件监听函数。如果需要自己定义Event类型,需要将事件分发到事件队列中,也就是dispatchEvent。也就是你要手动找到自定义的事件的前一个事件,在这个结束的时候调用dispatchEvent(event),这个event就是你自定一个事件,这个事件(一个类)一定要继承flash.events.Event。
给个例子:
自定义的事件类:

public class AddressFormEvent extends Event
 
{
public static const SUBMIT:String = “submit”;
private var _data:AddressVO;
public function AddressFormEvent (eventName:String)
{
super (eventName);
}
public function set data (value:AddressVO):void
{
_data = value;
}
public function get data ():AddressVO
{
return _data;
}
}
在上一个事件结束的时候发布这个事件,下面这段代码就是找到上一个事件:
public class AddressFormClass extends Form
 
{
public var submitButton:Button;
public var nameInput:TextInput;
public var street:TextInput;
public var city:TextInput;
public var state:TextInput;
public var country:CountryComboBox;
public var otherInput:TextInput;
public var otherText:Text;
public function AddressFormClass():void
{
addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler);
}
private function creationCompleteHandler(event:FlexEvent):void
{
submitButton.addEventListener(MouseEvent.CLICK,submitHandler);
}
private function submitHandler(event:MouseEvent):void //这个就是上一个事件的监听函数
{
// Gather the data for this form
var addressVO:AddressVO = new AddressVO();
addressVO.name = nameInput.text;
addressVO.street = street.text;
addressVO.city = city.text;
addressVO.state = state.text;
addressVO.country = country.selectedItem as String;
// 下面就是创建这个事件自定义事件,注意类型就是我们刚刚建的那个事件类。
var submitEvent:AddressFormEvent = new AddressFormEvent(AddressFormEvent.SUBMIT);
submitEvent.data = addressVO;
// Dispatch an event to signal that the form has been submitted
dispatchEvent(submitEvent); //这就是发布这个时间
}
}

No responses yet

Spring 使用AspectJ来配置AOP

Apr 26 2009 Published by Tony under Java

在Application_context中引入名称空间,例子:<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.springframework.org/schema/lang
     http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-2.5.xsd">
  <context:component-scan base-package="bean"/>
  <aop:aspectj-autoproxy/>
</beans>

No responses yet

Next »