2010-02-25

密底算盤

見2010年2月25日的都市日報

2010-02-15

塔勒布 在 【黑天鵝】的名句

舊年(2009)在深圳書城買了本"THE BLACK SWAN: The Impact of the Highly Improbable"中譯本,發覺題材非常新鮮,有很多發人心醒的內容。但由於是中譯本,始終不知原著的語句。

上星期,終於在圖書館借到原英文本(2007年版),現節錄一些我覺得非常有意思的內容,和大家分享:

Page xviii
Black Swan is an event with the following three attributes:

  1. Rarity – It lies outside the realm of regular expectations
  2. Extreme Impact – It carries an extreme impact
  3. Retrospective predictability – Human nature makes us concoct explanations for its occurrence after the fact, making it explainable and predictable.
Page xix
Black Swan logic makes what you don't know far more relevant than what you do know.

Why does reading the newspaper actually decrease our knowledge of the world?

Life is the cumulative effect of a handful of significant shocks.

Page xx
Our inability to predict in environments subjected to the Black Swan, coupled with a general lack of the awareness of this stage of affairs, means that certain professionals, while believing they are experts, are in fact not.

Page xxvii
You need a story to displace a story.

Ideas comes and go, stories stay.


Page 3
History doesn't crawl; it jumps.

Page 8
The human mind suffers from three ailments as it comes into contact with history, what I call the triplets of opacity. They are:

  1. the illusion of understanding, or how everyone thinks he knows what is going on in a world that is more complicated (or random) then the realize;
  2. the retrospective distortion, or how we can assess matters only after the fact, as if they were in a rearview mirror (history seems clearer and more organized in history books than in empirical reality); and
  3. the curse of learning - the overvaluation of factual information and the handicap of authoritative and learned people, particularly when they create categories - when they "Platonifiy."
Page 10
These events were unexplainable, but intelligent people thought they were capable of providing convincing explanations for them – after the fact. Furthermore, the more intelligent the person, the better sounding the explanation.

Page 21
(Financial) independence is person-specific: I have always taken aback at the high number of people in whom an astonishingly high income led to additional sycophancy as they became more dependent on their clients and employers and more addicted to making even more money.

Page 25
Publishers now have a theory that "truck drivers who read books do not read books written for truck drivers"
香港有沒有這些出版商呢?

Page 40
The uberphilosopher Bertrand Russell presents a particularly toxic variant of my surprise jolt in his illustration of what people in his line of business call the Problem of Induction.

Page 54
An acronym used in the medical literature is NED, which stands for No Evidence of Disease. There is no such thing as END, Evidence of No Disease. Yet my experience discussing this matter with plenty of doctors even those who publish papers on their results, is that many slip into the round-trip fallacy during conversation.

Page 59 footnote
Once your mind is inhabited with a certain view of the world, you will tend to only consider instances proving you to be right. Paradoxically, the more information you have , the more justified you will feel in your views.

Page 80
One death is a tragedy; a million is a statistics.

Page 96
Some people are like the turkey, exposed to a major blowup without being aware of it, while others play reverse turkey, prepared for big events that might surprise others.

Page 111
Recall the confirmation fallacy: governments are great at telling you what they did, but not what they did not do. In fact, they engage in what can be labeled as phony "philanthropy," the activity of helping people in a visual and sensational way without taking into account the unseen cemetery of invisible consequences.
咁似香港D區議員!

Page 112
Our neglect of silent evidence kills people daily. Assume that a drug saves many people from a potentially dangerous ailment, but runs the risk of killing a few, with a net benefit to society. Would a doctor prescribe it? He has no incentive to do so... A life saved is a statistics; a person hurt is an anecdote.

Page 120
My biggest problem with the educational system lies precisely in that forces students to squeeze explanations out of subject matters and shames them for withholding judgment, for uttering that "I don't know."

Page 152
We humans are the victims of an asymmetry in the perception of random events. We attribute our success to our skills, and out failures to external events outside our control, namely to randomness.

