maybe a mistake in 'Learning Perl'

最近开始学习perl,网上查加打听知道”Learning Perl”这本书很不错,被亲切地称为“小骆驼”。我读的是东南大学书版社第六版的影印版。今天看到chap11,遇到一个问题死活整不出来想要的结果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#!/usr/bin/perl
use DateTime;

my $dt1 = DateTime->new(
year => 1987,
month => 12,
day => 18,
);
my $dt2 =DateTime->new(
year => 2013,
month => 5,
day => 1,
);
my $duration = $dt2 - $dt1;
my @units = $duration->in_units( qw(years months days) ); #重点就在这里,书里面是单数,结果打印出来全是0,改成复数就ok了
printf "%d years, %d months, and %d days\n", @units;

今天到此收工, 明天还要早起。

只是想打给你

从小到大,每做一件事,或自觉或不自觉就要回答一个问题:“为什么呢?”仿佛如果没有,或者你解释不清,就会遭来质疑。也就是我们被灌输了这样一种意识,做A就是为了直接或间接达到B。

这里我联想到,《天才在做 疯子在右》里面作者讲自己和他朋友的一件趣事。作者这位朋友骨子里,就是有一种“反劲儿”,比如她坦言自己的想法,站在艾菲尔铁塔上小便一定特爽吧。说到这里的时候,作者就不停的揣度朋友这样做的动机,包括行为主义在内的几个答案都被否定了,因为本来就没有动机,她就是觉着这样做挺爽的,没有理由。

那么,要是有人打电话给你,只是为了打给你呢?

  • “xx 我是xx 在忙吗?”
  • “恩 xxx”
  • “哦 那你忙吧 没事儿”
  • “不是 有事你说吧,我真的没想到你会打过来”
  • “就是想起你来了 没事儿,你先忙,再联系。”

写得有点儿乱,归根结底就是想说,做事除了目的性很强的,有时候还有这样一类人,他们给你打电话,就是想听听你的声音,想知道你在干吗。他们哪怕想在艾菲尔铁塔上小便,也只是这样,他们是很纯粹的、简单的一类人。

书本之上

昨天读了字节社的新书《Tim O’Reilly in a Nutshell》其中的“书本之上”这篇心有共鸣。Tim在其中提到,他们考虑出版什么书,首先考虑的从来不是能赚多少钱,而是有没有用,而这样最终书的销量也不用担心了。

这样我想很久以前看到柯达中国的中国区领导(名字忘记了)说过的类似的话,不要奔着钱去做事,做你喜欢的事,最后你会发现同时也得到了钱。这起中的道理不言自明,而困难的是生活中会有各种诱惑,让你偏离本来的方向,有时忘了自己当初的目标。

关于”是做喜欢的事还是试着喜欢你做的事“我自己想过,也和我哥讨论过。老大说”这个问题太复杂“,老二说”很简单,先生存下来“。老实说,他俩的回答我都不满意。老大其实没有给出答案,老二说的貌似也挺有道理的,很现实的,先养活自己再说。可是然后呢?先做好必须做的工作,同时不忘自己的愿想,业余时间苦练。我想起在v2ex上看到一个人的博客里这句话”keep coding, keep thinking, planning future, doing now”。找到自己毕生从事的事是幸福的,越早越好,就好比第二次生命一样,从此后眼前会大不一样,你每天起床想到不用想就去做自己的事。就想这句话说的”每天早上被梦想叫醒“。

P.S.最后说说字节社app,总体很赞的应用。操作流畅,上手快,排版精良,下载书速度也很快,这点要比kindle for iphone强,我用的美国去kindle帐号登录的,下载速度不稳定,有时候等得人着急。一个建议,字节社以后是不是考虑出些英文原版书以及计算机类的?

附赠中文版和英文版地址:

a work around for babel key error

When working on this repo, I tried to use flask-babel like this:

1
2
3
from flask.ext.babel import gettext, ngettext
gettext(mystring)
ngettext(singular, plural, period)

It began complaining to me with “key error: babel” when I test it. I tried these things, don’t work:

Finally I come up with a simple solution, and it work well for the time being. I use string format like this

1
u'%d %s ago' % (period, plural) 

plus ‘if’ contrl statments instead of ‘ngettext’.

basic vim

Vim is a powerful editer coming with linux.Here I assumes that you already know it’s history and also have a vim on linux or gvim under windows(although I recomend using vim with linux). So let’s begin our basic vim.

##vimtutor
open a console and type ‘vimtutor’, then you are in a vimtutor file right in vim. This is a vim tutorial disgned for learning vim on the fly. Learning has never been more efficient through using it. Just keep in mind that when you leave don’t save you change. The tutorial cover the basic usage of vim, such as insertion/deletion/navigation/replacing/searching. Believe me, once you learn it, you will love it.

##vimperater/vimium
Afer you fall in love with vim, maybe you will think how about using vim when surfing internet, that sounds great, right? The short answer is there is already some extensions for firefox(vimperater) and chrome(vimum).All you need to do is searching for one you like and embrace it. very cool!

The biography of Steve Jobs:the reality distortion field

Recently I’m reading “the biography of Steve Jobs”. Firstly, I have to admit that i have an instinct feeling that populer books may not worth its fame,that’s why when steve passed away and many people rushed into book store for this book, i restricted myself outside.

Until yesterday i read a post from Ruan YiFeng’s blog introducing this book and admit that he should read it sooner. Indeed Mr Steve tremendously change the world of PC, phone and how we publish and read or listen have been completly changed.Before Apple, mobile phone is just a phone, that’s all it does and It seems that’s all people what people use it for. But now, you can hardly imagine life without a smart phone. Also, you won’t disagree that App Store is the biggest and most profitable electronic market on the planet.

Many a person aroud Steve mention that there is a reality distortion field suround him. He had the magic to make Apple’s engineer acomplish something they themselves don’t believe they can. And yes, sometimes when there’s no way to convice ourselves by science, we attribute it to magic or religion. Someone see technology and art on Steve and products of Apple. Steve had a strict demanding for the product. The author mentioned a lot in the book. Steve told the engineer even the electronic wires should be arranged in order so that gives a beautifull looking. The engineer apparently did’t understand, just like us, asking “Why do we need to do this, our customers won’t see this”. Steve replied “But we-the creator do! think about this, would a good artisan bear his table’s back made up of bad wooden board? Even he know the customer using his table may never look at the back?” I clearly remmenber another story, one day Steve show up at one engineer who design Macintosh’s software system and asked “Can you reduce Mac’s boot up time by 10 secs?” At this time, the engineer’s facial expression reveals reluctance, then Steve told her “If Mac boot up 10 secs sooner, one person’s life will be saved, would you do it? Now Imagine our Mac sold 1 million, if everyone can boot up 10 secs less than before, would that amount of time deserve our effert?”