Garey's Blog–FreeBSD/PHP/GoLang

三月 18th, 2010

FreeBSD 8.0的网关实现手册(ipfw+natd)

1 Comment, FreeBSD, by garey, 12,327 views.

一、编译内核

编辑内核文件,增加如下几行:

options    IPFIREWALL
options    IPDIVERT
options    IPFIREWALL_VERBOSE
options    IPFIREWALL_VERBOSE_LIMIT=5

重新编译内核。

二、配置启动项

vi /etc/rc.conf

gateway_enable="YES"
hostname="gateway.bsdart.org"
ifconfig_em1="inet 192.168.0.1  netmask 255.255.255.0"

firewall_enable="YES"
firewall_type="UNKNOWN"
firewall_script="/etc/ipfw.rules"

ppp_enable="YES"
ppp_mode="ddial"
ppp_profile="adsl"

natd_enable="YES"
natd_interface="tun0"
natd_flags=""

三、编辑防火墙规则

vi /etc/ipfw.rules

#!/bin/sh

oif="tun0"
iif="em1"
fwcmd="/sbin/ipfw -q add"

valid_tcpport="22, 80"

/sbin/ipfw -q -f flush

$fwcmd 0100 allow all from any to any via $iif
$fwcmd 0110 allow all from any to any via lo0

$fwcmd 0200 check-state

$fwcmd 1000 allow all from any to any out via $oif keep-state

$fwcmd 1100 allow tcp from any to me $valid_tcpport in via $oif setup keep-state

四、编辑ADSL拨号设置

vi /etc/ppp/ppp.conf

adsl:
set device PPPoE:em0
set mru 1492
set mtu 1492
set authname **********
set authkey **********
set dial
set login
add default HISADDR
enable dns
set timeout 0
set redial 3 5
set reconnect 5 10000
set cd 5

全部设置好了之后就可以将服务器重启了。

至此,实现局域网NAT上网已经成功实现。

三月 11th, 2010

3种WEB服务器的比较(Apache,Nginx,Lighttpd)

No Comments, FreeBSD, Linux, by garey, 9,560 views.

image

注:在相对比较大的网站,节约下来的服务器成本无疑是客观的。而有些小型网站往往服务器不多,如果采用 Apache 这类传统 Web 服务器,似乎也还能撑过去。但有其很明显的弊端: Apache 在处理流量爆发的时候(比如爬虫或者是 Digg 效应) 很容易过载,这样的情况下采用 Nginx 最为合适。

建议方案:

Apache 后台服务器(主要处理php及一些功能请求 如:中文url)

Nginx  前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求)

Lighttpd 图片服务器

总体来说,随着nginx功能得完善将使他成为今后web server得主流。

摘自:http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html

systat基本上是FreeBSD中最功能最多的系统监视命令,显示CPU、I/O、内存、虚拟内存、mbufs、磁盘IO、网络状态等信息等。

命令:

systat [-display] [refresh-interval]

其中 display 为我们所要显示的信息项目,我们也可以在进入 systat 后通过输入“:display” 变更显示项目,refresh-interval 参数是需要多长时间采样一次系统数据输出到屏幕,单位是秒。

实例:# systat -vmstat 1

命令解释:显示CPU、I/O、内存、虚拟内存、mbufs、磁盘IO、网络状态等信息。信息采样刷新时间为1秒。

实例截图:

vmstat

以下为可用的 display 参数:

pigs 显示目前系统中使用 CPU 最多的行程名称。如果所有行程的 CPU 使用量未满 100%,则多出来的部份显示为 IDLE。
icmp 统计目前 ICMP 封包的进出情形。
icmp6 显示 IPv6 的 ICMP 封包进出情形。
ip 显示 IP 层的封包统计及 UDP 封包信息。
ip6 和 IP 一样,但只显示 IPv6 的封包。
tcp 显示 TCP 的封包统计。
iostat 显示 I/O 状况统计,并分类为各种模式显示。
swap 显示目前各个储存空间上的虚拟内存的使用情形。
mbufs 显示 mbufs 被使用的状态。
vmstat 这是我们最常用的显示模式,它显示了最多的信息,包含 I/O、虚拟内存、mbufs、网络等信息。
netstat 显示网络的使用情形。
ifstat 显示各个网络适配卡的使用情形。

原文: http://www.lvtao.cn/computer-internet/freebsd/freebsd-systat-command.html

2月28日的Arseblog