Page 181
The only criticism one might have of Hayek is that he makes a hard and qualitative distinction between social sciences and physics. He shows that the methods of physics do not translate to its social science siblings, and he blames the engineering-oriented mentality for this. But he was writing at the time when physics, the queen of sciences, seemed to zoom into our world. It turns out that even the natural sciences are far more complicated than that. He was right about the social sciences, he is certainly right in trusting hard scientists more than social theorizers, but what he said about the weaknesses of social knowledge applies to all knowledge. All knowledge.

Page 198
Randomness, in the end, is just unknowledge. The world is opaque and appearances fool us.
好有佛理!

Page 222
Luck is the grand equalizer, because almost everyone can benefit from it.

Page 225 footnote
The giant firm J.P. Morgan put the entire world at risk by introducing in the nineties RiskMetrics, a phony method aiming at managing people's risk, causing the generalized use of the ludic fallacy.

Page 226
True, we now have fewer failures, but when they occur...I shiver at the thought. I rephrase here: we will have fewer but more severe crises. The rarer the event, the less we know about its odds. It means that we know less and less about the possibilities of a crisis.

希望大家有同感!

2010-01-28

不是小兒科的數字

近期在新聞報導常常聽到一些很大的數字,如多少百億興建高鐵,金融海嘯有關的天文數字等,令我覺得其實有多少人知道其真正「份量」?

有次在街上,聽到一母親教她的兒子數十進制:個、十、百、千、萬、十萬、百萬、千萬、億萬...我覺得愕然,為何會由千萬特跳到億萬呢?難怪現在的小孩不識理財了,因為連數數字也不懂!

我小學時學的,中國單位以萬為分位,西方則以千為分位,所以:

千萬以後是:萬萬(即億),十億,百億、千億、萬億、十萬億,百萬億、千萬億...

講起數數字,順便講一講「兆」。

中學時學十進制,知道兆是一百萬,所以電台FM頻道的兆赫是百萬Hertz。

但是台灣仍治用兆是萬億(即1012)(見維基百科 )

新聞報導員沒有加上附註,容易做成混亂!

2009-12-20

Gimp Polaroid Filter

To make my photo posting on my blog more interesting, I have usually resorted to use Gimp's "Round Corner" Script-Fu. I like this script because it drops a shadow so that my photos seems pop up from the background.

Later on, I encountered several blogs on internet like:
Gimp Making Border (in Chinese) (link)
Turn a digital photo into Polaroid with Gimp (link)

The idea is to make a digital photo resemble a photo-print and make it lay on a surface with some irregular shadows.

I very like this idea but find the steps clumsy if I have repeatedly do photo postings on my blog.

So... I start to write my first Gimp script!

Most of the Gimp macros are written in Script-Fu. It is said that it is a language called Scheme (however, I have learned Lisp before and I still cannot differentiate Scheme from Lisp because of their similarity!)

I hate Lisp because the proliferation of brackets and I have difficulties to make the opening and closing brackets match.

Anyway, after a one-day tutorial on learning the Script-Fu, my first Gimp script is born. It works as follows:
  • it adds a border to similar the print paper
  • it creates a shadow and then use the perspective effect to make the shadow irregular
  • it finally adds a background to match my blog background
I have tested my script in my two only Gimp environments, viz. version 2.2.17 (on Win98SE) and 2.6.2 (on Win XPP)

Installation steps:
  • download the script (link)
  • put it to the script directory (in my Windows environment, it is C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts)

Execution steps:

- open a photo, like


- run the script, which will solicit the following parameters


- the result is as follows:

2009-11-06

Using LINQ to retrieve XML data

Although it is like "to use a cannon to kill a mosquito", I find using LINQ to read XML has a clear advantage - to read the node like an associative array (like PHP).

I use the following VB example to illustrate:


Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xml_str As String
xml_str = "<ROOT><FIELD1>VALUE1</FIELD1><FIELD2>VALUE2</FIELD2><FIELD3>VALUE3</FIELD3></ROOT>"
Dim xmltree As System.Xml.Linq.XElement
xmltree = XElement.Load(New System.IO.StringReader(xml_str))
Label1.Text = xmltree.Element("FIELD2").Value
End Sub
End Class



