吾友李卡多

(注:此文分为中文版,英文版和葡文版,中文用古汉语写成,难免有错,多多见谅!我葡语更是初学,必然有错,希望懂得葡语的人多多指正!不甚感激!)

中文版

====

吾友李卡多

李卡多,吾友,葡国青年也。微胖,甚腼腆。葡国人多外向,此君不然,常异于他人乎。

其虽出身于工程师,但喜政治,亚洲诸国尤甚,然则中国。常夸其口,亦与众人辩之于网络。虽不济,亦乐于预知,似先知。其欲为葡国之宰相也!笃之!

吾尝访其舍,甚大,生活美满,似他国人也。有一妹,唤之“安娜”,与其相去甚远,活泼伶俐。其家人待吾甚好,吾喜其餐尤甚。

吾曾邀其兄妹进餐于中餐馆,言之甚。吾与其妹品一奇异冰激凌,君未;吾等又饮酒数杯,君亦未。皆因酒精乎!吾与其妹笑之曰:“略此女,此君仅喜美剧《欲望都市》乎!”吾等狂笑不止。

似吾,君亦喜Linux及Python是也。君亦有博客,于:http://my.opera.com/remelosilva/blog/。君曰,来日吾将访贵国,工作数年尔。卡多,吾将候君于中国也!

=================

葡文版

====

O meu amigo Ricardo

O Ricardo é o meu amigo em portugal, e ele é português. Ele é um “grande” homem, mas é tímido, como uma menina. :) Por mim, a maioria Português estão malucos, então, é um gente muito diferente e está sempre um exceção.

Gosta de política muito, embora é um engenheiro, como eu. Tem fortes interesses nos países asiáticos, como a china. Infelizmente, está um blaster sobre política, e muitas vezes luta com outras pessoas sobre política na Internet. O que é pior, também gosta de previsão coisas, como um profeta. Seu sonho está a tornar-se o primer ministro do portugal. Boa sorte, o menino!

Visitei a sua família em Cantanhede alguns dias atrás. Tem uma casa grande e uma família feliz, como a maioria de Português. Tem uma irmã nova, que é muito diferente do dele. Seu nome é Ana e ela é bonita e animada. Eles tratado-me muito bem e eu apreciei muito a comida.

Na semana passada, eu convidou-o e sua irmã para jantar juntos num restaurante chinês. Conversámos muito e tinha uma magia refeição. Sua irmã e eu comi um sorvete mágica, mas ele não! Também bebeu algum vinho chinês, mas novamente ele não! Só por causa do álcool! Nós diziamos uma piada com ele, “Vamos esquecê-la, somente Sexo e Cidade é para ELA”. Não podemos parar de rir.

Enfim, como eu, ele é um fã do Linux e também gosta de Python. Também escreve blogs, o seu blog está em: http://my.opera.com/remelosilva/blog/. Ele disse que algum dia ele irá à china para trabalhar por algum tempo. Então, o Ricardo, vou estar esperando por te na china.

=================

英文版

====

My friend Ricardo

Ricardo is my friend in Portugal, he is a native Portuguese. He is a big man, but he is as shy as a girl. :) Since, for me, most Portuguese people are crazy, he is a totally different guy. And he is always an exception.

He likes politics very much, although he is an engineer like me. He has strong interests in Asian countries, like China. Unfortunately, he is a blaster on politics and often fights with others about politics on Internet. What is worse, he also likes forecasting things, like a prophet. His dream is to become the primer minister of Portugal. Good luck, boy!

I visited his family in Cantanhede some days ago. He has a big house and a happy family, like most Portuguese. He has a younger sister who is very different from him. Her name is Ana and she is cute and lively. They treated me very well and I enjoyed the food very much.

Last week, I invited him and his sister to have dinner together in a Chinese restaurant. We talked a lot and had a magic meal. His sister and I ate a magic icecream, but he didn’t! We also drank some Chinese wine, but again he didn’t! Only because of the alcohol! We were joking with him, “let’s forget HER, only Sex and City is for HER.” We can’t stop laughing.