链接在此:
http://www.oleole.com/blogs/arseblog/posts/stoke-1-3-arsenal–ramsey039s-injury-sickening—the-media-have-blood-on-their-hands
我很喜欢Arseblog。昨天的比赛真的让人五味杂陈。自己也写不出什么东西,就分享一下今天的arseblog。大部分观点本人都很支持。
Stoke 1-3 Arsenal : Ramsey’s injury sickening – the media have blood on their hands
斯托克城 1-3 阿森纳:拉姆塞的受伤彷如噩梦—媒体是罪魁祸首
May 1st 2006 – Abou Diaby has his ankle fractured and dislocated by a challenge from Dan Smith.
2006年5月1日:迪亚比踝关节骨折错位,肇事者丹史密斯。
Feb 23rd 2008 – Eduardo has his left fibula fractured and sustains an open dislocation of his ankle joint after Martin Taylor’s tackle.
2008年2月23日:爱德华多腓骨(小腿双骨外侧的那根骨头)骨折,踝关节错位。肇事者马丁泰勒。
Feb 27th 2010 – Aaron Ramsey has his fibula and tibia broken, his leg left hanging in the air, by Ryan Shawcross.
2010年2月27日:拉姆塞腓骨和胫骨骨折(就是小腿整个断了)。肇事者肖克罗斯。
Arsenal captain Cesc Fabregas said immediately after the game:
In five years I’ve seen three of them, Abou, Edu and now Aaron. What can I say? It’s difficult.
阿森纳队长法布雷加斯在赛后立即发言:五年里我已经见过三回了,迪亚比、爱德华多,现在是拉姆塞。我还能说什么?这太困难了。
I love Cesc but he’s wrong. It’s not five years. It’s less than four years. These kinds of horror injuries can happen in football. It’s a physical sport and such injuries are thankfully rare but they do happen. However, I have never in all my years known one club to suffer three of these potentially career ending injuries, let alone in such a short period of time.
赛思克很好,可是这回他错了。并不是五年,连四年都不到。这种恐怖的受伤会发生在足球场上。足球是一项要求身体素质的体育运动,感谢上帝这样的伤势并不常见。但是我从没见过有任何一家俱乐部曾经发生过三次严重到威胁职业生涯的受伤事件,更别提在这么短的时间里就发生了三次。
Is it just coincidence? Arsene Wenger said afterwards he doesn’t believe in coincidence and I’m with him 100% on this one. I believe that these three injuries are a direct consequence of the ‘Arsenal don’t like it up ‘em’ ethos which has become conventional wisdom in recent years.
这只是巧合么?温格在赛后说他不相信巧合,我完全支持这个说法。我相信这三起事件发生的直接原因,就是“阿森纳讨厌身体对抗”这种近年来被广泛流传的观点。
‘They don’t like being kicked’, the implication that the wimpy foreigners can’t take it. And it has been peddled across the football world by reporters, TV pundits, radio commentators, Sky Sports presenters and anyone else you can think of. ‘Arsenal don’t like it up ‘em’, as if Arsenal were somehow unique in this. Let me tell you, nobody likes it ‘up em’.
“他们不喜欢硬碰硬”暗示着这只弱不禁风的外国队儿受不起英超强烈的身体对抗。这种说法在足球界广为流传,体育记者、电视嘉宾、电台评论员、天空体育解说或者任何其他的媒体都会这么想你传授。“阿森纳讨厌打硬仗”,就好像人人都喜欢被别人踹一样。我告诉你们,没人愿意被人踹。
No other club has suffered three horrendous injuries like this in the last four years. My honest opinion is that the belief that it’s ok to be overly physical with Arsenal because, surprise surprise, they don’t like it, is the root cause. If I had to trace it back I think it’d probably start with Sam Allardyce and if I had a time machine that cunt would get it good and proper but sadly we can only deal with the here and now.
这四年间在英超,没有其他任何一家俱乐部曾经遭受过如此严重的受伤事件。说实在的,这种“完全可以对阿森纳下狠脚”的原因,猜不到吧?其实就是阿森纳不喜欢被人下狠脚,这就是根本原因了。如果要我往回追溯一下这个对付阿森纳的策略好像是起源于阿勒代斯(混球啊!)。有时间机器的话就好了,咱们可以回到过去然后证明我的正确性,但是杯具的是我们只能看到此时此地。
Before I go on, I’ll make this point : I don’t think any of the players who carried out these tackles wanted to break another professional’s leg. And in that I’m giving Dan Smith the serious benefit of the doubt because his tackle was by far the worst, well late and I think a bit nasty. Even still I don’t think he intended to do that kind of damage. Now, let me address the people who say "Well, he’s is not that kind of player’.
在继续之前,我必须澄清我的观点:我不认为任何一位上述的肇事者之一真心想弄断另一个职业球员的腿。这个认定给了史密斯最大的好处,因为他的犯规时最恶性的,后来想起来真的觉得很恶毒。即使这样我仍然愿意相信他并不是为了踢断腿而踢断腿的。好,现在让我们来谈谈那些说 “他是个本性善良的球员”的人。
Duh, you are a fucking moron and you should shut up. Unless the person in question is an actual psychopath of course they’re not that kind of player. It goes without saying. Nevertheless they’ve been told to go out there and get stuck in and give Arsenal a bit extra because, as we all know, they don’t like it up ‘em. So you have Dan Smith’s snide tackle, Martin Taylor’s ‘reducer’ and last night Shawcross’s reckless hack at Aaron Ramsey. Did he mean to break his leg? Of course not. Did he want to? No, of course not. The bottom line though is that he did. I feel his tackle was absolutely reckless. Watch it again if you can – via @twistedgambino. If it happened on a football pitch at the very poor level I play at there would have been war, because everyone could see it was unnecessary. At this level of the professional game it was a horrendous challenge.
哈!你们这些SB们请闭嘴吧!除非那几个哥们儿是真正的神经病不然他们当然是“本性善良”的球员。这是当然的。但是,他们仍然在比赛之前被告知“上场给阿森纳点儿颜色看看吧,地球人都知道,他们不喜欢硬碰硬”。所以史密斯卑鄙的滑铲,泰勒“没收住脚”,所以昨天肖克罗斯鲁莽的踹向拉姆塞。他的目的是弄断对方的腿么?当然不是。他想看对方断腿么?当然不想。但是无论如何他做到了。如果这发生在我平常去的草根水平的球场,那肯定要爆发群殴了,因为每个人都看得出这个动作不必要。但是这发生在高水平的职业联赛上,于是它只是一次极为严重的犯规。
If I can liken to it something else it’s speeding. The young guy in his car who goes out, thinking he’s Johnny Invincible, until he careers around a corner too fast and mows down a child. He didn’t mean to, but he did it, and he is responsible. "I didn’t meant to run the kid over" and "He’s not that kind of driver" aren’t acceptable excuses in a courtroom so spare me the mealy-mouthed crap over Shawcross. He looked distraught but his tears don’t matter. What matters is that a talented young footballer has been the victim of a ridiculous tackle and his leg is broken in pieces.
请类比一下。一个年轻人开着车外出,感觉自己就像宇宙无敌超级英雄一样,直到他转弯太急撞死了一小孩儿。他不想撞死人,但是无论如何人死了,他的责任。“我不是故意撞死那个小孩儿的”和“他是个本性善良的司机”可不能成为呈堂证供为他免罪。所以别TM跟我这给肖克罗斯找借口了。他看起来确实很难过,但是他的眼泪P用不顶。现实是一个年轻而才华横溢的足球运动员成为了这次荒唐滑铲的牺牲者,他的小腿被踢得粉碎。
We know Aaron is going to get the best possible medical care and all we can do is wish the best for him as his career takes an unexpected and horrific diversion. We’ve seen the impact of these injuries, the fallout is not pretty, and he is probably going to have to battle the same niggles that Eduardo and Diaby have to struggle against all the time. The physical damage is tremendous, not just the broken leg but try to redevelop the muscle and everything else, but so too is the mental damage. Thankfully he’s got two guys who can show him the way, who can help through when things get really difficult and when it’s time to come back they can help him cross the white line again without fear.
我们知道拉姆塞会得到最好的医疗救治,我们能做的只有在他职业生涯这个难以预料的恐怖事故之后给他最好的祝福,我们曾经见过这样的时间给运动员带来的打击,这打击非同小可,他很有可能将会面临爱德华多以及迪亚比同样的困境,这样的困境会自始至终缠着他。物理伤害已经相当严重了,断了的骨头、损伤的肌肉以及其他,但心里上的打击同样严重。感谢上帝队里还有两个过来人,可以在最艰难的时刻扶他一把,当他身体条件恢复,可以付出的时候,帮他克服恐惧,重返球场。
But how fucking heartbreaking is it that we have those two players? I will admit to being rather emotional watching that game last night. It was obvious from the first instant what had happened and I felt sick for Aaron Ramsey. A kid of 19. It leaves you angry. And angrier because this is not the first time it has happened to Arsenal. Nor the second. But the third inside four years and quite frankly enough is enough.
但是反过来想想我们已经有两个曾经断过腿的球员是多TM的令人难过啊?我必须承认昨天看比赛的时候情绪非常激动。一看就知道有多严重,我为拉姆塞感到异常难过,一个十九岁的小孩儿。这让人愤怒,更让人愤怒的是他不是阿森纳的第一个,不是第二个,而是4年里的第三个。坦白的说我真TM受够了。
Immediately afterwards on Sky we had Richard Keys and Andy Gray making excuses. "Is it because Arsenal are too quick?", said Keys. Fuck me. No. It’s not because we’re too quick, it’s because we’ve been on the receiving end of some obscene tackles. "Sometimes you have to play them like that", said Gray, referring to the fact that Arsenal don’t like it up ‘em. Well, he’s the thing – as far as I’m concerned, Andy Gray, Richard Keys, the rest of those utter cunts at Sky, and anyone else who has helped perpetrate that myth over the years is in some way culpable for the fact that Aaron Ramsey had his leg busted like a twig last night. They have gone on and on and on about it and this, ladies and gentlemen, is what happens.
事件发上之后,天空体育立刻又基斯和格雷来给这事儿找借口。“也许是因为阿森纳速度太快了?”基斯说。我Cao。真不是,真不是因为我们太快了,是因为我们遭到了一个该死的滑铲。“有些时候,对阿森纳确实只能这么踢”格雷如是说。他的意思就是阿森纳不喜欢身体对抗。恩,就是他了——在我看来,格雷、基斯,还有其他那些天空体育的纯SB们,或者任何像他们一样四处宣传这句“对付阿森纳的不二法门”的人,都要为今天的事件负责。他们就是是昨天拉姆塞被人踢断了腿的罪魁祸首。他们就这样不厌其烦的向别人都受这个对付我们的法宝,然后,女士们先生们,昨天的事情就是这么发生的。
Arsene Wenger addressed it already this season at one his press conferences.
温格曾经在这个赛季的新闻发布会上谈过此事
I am always absolutely amazed that people get away with it. When we get kicked and lose the game, the question I get from the press is ‘oh, you did not fancy that’. But nobody is upset or shocked by it. When we are kicked they find that it is absolutely all right.
我一直都觉得他们可以明目张胆的干坏事真是不可思议。当我们被人踹,输了比赛,媒体就说“看,你们不喜欢这个”,但是没人觉得故意犯规令人震惊。他们觉得阿森纳球员就是用来被人踢的。
And the assembled hacks had a little titter and off they went to do exactly that. The furor over Gallas’s tackle after the Bolton game was incredible. I don’t remember any pundit saying "He’s not that kind of player", only slamming him for what was, I agree, a bad challenge. The Shawcross apologists are out in force today yet these are the same people who made such a mountain out of the molehill that was Eduardo’s dive against Celtic that UEFA ‘investigated’ and tried to ban him. A dive. Yet when a young man has his leg broken in bits they keep their mouths shut or come out in defence of the honest English clogger (any coincidence all three challenges have been by Englishmen?). Honestly, they make me fucking sick. This willingness to overlook acts of horrific violence yet focus on trivia like diving.
再加上量刑根本不是一视同仁的。大家对加拉斯在对阵博尔顿的比赛中那次犯规出离愤怒。我不记得当时有任何一个嘉宾在那儿说:“他是个本性善良的球员”只有人痛骂他的所作所为,好吧我同意,那个犯规。肖克罗斯今天迫于压力公开道歉。但是爱德华多也曾道歉。当时那所有人该死的鸡蛋里挑骨头的去调查爱德华多的假摔并试图让他禁赛,拜托,假摔,一个年轻人曾经被人在球场上踢断了腿,他们也没张罗着要调查或者让肇事者禁赛,甚至还有人站出来护着那个英格兰混球,(真是凑了巧了,三个肇事的家伙都他妈是英国人)。说实话这帮人真让人恶心。他们愿意为了假摔斤斤计较,却忽略赤裸裸的球场暴力。
Shawcross gets a three match ban, Alex Song is now banned for two matches for a booking that never was. How the fuck does that work in any sane kind of world? It’s rotten to the core, is what it is.
肖克罗斯被禁赛三场。亚历山大宋现在也被禁赛两场,因为一个子虚乌有的犯规。他妈的这个世界还有没有点儿人性?英超是烂在根儿上了。
And back to Sky for a moment. If anything sums up their hypocrisy it’s the decision not to show replays of the tackle. Why not? They say it’s because the images are too upsetting. Firstly, who the fuck made them the arbiters of good taste? Why do they get to decide what is and isn’t acceptable? People have buttons on their remote which say ‘off’ or ‘channel up’. If they don’t want to watch it, advise them and they can turn it off. As the broadcaster who has done most to big up the ‘Arsenal don’t like it up ‘em’ thing they have a responsibility to show what happened to Aaron Ramsey. To show what a tackle like that can do. To show that when you egg people on enough and they think it’s ok to behave recklessly that there are consequences.
再来说说天空体育。不重新播放犯规片段能客观反映出他们的虚伪。为什么不放?他们说是因为片段过于血腥。第一,谁规定他们说了算?为什么他们能决定什么观众看得,什么看不得?观众手握遥控器,如果他们不想看,警告他们让他们关掉不就得了。他们是宣传“阿森纳不喜欢身体对抗”的始作俑者,他们又责任播放发生在拉姆塞身上的事情。告诉人们所谓的“身体对抗”能带来什么效果,告诉人们“不断怂恿别人可以鲁莽犯规”是有后果的。
For Ramsey it’s a broken leg and a year out of the game, all going well. For Arsenal we lose a talented player at a crucial part of the season … and we have to watch another of our lads injured in a way that would bring tears to your eyes. And even for Shawcross, who I think was utterly reckless, the tackle on Ramsey was not his first wild lunge of the night, who has been told to go out and play like that. He didn’t want to break Ramsey’s leg. I’m sure it’ll make him sick, give him nightmares and all the rest. I’m not suggesting he’s a victim by any means but he is a byproduct of this media led scheme too. I don’t feel sorry for him but I think it’s a fair point in the grand scheme of things.
对于拉姆塞来说,就是断了条腿,修养一年。对于阿森纳来说,我们在联赛关键阶段失去了一个有才华的运动员。对于球迷来讲我们又得目睹我们的小伙子严重受伤并且泪流满面。甚至是对于肇事者来说,(即使我认为他是一纯粹的屠夫,对拉姆塞的犯规并不是他的初犯),但他是被人教唆的,他不是成心弄断拉姆塞的腿,我敢肯定这件事也会给他带来影响,噩梦阴魂不散什么的。我并不是说他是受害者,但他确实只是媒体宣传的副产品而已,我不同情他,但确实有必要指出始作俑者。
I’m sure there are some reading this who will say ‘Arsenal aren’t whiter than white’. And that’s true. No team that plays a high intensity physical sport can say that. Yet no other team has been on the receiving end of the kind of injuries we have. That is a fact. One you can put down to an accident, two could be just unfortunate, three … too much. And enough is enough. I’m sure this will get plenty of coverage on Arsenal blogs, many of whom I’m sure feel the same way about this as I do, but there are good journalists and sports writers out there who also have a platform and, in my opinion, a duty to address this issue. If they love football then they can’t ignore this.
我敢说有些正在看这篇文章的人会站出来说阿森纳也不总是干干净净的踢球,这是事实。没有一个对在这样高强度对抗的比赛中能说自己绝对干净。但同样的,也没有任何其他球队向我们这样被人伤害。这也是事实。一次你可以说是意外,两次可以说是运气太差,三次,已经太多了。足够多了。我想这件事肯定会被许多阿森纳球迷博客提到,我知道肯定好多人和我有同感。但是还有许多优秀的体育记者,他们有更广泛的平台,他们有责任和义务来呼吁大家重视这个事件。如果他们真正热爱足球,他们不会忽视这次惨剧。
Some will, Shawcross has been called up the England squad which affords a player a certain amount of protection from the most jingoistic and snide journalists. I do hope there are others who will take up the baton though. Not against Shawcross in particular but on the general issue. It is not ok to kick Arsenal, or any other team, out of a game. We all love the physical aspect of football, it’s part of what makes it such a great game, but there’s a line you don’t cross and too often now teams have crossed it with us, without so much as a word of condemnation. Instead there’s the sly smile, the snigger and the sneering about how ‘Arsenal don’t like it up ‘em’.
肖克罗斯被招进英格兰国家队,国家队给他提供了一个不被记着骚扰的环境。但是我仍然希望有人能报道此事,不是针对肖克罗斯,而是针对事件。侵犯阿森纳球员同样是犯规,就像侵犯别的队员,或者是在赛场外侵犯任何人都是有罪的。我们都喜欢足球中的身体对抗,这是让足球比赛精彩的一个要素,但是这是有底线的,而现状却是太多的球队在对付阿森纳的时候跨过了底线,却没有得到应有的责备。而且恰恰相反,反倒是阿森纳被冠上了“不能应付身体对抗”的头衔。
It is not acceptable. The consequences of that mindset were obvious last night as a 19 year old boy screamed in agony as his leg hung at a sickening angle. This is the outcome of your sly smiling and your sneering. Are you happy now?
这是我不能接受的。这种心态广为流传的后果就是,昨天晚上,一个十九岁的男孩儿被踢断了腿,痛苦不堪的倒地尖叫。这就是你们带来的后果。你们现在高兴了?
Before I finish on this particular section, props to Stoke’s Glen Whelan who stayed with Aaron Ramsey from the moment it happened. A cut above the rest. To the Stoke fans who applauded Aaron off the field, fair play to you. To the rest who chanted abuse as he lay injured and gave him wanker signs as he was taken off the pitch on a stretcher, you are fucking pondlife. I hope you die roaring.
斯托克诚的维兰,他在拉姆塞倒地后自始至终和他在一起,确实是境界高人一等。对于那些为阿姆赛鼓掌支持的球迷,你们是真球迷。至于那些唱歌辱骂甚至对我们的受伤球员伸中指的混蛋,你们TM的不是东西。你们去死吧!
Finally, it seems a bit trite and redundant but I want to wish Aaron Ramsey all the best and I hope we see him back in an Arsenal shirt, where he belongs, as soon as possible.
最后,虽然有点陈词滥调和多余,但是我还是想祝福拉姆塞早日康复,希望我们能尽快看见他穿回阿森纳球衣,回到属于他的球场。
As for the game, what can you say? It doesn’t bear much analysis in terms of the performance but one thing stood out for me. Cesc Fabregas. Our captain. When Eduardo was injured against Birmingham we went to pieces, culminating in the toe-curling sight of then captain William Gallas throwing a tantrum when we gave away a late penalty. Last night we were a bit tentative after the incident, which is only natural, but it became clear this is a different Arsenal team. There was no feeling sorry for ourselves. No dwelling on things we couldn’t change.
关于昨天的比赛,我还能说什么呢?这种比赛也没什么好分析的了。但是还是有一点惊艳,法布雷加斯,我们的队长。当年爱德华多受伤的时候我们彻底崩盘了,我们得队长加拉斯悲痛不已,精神涣散,最后我们打飞了点球。昨天晚上阿姆赛受伤后,我们确实受到了打击,这是正常现象,但是我们确实不再是两年前的那只阿森纳了。现在的我们不再自怨自艾,不会再陷在改变不了的悲剧里不能自拔。
Cesc Fabregas became the leader Arsenal fans have so dearly wanted for so long. I won’t hear a thing about how he’s not a captain because he fucking well is. First goal – assist for Bendtner’s fantastic header. Second goal – a penalty under the most intense pressure imaginable. He had the balls to get up there, take it and score it. Third goal – assist for Vermaelen. Nor did he stand for any of Stoke’s baiting. He had a little kick at one of their players who had kicked him earlier. He Sssshhh’d Tony Pulis. He dragged his Arsenal team over the line. He led by example last night and at the end of the game our players stood in a huddle, knowing they’d shown what they’re made of, and the captain rallied his troops. Each one of them was fantastic last night. The lessons of Birmingham have been learned.
法布雷加斯真的成长成了我们阿森纳球迷日夜期盼了太久的领袖。我不想再听人说“他不是队长的材料”了,因为他就队长料。第一个进球,他主攻本特纳打进了精彩的头球,第二个进球,他承受了巨大的压力射入点球,他协助创造机会,主罚点球,并且命中,第三个进球,他主攻维尔瓦伦。他也不会对对方的犯规忍气吞声。他对一个早先将他放倒的队员还以颜色,并对对方主教练做了噤声的手势。他带领阿森纳战胜逆境,他在昨天晚上为我们的球员树立了榜样。比赛结束的时候,我们的队员在场中央围成一圈,围绕在队长周围,宣告我们是一只坚强的队伍。昨天的每一个队员都是出色的。我们从伯明翰的那场比赛学到了教训。
I know people all have their opinions of this team, the players, the managers and everything else but if last night didn’t make you proud to be an Arsenal fan then there’s something wrong with you. My spine is tingling even thinking about it.
我知道大家都怀有有自己的看法,对球队,对球员,对教练,或者其他。但是如果昨天晚上你没有因为自己是阿森纳球迷而感到骄傲,那一定是神经有毛病了。我只要想想就激动不已。
I think that sometimes we lose sight of why and how we support our football club, and while you’d never want to be reminded because of what happened to Aaron Ramsey last night did just that. Our reaction, our desire, our spirit, our togetherness, it was the Arsenal.
我觉得有时候我们会忘了自己为什么支持我们的俱乐部,也许我们也不愿意想起来,因为昨天晚上拉姆塞身上发生的事情才会让你想起来。我们队员的处事能力,精神,团结,这才是阿森纳。
I love the Arsenal.

 