I deliberately use a string to hold the XML content in this example, although the native constructor can be as simple as

Dim xmlTree1 As XElement =
<Root>
 <Child1>1</Child1>
 <Child2>2</Child2>
 <Child3>3</Child3>
</Root>

2009-11-03

Using VB 2008 Express as client to consume SugarCRM Web service

In additional to my previous example of using AXIS as web client, I now use VB.NET as another example to consume web service. Moreover, I will just the open source SugarCRM as web service provider.

SugarCRM
The wsdl link is as follows (the host name depends on your installation. I use localhost here)
http://127.0.0.1/sugarcrm/soap.php?wsdl
as shown in the following IE screen dump


VB
The set up is a little bit tricky, as the initial menu does not have any web service item. The steps are as follows:
(1) Project > Add Service Reference


(2) Click the "Advanced" button (Do not type the WDSL link yet)


(3) Click the "Add Web Reference" button


(4) Type the WSDL link and press "Go" button. The web service description will be displayed. Then choose a reference name you like (I use SugarCRM) and press "Add Reference"


(5) You will find VB has added the WS reference in the Solution Explorer


(6) Ironically, VB will now have the "Add Web Referebce" menu item available in the Project menu


7) Now you can start to write codes to consume the web service. Since my example just illustrate the principle, I have hard-coded many things. The logic is there is a Button1. If I click this button, it will call the login method of SugarCRM. The session id returned will be displayed as Label1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim soapservice As New SugarCRM.sugarsoap
Dim credential As New SugarCRM.user_auth
Dim opensession As New SugarCRM.set_entry_result
credential.user_name = "admin"
credential.password = getMd5Hash("password")
credential.version = "1.0"
opensession = soapservice.login(credential, "SugarCRM")
Label1.Text = opensession.id
End Sub


The convenience of using VB is its IntelliSense which can enumerate the available options.


I have declared three objects
soapservice - the client stub
credential - the first argument of the service, containing the user id, md5 of the password and the version.
openssion - the returned result of the service. One of the most important field is the session ID

The result is shown below

2009-10-23

CTI (Computer Telephony Integration) for SugarCRM

Recently I come across SugarCRM. It has a Community Edition which I do not need to pay. Moreover, since it is open-source, I can realize some customization easily.

I have experience in CTI (Computer Telephony Integration). But what I can search around SugarCRM is its integration with Asterisk, which is also an open source telephony project.

Because I have already an Avaya installation base, I study whether I can do some quick start work easily.

What I need are two functions:

(1) Screen Pop
To pop up the SugarCRM screen based on the Calling Line Identity (CLI)

(2) Click to Dial
Turn the phone number in the SugarCRM screen to a link that is clickable and activate automatic phone dialling

For those readers which are familar with CTI, these are just very basic features. But it is achievable for SugarCRM, this is already a great time-saver for the CRM users.

I tackle the problem in the following ways:

(1) Screen Pop
Since SugarCRM is web-based, I can simply ask the browser to navigate to a specific link.

The first question is what the link is.

In SugarCRM, I make a search with a phone number. Then I get the following screen.


Great, I find the URL is
http://127.0.0.1/sugarcrm/index.php?module=Home&query_string=test&advanced=true&action=UnifiedSearch&search_form=false&query_string=5551888&search_mod_Contacts=true
5551888 is the phone number I have typed.
Therefore in .NET code, I use:
url_str = "http://127.0.0.1/sugarcrm/index.php?action=UnifiedSearch&search_form=false&advanced=false&query_string=" _
& SkpSock1.CLID & "&search_mod_Contacts=true"
System.Diagnostics.Process.Start(url_str)
Here, SkpSock1.CLID is my CTI object to collect the CLID (Calling Line Identity) property.

(2) Click to Dial
I find SugarCRM has Skype integration, in which it will convert a phone number to a clickable link. First you need to turn this feature on in the Administration screen, as follows:

After the feature activation, you will find that when you put a mouse pointer over a phone number, you can find it the associated link is :
callto://5551234/