At last, like me, he is a fan of Linux and also likes Python. He also writes blogs, his blog is at: http://my.opera.com/remelosilva/blog/. He said some day he will go to China to work for some time. So, Ricardo, I will be waiting for you in China. :)

愿阳光打在你的脸上

愿阳光打在你的脸上,温暖留在我们心里。”这是我在冬季里听到的最温暖的一句祝福。

最近,葡萄牙的天气实在是很糟糕,接二连三地下了一个星期的雨了。心情和天气一样糟,只能憋在家里哪里也不能去。一个偶然的下午,刚吃过午饭,从forum里出来,阳光扑面,太阳穿过厚厚地云层把阳光洒向地面,感觉到一种说不出来的美。

它让我感觉到了一种久违的意境,在一首钢琴曲里,今天我才发现,那首钢琴曲是奥斯伯森的《黎明时刻》。在这首钢琴曲里,你似乎可以感觉到黎明时阳光开始洒向地面的情景……黎明时分是一天中最黑暗的时候,可是过了黎明就是阳光灿烂 !

愿阳光打在你的脸上,再黑暗的黎明也终会过去。

愿阳光打在你的脸上,哪怕冬天再冷,也能让你感觉到春的气息。

愿阳光打在你的脸上,哪怕风雨再大,也不会停止你前进的脚步。

愿阳光打在你的脸上,有阳光的地方就有希望。只要有希望,一切都会好起来的。

愿阳光打在每一个人脸上。

通过http快速共享文件

一直有这么个想法,可以通过http像nfs那样快速共享文件。用apache吧,不至于动用那个大家伙,用C写一个吧,太麻烦。最后决定用Perl写,可无意间发现了Python有个更简单的模块——SimpleHTTPServer,于是就用Python写,几行就搞定了。

代码见下:

[python]

!/usr/bin/env python

import sys
import string
import SimpleHTTPServer
import SocketServer

if len(sys.argv) != 3:
sys.exit(1)

addr = sys.argv[1]
port = string.atoi(sys.argv[2])

handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer((addr, port), handler)
print “HTTP server is at: “, addr, port
httpd.serve_forever()

[/python]

C++标准函数查询

man page只能查Linux系统调用,C标准函数和其它一些glibc函数,不能查C++标准库函数。怎么才能像man那样查询C++的函数呢?我写了下面这么个Perl脚本来完成。

用法:

$ ./mancpp cmath::sin
$ ./mancpp cmath::cos
$ ./mancpp vector::size
$ ./mancpp algorithm::count_if

代码:

[perl]

!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;

die “Please provide one argument.n” unless @ARGV==1;
die “Use class::function format.n” unless $ARGV[0] =~ /S::S/;

my ($class, $func) = split(/::/, $ARGV[0]);
my $file = “/tmp/$class.$func.html”;

if ( ! -f “$file”) {
my $url;

if ($class =~ /^c/) {
    $url = "http://www.cplusplus.com/reference/clibrary/$class"."/".$func.".html";
} elsif ($class eq "filebuf" || $class eq "fstream"
    || $class eq "ifstream" || $class eq "ios"
    || $class eq "iostream" || $class eq "ios_base"
    || $class eq "istream" || $class eq "istringstream"
    || $class eq "ofstream" || $class eq "ostream"
    || $class eq "ostringstream" || $class eq "streambuf"
    || $class eq "stringbuf" || $class eq "stringstream"){
    $url = "http://www.cplusplus.com/reference/iostream/$class"."/".$func.".html";
} elsif($class eq "vector" || $class eq "bitset" || $class eq "deque"
    || $class eq "list" || $class eq "stack" || $class eq "map"
    || $class eq "queue" || $class eq "set" || $class eq "multiset"
    || $class eq "priority_queue" || $class eq "multimap") {
    $url = "http://www.cplusplus.com/reference/stl/$class"."/".$func.".html";
} elsif ($class eq "functional" || $class eq "iterator"
    || $class eq "memory" || $class eq "utility") {
    $url = "http://www.cplusplus.com/reference/misc/$class"."/".$func.".html";
} elsif ($class eq "algorithm") {
    $url = "http://www.cplusplus.com/reference/$class"."/".$func.".html";
} elsif ($class eq "string") {
    $url = "http://www.cplusplus.com/reference/string/$class"."/".$func.".html";
}

print "Retrieving $url", "...n";
LWP::Simple::getstore($url, "$file");

}