原文:http://bbs.arsenal.com.cn/thread-230824-1-1.html

二月 26th, 2010

python使用json的方法

No Comments, Python, by garey, 11,252 views.

>>> import json
>>> userinfo = {‘name’: ‘garey’, ‘dob’: ’1983-01-01′, ‘gender’: ‘M’, ‘country’: ‘CN’, ‘access’: 0, ‘state’: 1, ‘last_login’: ’2010-02-25 18:00:00′}
>>> json_userinfo = json.write(userinfo)
>>> json_userinfo
‘{"name":"garey","dob":"1983-01-01","gender":"M","country":"CN","access":0,"state":1,"last_login":"2010-02-25 18:00:00"}’
>>> user = json.read(json_userinfo)
>>> user['name']
‘garey’

二月 26th, 2010

python连接memcached的方法

No Comments, Python, by garey, 8,074 views.

import memcache
mc = memcache.Client(['192.168.0.1:11211'], debug=0)

写入
mc.set("key", "value")
第三个参数默认为0,也就是数据永不超时。
如果这样设置:
mc.set("key", "value", 1)
表示一秒后超时

读取
value = mc.get("key")
print value

删除
mc.delete("key")

自增和自减
mc.set("key", "1")
mc.incr("key")
mc.decr("key")

二月 25th, 2010