In Windows, each URL protocol can be managed by the "Folder Option" in the Windows Explorer. (Someone suggested registry hack. But I prefer the conventional way.)

After pressing the "Advanced" button and then the "Edit" button, you can set your preferred program to handle this protocol. In my case, I have

written a program called "qcallto.exe". Windows will pass the link a program parameter to it.

Finally, a point of SugarCRM hack. As shown in the SugarCRM adminstration screen, it requires a phone number to conform to certain format (e.g. prefixed with a plus sign). I do not like this convention. Why cannot SugarCRM simply treat all the phone number clickable?

Thanks to the PHP open sources, I find that in "c:\Inetpub\wwwroot\sugarcrm\include\utils.php" (the actual directory depends on your installation), there is a php function will determine whether a phone number is clickable:

Original:
function skype_formatted($number){
 if(isset($_REQUEST['action']) && $_REQUEST['action']=="Popup") {
  return false;
  }
 else {
   return substr($number, 0, 1) == '+' || substr($number, 0, 2) == '00' ||
   substr($number, 0, 2) == '011';
  }
 }

I change it to
function skype_formatted($number){
 if(isset($_REQUEST['action']) && $_REQUEST['action']=="Popup") {
  return false;
  }
 else {
  return 1;
 }
}

Some final words... Although my implemented solution is Avaya-based, it is easily portable to other platforms (even for a modem connected phone line) easily.

2009-10-12

Why DC cannot shoot a picture with shallow depth of field

I carry an Optio S3 to make ad hoc photography.

According to the specification, the tiny camera has an aperture f2.6 - f4.8

However, even at an aperture f2.6, I can never shoot a picture with sufficient shallow depth of field (DOF), except in macro mode of course.

I start to ask why.

The most authoritative reference (but hard to understand) about Depth of Field is at Wiki (link http://en.wikipedia.org/wiki/Depth_of_field)

It gives complicated formula to show the relation of DOF vs. format size (though roughly speaking, DOF is inversely proportional to format size). Since my DC has a small CCD, the DOF is less shallow than the conventional SLR.

However, I try to associate the problem with APS-C or Four Thirds or micro Four Thirds.

In these cases, usually, we will use a crop factor to represent the effective focal length at full-frame (FF, at 35mm) format size . For instance, even you use a lens with 18mm on DSLR with crop factor 1.6, its effective angle of view is just same as 28.8mm at FF.

Please note that aperture is actually stated in F-number (the ratio of focal length to effective aperture diameter).

Then why not use similar the crop factor to calculate the effective DOF?

For instance, my Optio S3 has the focal length 5.8mm (equivalent to 35mm at FF). This means that the crop factor is about 6X.

Then even at aperture f2.6, the "equivalent" aperture at FF is already 6x2.6 = 15.6

This explains why I cannot shoot at shallow DOF even with the largest aperture (smallest F-number) because its FF-equivalent aperture at 15.6!

2009-10-09

Using COM objects in VB.NET

I am an old-fashioned guy and right now even though I uses VB.NET for my new programming, I still need to resort to old COM objects sometimes.

I find there is not much references to facilitate the process (e.g. I do not like command line tools). If I have a VB6 project orginally, the Studio Express can import it automatically. But if I starts a new .NET project, I find the following procedures is the quickest:

(1) Add the COM reference in the "Tools" | "Choose Toolbox Items" menu, so that the object is selectable in the left Toolbox


(2) Choose the COM Components Tab. If your object has been registered before hand, it is listed. Otherwise, click the Browse button to include it in the list


(3) Then you will find the Componet will appear in the left Toolbox. You then can drag it into your form.


(4) You will find VB.NET will automatically add appropriate references in your Project Properties, as in the following screen dump. In my cases, VB.NET add two references: one is the Interop and one is the AxInterop

2009-08-24

高清無用!

當人人都「講」高清時,我發看很多人其實都將Windows的display解像度set得比native低(可能使用者有老花?),見MSDN Blog Follow-up on High DPI resolution


從圖可見,只有55%的人用native resolution,可悲!