open my $fd, “$file” or die “No such class or function!n”;
my $found = 0;
my @ret;

while(){
if (m//) {
$found = 1;
}
if ($found) {
s/]*>//g;
s//g;
s/</</g;
s/Parameters/n==Parameters==/;
s/Example/n==Example==/;
s/See also/n==See also==/;
push @ret, $_;
}
if (m/SuOptions()/) {
$found = 0;
pop @ret;
}
}

open my $hd, "|less" or die "Can't open pipe!n";

foreach (@ret){
print $hd $_;
}

close $hd;

close $fd;
exit 0;

[/perl]

谁都没错?

$ cat abs.cpp

include <cstdlib>

include <iostream>

using namespace std;

int main()
{
cout<<abs(-19.50)<<endl;
return 0;
}

编译你会得到如下错误:

abs.cpp: In function ‘int main()’:
abs.cpp:7: error: call of overloaded ‘abs(double)’ is ambiguous
/usr/include/stdlib.h:699: note: candidates are: int abs(int)
/usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/cstdlib:175: note: long long int __gnu_cxx::abs(long long int)
/usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/cstdlib:144: note: long int std::abs(long int)

为啥呢?因为abs()在<cmath>中,而不是C++标准参考手册中提到的<cstdlib>!

谁错了捏?其实谁都没错。这里解释到:

The Standard C++ library is supposed to
overload abs the way you expect, but it’s common for implementations
to omit the overloads, or put them in the wrong place (<cmath> instead
of <math.h>).
这个真的让人很无语,一边是出错,另一边是明知道出错也这么做。。。冏。。。

星星山之行

周六和Marco一起去了传说中的葡萄牙(陆地)最高峰,星星山。

星星山离Marco家Lapa很近,所以我们先到了他家,吃完中午饭之后才动身。走之前他还叫上了他的小外甥,一个才上小学四年级的小鬼,于是我们三个一起上路了。那个小鬼叫Mario,就是“超级玛里”中的“玛里”,是个活泼,聪明伶俐的孩子。小鬼的英语比我的葡语还糟,他和我说的英语还不如我和他说的葡语多。不过对于这个年纪的孩子来说已经很不错了。

我们在路上花了相当多的时间,本来是计划到了山顶之后下来再去附近的一个城堡,所以我们绕道走了另一条比较远的路上山。谁知道那条路那个长啊,先是在山下的镇上绕来绕去,还好我们有GPS,终于绕到山上去了。到山上还是得继续绕,山路绕得比F1赛道还多,绕得坐到后面那个小鬼昏昏欲睡。

最后终于绕到了山顶,可是天色已经渐暗,山上天黑得很快,才拍了没多少张照片天色就基本上已经全黑了。山顶上风很大,气温很低,只有三四度,还好我们有提前准备的衣服,拍照时也不得不裹得严严实实的。那小鬼似乎带的衣服太少,只好又穿上了Marco的外套,那对他来说太大啦,结果看起来很是滑稽。

山顶上有商店,我们钻进去看了看,我在那里买了个小纪念品。然后我们又进了旁边的一家咖啡吧,我要了一杯热咖啡热身,喝完感觉暖和多了。在国内,在山顶的商店卖的东西一般是山下的N倍,而这里的东西比山下贵了不多少,让我感到一丝惊讶,大概因为能开车到这里的缘故吧。

等我们出来天已经完全黑了,本来计划要去看的湖泊和城堡也只好作罢了。匆匆忙忙赶回去吃晚饭去了。

吃完饭准备回Coimbra时,我们又去了那个酒吧。那老板娘还记得我,这次又和我开玩笑,她问我喝什么啤酒?大瓶的还是小瓶的?我说小瓶的,然后比划了一下小的有多小,过了一会儿她拿来一个小瓶的,说你要的是这个吧?我看了看说是,谁知道她后面还藏着一个更小的呢。。。她后面的人都笑了。然后她还拿出一个特大号的来,说让我下次再来喝那个。。。