关于php中mysqli->close()的使用问题

No Comments, MySQL, PHP, by garey, 10,063 views.

我在php中使用mysqli->close()的时候,总会出现如下的Warning:

Warning: mysqli::close() [mysqli.close]: Couldn’t fetch mysqli in /usr/local/apache2/htdocs/test.php on line 84

PHP代码如下:

class Mysql_class{

private $link;

function __destruct(){

$this->close();

}

function connect($dbhost, $dbport, $dbuser, $dbpasswd, $dbname){

$this->link = new mysqli($dbhost, $dbuser, $dbpasswd, $dbname, $dbport);

}

function close(){

$this->link->close();

}

}

$mydb = new Mysql_class($dbhost, $dbport, $dbuser, $dbpasswd, $dbname);

$mydb->close();

 

找了好久才发现在使用__destruct()执行$this->close()之后,就不需要再手动调用$mydb->close()了,这样mysqli->close就被执行了两次,所以第二次会提示Couldn’t fetch mysqli。

二月 21st, 2010

[转]python-rbtree和内建dict的性能比较

No Comments, Python, by garey, 6,798 views.

python内建的dict(字典)类使用的是hash算法,因此它的key不是有序的。而C++中的std::map或std::set使用的是平衡二叉树(通常为红黑树),其key是有序的。在网上搜了搜,找到了一个用C和pyrex混合实现的红黑树模块,python-rbtree。

