Java关于夏令时的神来之笔

夏令时简介:

Daylight Saving Time:DST     夏令时,又称“日光节约时制”或“夏时制”,是一种为节约能源而人为规定地方时间的制度,在这一制度实行期间所采用的统一时间称为“夏令时间”。一般在天亮早的夏季人为将时间提前一小时,可以使人早起早睡,减少照明量,以充分利用光照资源,从而节约照明用电。各个采纳夏令时的具体规定不同。目前全世界有近110个每年要实行夏令时。(各时区多数位于其理想边界之西,导致实际上全年实施夏令时。)

      1986年至1991年,在范围实行了六年夏令时,每年从4月中旬的第一个星期日2时整(时间)到9月中旬第一个星期日的凌晨2时整(夏令时)。除1986年因是实行夏令时的第一年,从5月4日开始到9月14日结束外,其它年份均按规定的时段施行。1992年4月5日后不再实行。

如果有幸你阅读完了上面的内容,下面的东西可能会更加有趣: 

java198654号的0点不见了!!!

 

public static final SimpleDateFormat Y2MD_HMS = new SimpleDateFormat("yy-MM-dd HH:mm:ss");

Date d = TimeFormattor.Y2MD_HMS.parse("1986-5-4 0:0:0");
 System.out.println(d);
 

输出是Sun May 04 01:00:00 CDT 1986

继续验证:

 

循环打印了附近的时间

long _1986_5_4_0_0_0 = 515520000000L;//
  Calendar c = Calendar.getInstance();
  
  for(long i=_1986_5_4_0_0_0-H;i<_1986_5_4_0_0_0+H;i+=M)//
打印每分钟   {
   c.setTimeInMillis(i);
   System.out.println(c.getTime());
  }

是java的神来之笔,还是jdk的bug???

d.yang同志的无名氏的代码学习记录-flex 2d Rpg游戏demo