喝完要走时,遇到一个喝醉的,非得拉着我和我说葡萄牙语,我站在那里无语得很,用葡语告诉他我不说葡语,谁知道他说,你这不就是在说葡语嘛,冏。。。。要不是其他人给我解围我是走不出那个酒吧了~

非常难忘的一个周末~!

gcc 4.3 改变了 -Wconversion

gcc 4.3之前,-Wconversion是这样的:

Warn if a prototype causes a type conversion that is different from what would
happen to the same argument in the absence of a prototype.

Also, warn if a negative integer constant expression is implicitly converted to
an unsigned type.
到了4.3就变了,发布日志上解释到:
The -Wconversion option has been modified. Its purpose now is to warn for
implicit conversions that may alter a value. This new behavior is available for
both C and C++. Warnings about conversions between signed and unsigned integers
can be disabled by using -Wno-sign-conversion. In C++, they are disabled by
default unless -Wsign-conversion is explicitly requested. The old behavior of
-Wconversion, that is, warn for prototypes causing a type conversion that is
different from what would happen to the same argument in the absence of a
prototype, has been moved to a new option -Wtraditional-conversion, which is
only available for C

这个改变其实挺大的,下面通过这个程序就可以展示这个问题:

[c]
void foo(short i);

void foo(short i)
{
i++; //dummy
}

int main(void)
{
int a = 1;
short b =2;
b = a;
foo(a);
return 0;
}
[/c]

$ gcc -Wall -Wtraditional-conversion -o conv conv.c
conv.c: In function ‘main’:
conv.c:14: warning: passing argument 1 of ‘foo’ with different width due to prototype
$ gcc -Wall -o conv conv.c
$ gcc -Wall -Wconversion -o conv conv.c
conv.c: In function ‘main’:
conv.c:13: warning: conversion to ‘short int’ from ‘int’ may alter its value
conv.c:14: warning: conversion to ‘short int’ from ‘int’ may alter its value

键盘符号的英文读法

键盘上一些符号的英文读法真的让人头疼,很多根本就没有统一的念法。上葡语课时我问老师dash在葡语里怎么用,结果她不知道什么是dash,最后经过探讨我们达成共识,我问的是hyphen…… 因为我整天和程序打交道,“-”更多被读作dash,而非程序员更多读作hyphen。比较烦~~

这里简单整理一下键盘上所有特殊符号的英文读法,最后还有葡语中特殊符号的英文读法。参考资料见本文最后。

! 叹号 exclamation mark/bang
? 问号 question mark
, 逗号 comma
. 点号 dot/period/point
: 冒号 colon
; 分号 semicolon
“ 双引号 quotation marks/double quote
‘ 单引号/撇号 apostrophe/single quote
` 重音号 backquote/grave accent

  • 星号 asterisk/star
  • 加号 plus sign
  • 减号/横线 hyphen/dash/minus sign/
    = 等号 equal sign
    / 斜线 slash
    反斜线 backslash/escape
    | 竖线 bar/pipe/vertical bar
    _ 下划线 underline/underscore
    $ 美元符号 dollar sign
    @ at at sign

    井号 crosshatch/sharp/hash

    % 百分号 percent sign/mod
    & and/和/兼 and/ampersand
    ^ 折音号 circumflex/caret
    ~ 波浪号 tilde
    {} (左右)花括号/大括号 (left/right|open/close) braces
    [] (左右)方括号/中括号 (left/right|open/close) brackets
    () (左右)圆括号/小括号 (left/right|open/close) parentheses
    <> 尖括号 angle brackets
    < 大于号 less than
    > 小于号 greater than

葡语中的变音符号(diacritic mark)在英文中的读法:

^ circumflex/caret
~ tilde/squiggle
´ acute
` grave
ç cedilla

参考资料:

1. http://www.codinghorror.com/blog/archives/001133.html
2. http://ascii-table.com/pronunciation-guide.php
3. http://www.learningportuguese.co.uk/language/diacritics.html

光棍节快乐!

一年过了又一年,只是每年这个节日还是没变。:-)

希望明年有所改观,不过貌似我每年都这么说……