我编写了一个极简单的测试程序,在Solaris x86 + python 2.4.4平台上运行,分别使用dict和rbtree,插入两百万个记录(key是3个整型,value是1个整型,你大概猜到我在干什么了吧 :) )。且在dict插入完之后,调用dict.keys().sort()对其key进行排序(也就是快排)。比较的结果是,两种方法使用的内存相当(大概在200M左右)。但是hash算法的速度要快一倍以上。当记录个数增加到五百万个时,结果还是差不多──即内存使用相当,hash算法快一倍。

至少在这个数量级上,内建的dict性能更佳。我还尝试了另一个纯Python的红黑树实现–RBTree.py,结果令人失望,在记录个数比较多的情况下,似乎根本无法得到正确的结果。

结论,python中的dict是可信赖的!

 

原文:http://blogs.sun.com/yongsun/entry/python_rbtree%E5%92%8C%E5%86%85%E5%BB%BAdict%E7%9A%84%E6%80%A7%E8%83%BD%E6%AF%94%E8%BE%83

二月 21st, 2010

[转]HASH表原理

No Comments, 未分类, by garey, 6,668 views.

    哈希表又名散列表,其主要目的是用于解决数据的快速定位问题。考虑如下一个场景。
    一列键值对数据,存储在一个table中,如何通过数据的关键字快速查找相应值呢?不要告诉我一个个拿出来比较key啊,呵呵。
    大家都知道,在所有的线性数据结构中,数组的定位速度最快,因为它可通过数组下标直接定位到相应的数组空间,就不需要一个个查找。而哈希表就是利用数组这个能够快速定位数据的结构解决以上的问题的。
    具体如何做呢?大家是否有注意到前面说的话:“数组可以通过下标直接定位到相应的空间”,对就是这句,哈希表的做法其实很简单,就是把Key通过一个固定的算法函数既所谓的哈希函数转换成一个整型数字,然后就将该数字对数组长度进行取余,取余结果就当作数组的下标,将value存储在以该数字为下标的数组空间里,而当使用哈希表进行查询的时候,就是再次使用哈希函数将key转换为对应的数组下标,并定位到该空间获取value,如此一来,就可以充分利用到数组的定位性能进行数据定位。
    不知道说到这里,一些不了解的朋友是否大概了解了哈希表的原理,其实就是通过空间换取时间的做法。到这里,可能有的朋友就会问,哈希函数对key进行转换,取余的值一定是唯一的吗?这个当然不能保证,主要是由于hashcode会对数组长度进行取余,因此其结果由于数组长度的限制必然会出现重复,所以就会有“冲突”这一问题,至于解决冲突的办法其实有很多种,比如重复散列的方式,大概就是定位的空间已经存在value且key不同的话就重新进行哈希加一并求模数组元素个数,既 (h(k)+i) mod S , i=1,2,3…… ,直到找到空间为止。

 