[文章作者:陈臻 本文版本:v1.0 最后修改:2009.2.23 转载请注明原文链接:http://www.54chen.com/c/469]

略去一千字废话,要谢谢地阳同学把人家的包全改成了funcat...哪里来的胖猫。。。

先上截图:

flex builder3编译后运行,鼠标控制小女孩,按空格时小男孩坐下。

只能大概对初始化的代码注释下,其他的自己看了,抛砖引玉:

private function initApp():void
this.contextMenu.hideBuiltInItems();

sceneHolder = new UIComponent();
this.addChildAt(sceneHolder, 0);

scene = new RPGScene();
sceneHolder.addChild(scene);

//主屏幕在浏览器的位置设置
sceneHolder.x = 0;//(this.stage.stageWidth - 1000)/2;
sceneHolder.y = 0;//(this.stage.stageHeight -631)/2;
//男孩 参数:图片地址,宽度,高度,x,y,速度
role = new Player("../assets/roles/38x88.png", 62, 103, 38, 88, 4);
scene.addContain(role);
role.place(600,315);
//女孩 同上
role1 = new Player("../assets/roles/39x83.png", 62, 103, 39, 83, 4);
scene.addContain(role1);
role1.place(600,515);
//创造一个Item 参数: 图片地址,宽,高,x,y
bg = new Item("../assets/bg/ground1.jpg", 1000, 631, 0, 0);
scene.addBg(bg);

//蓝色房子三个
for(var i:int=0;i<aList.length;i++){
building = new Item("../assets/bg/building2.png", 297, 307, -1, 275);
building.place(aList[i][0]+500, aList[i][1]+315);
building.mirror(aList[i][2]);//数组的第三个元素控制房子是否水平翻转,-1翻转,1转
scene.addContain(building);
//色的房子
for(var j:int=0;j<bList.length;j++){
building = new Item("../assets/bg/building1.png", 275, 334, -1, 260);
building.place(bList[j][0]+500, bList[j][1]+315);
building.mirror(bList[j][2]);
scene.addContain(building);
//中间那个塑像
girl = new Item("../assets/bg/obj1.png", 110, 154, -1, 135);
girl.place(500, 315);
scene.addContain(girl);
//再放一个房子
ft = new Item("../assets/bg/building1.png", 275, 334);
ft.place(400+500, 200+315);
scene.addFront(ft);

this.stage.addEventListener(MouseEvent.CLICK, onClick);
this.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyDownHandler);
}

附代码包供学习使用。

rpgdemo

用iptables做两机之间的端口转发

 [文章作者:陈臻 本文版本:v1.0 最后修改:2009.2.19 转载请注明原文链接:http://www.54chen.com/c/264]

以前发过一篇利用iptables做本机的端口转发的文章,利用简单的地址转换的原理,可以将两台互相可访问的机器利用iptables转发,这样很容易实现类似透明代理的功能,当然,这个代理不会有缓存的。:)

假如我希望把对 1.2.4.5:8080的访问都转向 1.2.6.9:80:

IP包来到之后,修改目的地址,使之转向目标机器的目标端口,在.5这个机器上:

iptables -t nat -A PREROUTING -d 1.2.4.5 -p tcp --dport 8080 -j DNAT --to 1.2.6.9:80

IP包返回的时候,修改源地址(源端口),使之符合IP协议,正确返回,还是在.5这个机器上:

iptables -t nat -A POSTROUTING -d 1.2.6.9 -p tcp --dport 80 -j SNAT --to 1.2.4.5:8080

然后我们需要在.5作系统上打开IP转发:

echo '1' > /proc/sys/net/ipv4/ip_forward

最后再设置.5的连接状态

  iptables -A FORWARD -o eth0 -d 1.2.4.5 -p tcp --dport 8080 -j ACCEPT

iptables -A FORWARD -i eth0 -s 1.2.6.9 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT  

附全部脚本(不关.9的事,全是在.5上)

iptables -t nat -A POSTROUTING -d 1.2.4.5 -p tcp --dport 8080 -j DNAT --to 1.2.6.9:80

iptables -t nat -A PREROUTING -d 1.2.4.5 -p tcp --dport 8080 -j DNAT --to 1.2.6.9:80

iptables -t nat -A POSTROUTING -d 1.2.6.9 -p tcp --dport 80 -j SNAT --to 1.2.4.5:8080

iptables -A FORWARD -i eth0 -s 1.2.6.9 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

iptables -A FORWARD -o eth0 -d 1.2.4.5 -p tcp --dport 8080 -j ACCEPT

Tomcat,resin,oc4j,jboss大比拼

本文是山寨比较方法,全凭个人感觉,高手和自认为高手略过。

老资格tomcat,但只是web容器,不支持ejb;resin比起tomcat更加优秀在于中文的支持,性能更好,校内网用;oc4j师出名门oracle,明声好,没有别的特别的,某大型保险公司用;jboss很牛叉,很,效率未知,淘宝用。待续。。。

Lighttpd 插件开发方法

 [文章作者:陈臻 本文版本:v1.0 最后修改:2009.2.12 转载请注明原文链接:http://www.54chen.com/c/309]

lighttpd插件开发步骤

 

插件架构说明

  • lighttpd的状态:为了便于理解lighttpd插件开发,需要了解lighttpd server在处理请求响应消息的过程中的11种状态,在这些状态中有如下重要函数需要被调用。对于这些状态,有的请求可能都会涉及到,有些请求可能只会经过部分状态。
状态 含义 对应函数
connect waiting for a connection nothing
reqstart init the read-idle timer nothing
read read http-request-header from network connection_handle_read_state()
connection_handle_read()
reqend parse request http_request_parse()
readpost read http-request-content from network connection_handle_read_state()
connection_handle_read()
handlereq handle the request internally (might result in sub-requests) http_response_prepare()
respstart prepare response header connection_handle_write_prepare()
write write response-header + content to network connection_handle_write()
respend cleanup environment, log request plugins_call_handle_request_done()
plugins_call_handle_connection_close()
connection_close() (if not keep-alive)
connection_reset()
error reset connection (incl. close()) plugins_call_handle_request_done()
plugins_call_handle_connection_close()
connection_reset()
close close connection (handle lingering close) connection_close()
  • lighttpd的回调函数:lighttpd在不同的状态中共有16个回调函数.
    • Serverwide hooks
init_
    called when the plugin is loaded
  cleanup_
    called when the plugin is unloaded
  set_defaults_
    called when the configuration has to be processed
  handle_trigger_
    called once a second
  handle_sighup_
    called when the server received a SIGHUP
 
    • Connectionwide hooks
 
Most of these hooks are called in ``http_response_prepare()`` after some
  fields in the connection structure are set.

handle_uri_raw_
called after uri.path_raw, uri.authority and uri.scheme are set
handle_uri_clean_
called after uri.path (a clean URI without .. and %20) is set
handle_docroot_
called at the end of the logical path handle to get a docroothandle_subrequest_start_
called if the physical path is set up and checked
handle_subrequest_
called at the end of ``http_response_prepare()``
handle_physical_path_
called after the physical path is created and no other handler is
found for this request
handle_request_done_
called when the request is done
handle_connection_close_
called if the connection has to be closed
handle_joblist_
called after the connection_state_engine is left again and plugin
internal handles have to be called
connection_reset_
called if the connection structure has to be cleaned up

Php正则表达式常见 Regex 作符清单

php的正则表达式反馈了php的功力,下面是作符的清单,常备重要哦。。。

作符 用途
.(句点) 匹配所有单个字符
^(脱字符号) 匹配出现在行或字符串开头的空字符串
$(美元符号) 匹配出现在行尾的空字符串
A 匹配大写字母 A
a 匹配小写字母 a
\d 匹配所有一位数字
\D 匹配所有单个非数字字符
\w 匹配所有单个字母或数字字符;同义词是 [:alnum:]
[A-E] 匹配所有大写的 A、B、C、DE
[^A-E] 匹配大写 A、B、C、DE 之外的任何字符
X? 匹配出现零次或一次的大写字母 X
X* 匹配零个或多个大写字母 X
X+ 匹配一个或多个大写字母 X
X{n} 精确匹配 n 个大写字母 X
X{n,m} 至少匹配 n 个且不多于 m 个大写字母 X;如果忽略 m,则表达式将尝试匹配至少 nX
(abc|def)+ 匹配一连串的(最少一个)abcdefabcdef匹配

春晚的魔术揭秘

魔术这东西知道真像就不好玩了,如果你没有像我一样探查世界的,那还是不要知道怎么样实现的为妙,知道了就感觉被骗了.

1.橡皮筋

个人认为,这个才是最有意思的,适合居家旅行逗女生使用.

下面是揭秘的教程视频:

2.硬币

没啥大意思,基本一看我就知道硬币就在大杯子底里掉下去的,中间摄像机又不给全镜头,有很多机会去动手脚.

核心提示:胶水在受热时会改变性状,平时能粘住的东西在受热时就粘不住了.

3.戒指进鸡蛋

现在做假鸡蛋的技术已经不是什么新鲜的了,上路边报刊亭买本野杂志,上面有人造鸡蛋机器的招商广告.

所以是两个戒指.看有网友说是提前放到盘子里的,其实不是,蛋打开是散的,这在我们那边是叫"寡鸡蛋",是不能吃的,有硬物在蛋里把蛋搅坏了.

综上,23都没意思,过个不容易,主持人也是拖儿.