原文:http://calmness.javaeye.com/blog/184465

二月 11th, 2010

[转]Linux下的Memcache安装

No Comments, Linux, by garey, 5,797 views.

Linux下Memcache服务器端的安装
服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.3.0 。
下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,libevent的最新版本是 libevent-1.3。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/
下载:http://www.monkey.org/~provos/libevent-1.3.tar.gz

用wget指令直接下载这两个东西.下载回源文件后。
1.先安装libevent。这个东西在配置时需要指定一个安装路径,即./configure –prefix=/usr;然后make;然后make install;
2.再安装memcached,只是需要在配置时需要指定libevent的安装路径即./configure –with-libevent=/usr;然后make;然后make install;
这样就完成了Linux下Memcache服务器端的安装。详细的方法如下:

    1.分别把memcached和libevent下载回来,放到 /tmp 目录下:
    # cd /tmp
    # wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
    # wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

    2.先安装libevent:
    # tar zxvf libevent-1.2.tar.gz
    # cd libevent-1.2
    # ./configure –prefix=/usr
    # make
    # make install

    3.测试libevent是否安装成功:
    # ls -al /usr/lib | grep libevent
    lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
    -rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3
    -rw-r–r– 1 root root 454156 11?? 12 17:38 libevent.a
    -rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la
    lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
    还不错,都安装上了。

    4.安装memcached,同时需要安装中指定libevent的安装位置:
    # cd /tmp
    # tar zxvf memcached-1.2.0.tar.gz
    # cd memcached-1.2.0
    # ./configure –with-libevent=/usr
    # make
    # make install
    如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
    安装完成后会把memcached放到 /usr/local/bin/memcached ,

    5.测试是否成功安装memcached:
    # ls -al /usr/local/bin/mem*
    -rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
    -rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug

安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
2.安装PHP的memcache扩展

    tar vxzf memcache-2.2.1.tgz
    cd memcache-2.2.1
    /usr/local/php/bin/phpize
    ./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
    make
    make install

3.上述安装完后会有类似这样的提示:

    Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/

4.把php.ini中的extension_dir = “./”修改为

    extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”

5.添加一行来载入memcache扩展:extension=memcache.so

memcached的基本设置:
1.启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

    -d选项是启动一个守护进程,
    -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
    -u是运行Memcache的用户,我这里是root,
    -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
    -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
    -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
    -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

2.如果要结束Memcache进程,执行:

    # kill `cat /tmp/memcached.pid`

也可以启动多个守护进程,不过端口不能重复。

3.重启apache,service httpd restart

Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?php
$mem = new Memcache;
$mem->connect(”127.0.0.1″, 11211);
$mem->set(’key’, ‘This is a test!’, 0, 60);
$val = $mem->get(’key’);
echo $val;
?>

参考资料:
对Memcached有疑问的朋友可以参考下列文章:
Linux下的Memcache安装:http://www.ccvita.com/257.html
Windows下的Memcache安装:http://www.ccvita.com/258.html
Memcache基础教程:http://www.ccvita.com/259.html
Discuz!的Memcache缓存实现:http://www.ccvita.com/261.html
Memcache协议中文版:http://www.ccvita.com/306.html
Memcache分布式部署方案:http://www.ccvita.com/395.html

原文:http://www.ccvita.com/257.html