Monday, December 28, 2015

【成長,必須付出代價】只有 1% 的人能到達的人生境界,你達到幾項了?

【成長,必須付出代價】只有 1% 的人能到達的人生境界,你達到幾項了?

智慧境界的 16 種共同特徵

美國心理學大師馬斯洛 (Maslow)

在研究了許多歷史上偉人

共同的人格特質之後,

更詳細地描繪出

“自我實現者” (成長者) 的畫像。

自我實現者有下列 16 個特色:

趕緊接著看下去...

(贊助商連結...)

1.他們的判斷力超乎常人

對事情觀察得很透徹,

只根據現在所發生的一些事,

常常就能夠正確地

預測將來事情會如何演變。

2.他們能夠接納自己、接納別人,
也能接受所處的環境

無論在順境或逆境之中,

他們能安之若命,處之泰然。

雖然他們不見得喜歡現狀,

但他們會先接受這個

不完美的現實

(不會抱怨為何只有半杯水),

然後負起責任改善現狀。

3.他們單純、自然而無偽

他們對名利沒有強烈的需求,

因而不會戴上面具,

企圖討好別人。

有一句話說:

“偉大的人永遠是單純的。”

我相信,

偉人的腦子裡滿有智慧,

但常保一顆單純善良的心。

4.他們對人生懷有使命感

因而常把精力用來

解決與眾人有關的問題。

他們也較不以自我為中心,

不會單顧自己的事。

(圖片翻攝自網路)

5.他們享受獨居的喜悅,
也能享受群居的快樂

他們喜歡有獨處的時間

來面對自己、充實自己。

6.他們不依靠別人
滿足自己安全感的需要

他們像是個滿溢的福杯,

喜樂有餘,

常常願意與人分享自己,

卻不太需要向別人收取什麼。

7.他們懂得欣賞簡單的事物,
能從一粒細砂想見天堂

他們像天真好奇的小孩一般,

能不斷地從

最平常的生活經驗中

找到新的樂趣,

從平凡之中領略人生的美。

8.他們當中有許多人
曾經歷過“天人合一”的宗教經驗

(圖片翻攝自網路)

9.他們能從醜陋之中
看到別人善良可愛的一面

雖然看到人類

有很多醜陋的劣根性,

他們卻仍滿有悲天憫人之心。

10.他們交友不廣但深入

他們的朋友或許不是很多,

然而所建立的關係,

卻比常人深入。

他們可能有許多

淡如水的君子之交,

素未謀面,卻彼此心儀,

靈犀相通。

11.他們懂得尊重

他們比較民主,

懂得尊重不同階層、

不同種族、不同背景的人,

以平等和愛心相待。

12.他們有智慧明辨是非

不會像一般人用絕對二分法

(“不是好就是壞”

或“黑人都是懶惰鬼”)分類判斷。

13.他們說話含有哲理,
也常有詼而不謔的幽默

(圖片翻攝自網路)

14.他們心思單純,
像天真的小孩,極具創造性

他們真情流露,

歡樂時高歌,悲傷時落淚,

與那些情感麻木,

喜好“權術”、“控制”、

“喜怒不形於色”的人截然不同。

15.他們的心態開明

他們的衣著、生活習慣、

方式、處世為人的態度,

看起來比較傳統,保守,

然而,他們的心態開明,

在必要時

能超越文化與傳統的束縛。

16.當他們專心起來,
對其他事毫不在意

他們也會犯一些天真的錯誤,

當他們對真善美執著起來時,

會對其他瑣事心不在焉。

例如愛迪生有一次做研究太過專心,

竟然忘了自己是否吃過飯,

朋友戲弄他,說他吃過了,

他信以為真,拍拍肚皮,

滿足地回到實驗室繼續工作。

(圖片翻攝自網路)

據馬斯洛的估計,

世上大概只有 1% 的人,

最後能成長到上述這種

“不惑”、“知天命”、“耳順”、

“隨心所欲而不逾距”、

圓融逍遙、充滿智慧的人生境界。

成長是必須付代價的,

因為成長永遠包含著冒險、

面對未知、嘗試新經驗、

擴展個人的極限與改變。

若不必成長,

我們就不用改變自己,

不用面對未知的危險,

更不用花心神面對生活的挑戰,

從各種選擇中做出新的決定。

我不敢期望每個人

都能達到這個境界,

然而我相信,

當我們愈趨近這種境界時,我們的人生會愈有喜樂、愈有意義。

Reference:

http://www.cmoney.tw/notes/note-detail.aspx?nid=47214

CPU 的最小執行單位是 Microoperation

1. CPU 的最小執行單位是 Microoperation
2. 一條 Instruction 裡包含 opcode、mode、address (視不同 CPU) 等
opcode 指定要做的運算,一個 opcode 會執行「一群」 Microoperation
3. Instruction 以 binary 呈現,就是所謂的「機械碼」
4. 機械碼難記 -> 組合語言
5. 所有組合語言指令不可能都有一一對應的機械碼,通常內部電路只 implement
必要的 Instruction,其他的 Instruction 由程式或硬體 (某些指令最佳化
時) 來執行一串的 Instructions 完成

最基本的 CPU 是如此...

===

唉!這個話題扯了半天,還是圍在組語的現行用途在繞。新一批程式菜鳥
還沒搞清楚組語是啥東東就已經被 VB, Delphi, CBC 這些 RAD 給寵壞了
,看到學校老師還在教組語就哇哇叫,大加撻伐,上網來數落組語的不是
。我們先來釐清一個先後因果關係,搞清楚了,菜鳥們就不會再聊組語會
不會淘汰這種超爆笑的話題了。這種問題就跟問『人不會是細胞組成的』
一樣搞笑。
CPU 是電腦的運算中心,它由電路組成。控制電路,由CPU設計小組所規畫
的機械碼來控制。為了能更方便撰寫機械碼,於是把每一個機械碼指令用一
個簡單明瞭的指令代替,這就是『組合語言』。但每一個組合語言(機械碼)
所做的工作實在太小了,於是把『一堆』組合語言指令集合成一個完整的動
作,這就是高階程式語言。程式寫多了,又覺得高階語言指令所做的動作又
太少,再集合數個指令衍生出物件類別,這就是物件導向程式語言。
如此一直演變下去,程式語言越來越簡單,但每一個指令所包含的組合語言
碼卻越來越多,所以後代程式語言所產生的執行檔也就越大。因為它是由組
語開始一層包一層地衍生出來的,過去高階語言要編譯成執行碼,都是先翻
譯成組語,再由組語組譯成執行檔。現在一開始就用 RAD 的菜鳥們誰還知道
這個步驟啊?知道的話就不會問這種問題了,還可以討論這麼久哩!
總而言之,組合語言等於是控制 CPU 的電路設計。有 CPU 就有組語,這不
是誰想淘汰它就能淘汰得了的。除非他的電腦不用 CPU 。否則,只要你在寫
程式,就是在用組合語言,不同的只是這個組合語言是由你自己寫,還是高階
語言編譯器幫你產生而已。

Friday, December 25, 2015

Where should I start learning Assembly?

Where should I start learning Assembly?


Code by Charles Petzold [1] is a fantastic introduction. It isn't so much the nitty gritty "this opcode performs this operation, and these are all the tricks to making it do things, edge cases and things you should worry about" and more along the lines of "what opcodes should a CPU have, and how do those translate into electricity flowing through physical wires?" I feel like really thinking through that book made MIPS and x86 assembly much easier for me.

http://www.charlespetzold.com/code/

In addition, if you like "Code", I'd recommend The Pattern on the Stone by Danny Hillis (creator of Thinking Machines' Connection Machine supercomputer).

It's much shorter than "Code" but covers basically the same ground much more quickly, but Code might be better first because it really explains it thoroughly.
===
If you already know C, you can start out by looking at the machine code generated by your compiler with "objdump -d" on Linux and "otool -tV" on Mac. Start experimenting by writing out C constructs like functions, loops, switch statements, etc., and just looking at what the generated code looks like.

Of course, to do that, you need to find the manual for your machine architecture. The x86 manuals are, for example, available here:

http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

You also then start to notice things like the operating system specific application binary interfaces (ABI):

http://www.x86-64.org/documentation/abi.pdf

and object file formats such as ELF that's used in Linux:

http://www.skyfree.org/linux/references/ELF_Format.pdf

or Mach-O used in Mac OS X:

https://developer.apple.com/library/mac/documentation/developertools/conceptual/machoruntime/reference/reference.html

You can also do the same thing with the JVM and look at its JIT-generated machine code with the '-XX:+PrintCompilation' option:

http://stackoverflow.com/questions/13086690/understanding-the-output-of-xxprintcompilation

Reference:

https://news.ycombinator.com/item?id=7143186

Thursday, December 24, 2015

To let other different users login to Amazon's EC2 instance

Solution 1:

# vim /etc/ssh/sshd_config

PasswordAuthentication = yes

# systemctl restart sshd.service

Solution 2:

Add a new user:

# useradd testuser -m -c 'test user'

Switch to the new account so that newly created files have the proper ownership:

# sudo su - testuser

$ mkdir ~/.ssh

$ chmod 700 ~/.ssh

Note: this step is very important; without these exact file permissions, you will not be able to log into this account using SSH.

$ touch ~/.ssh/authorized_keys

$ chmod 600 ~/.ssh/authorized_keys

Login to Amazon Web Services console. Then, go to EC2 and create a new key pair: machineName_userName.

It will generate a machineName_userName.pem file for you to download.

Upload machineName_userName.pem to your Linux instance.

Change the permission of the machineName_userName.pem:

# chmod 400 machineName_userName.pem

Retrieving the Public Key for Your Key Pair on Linux:

# ssh-keygen -y

When prompted to enter the file in which the key is, specify the path to your .pem file; for example:

/path_to_key_pair/machineName_userName.pem

The command returns the public key:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE

Edit the authorized_keys file with your favorite text editor and paste the public key for your key pair into the file:

# sudo su - testuser

$ vim ~/.ssh/authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE

Remove the private key from the server if you do not need it anymore:

# rm /path_to_key_pair/machineName_userName.pem

Reference:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws

Wednesday, December 23, 2015

compare the rows in two Tables and show difference

compare the rows in two Tables and show difference

Summary: in this tutorial, you will learn how to compare two tables to find the unmatched records.

In data migration, we often have to compare two tables and identify a record in one table that have no corresponding record in another table.

For example, we have a new database whose schema is different from the legacy database. Our task is to migrate all data from the legacy database to the new one and verify that the data were migrated correctly. In order to check the data, we have to compare two tables, one in the new database and one in the legacy database, and identity the unmatched records.

Suppose, we have two tables: t1 and t2 . The following steps compare two tables and identify the unmatched records:

First, use the UNION statement to combine rows in both tables; include only the columns that needs to compare. The returned result set is used for the comparison.

SELECT t1.pk, t1.c1
FROM t1
UNION ALL
SELECT t2.pk, t2.c1
FROM t2

Second, group the records based on the primary key and columns that need to compare. If the values in the columns that need to compare are identical, the COUNT (*) returns 2, otherwise the COUNT (*) returns 1. See the following query:

SELECT pk, c1
FROM
 (
   SELECT t1.pk, t1.c1
   FROM t1
   UNION ALL
   SELECT t2.pk, t2.c1
   FROM t2
)  t
GROUP BY pk, c1
HAVING COUNT(*) = 1
ORDER BY pk

If values in the columns involved in the comparison are identical, no row returns.

MySQL compare two tables example

Let’s take a look at an example that simulate the steps above.

First, create 2 tables with a similar structure:

CREATE TABLE t1(
 id int auto_increment primary key,
    title varchar(255) 
);

CREATE TABLE t2(
 id int auto_increment primary key,
    title varchar(255),
    note varchar(255)
);

Second, insert some data into both t1 and t2 tables:

INSERT INTO t1(title)
VALUES('row 1'),('row 2'),('row 3');

INSERT INTO t2(title,note)
SELECT title, 'data migration'
FROM t1;

Third, compare values of id and title column of both tables:

SELECT id,title
FROM (
SELECT id, title FROM t1
UNION ALL
SELECT id,title FROM t2
) tbl
GROUP BY id, title
HAVING count(*) = 1
ORDER BY id;

No row returns because there is not unmatched records.

Fourth, insert a new row into the t2 table:

INSERT INTO t2(title,note)
VALUES('new row 4','new');

Fifth, execute the query to compare the values of title column in both tables again. The new row, which is the unmatched row, should return.

MySQL compare two tables example

In this tutorial, you have learned how to compare two tables based on specific columns to find the unmatched records.

Reference:

http://www.mysqltutorial.org/compare-two-tables-to-find-unmatched-records-mysql.aspx

Monday, December 21, 2015

Setting up the network access on Windows Mobile device

Setting up the network access on Windows Mobile device

For the Emulator:

In Visual Studio > Windows Mobile 6 Professional VGA (top-left corner) > Device Options > Property:

Click on "Emulator Options" > Network > check "Enable NE2000 PCMCIA network adapter and bind to" and select your network card.
===
When the virtual machine is launch, go to settings > Connections > Network card:

My network card connects to: Work

Select "NE2000 Compatible Ethernet Driver" and click on "Edit". Then, input your IP addresses and Name Servers.
===
When the virtual machine is launch, go to settings > Connections > Connections > Advanced > select networks:

On "Programs that automatically connect to Internet should connect using: "My work network" > click on "Edit" > Proxy Settings > Check "This network connects to the Internet

To enable the scan function on the Windows Mobile device

You will need to install datawedge 3.4 in order to enable the scan function on the Windows Mobile device.

Wednesday, December 16, 2015

Quickly finding and debugging jQuery event handlers with findHandlersJS

Method 1:
Below JQuery 1.7, type this in console:

$('#myId').data('events');
or
$($0).data('events');

Above JQuery 1.7, type this in console:

$._data($('#myId').get(0), "events");
or
$._data($($0).get(0), "events");

Note: that $0 is a special dev tools variable which always points to the last element selected in the "Elements" tabs.

Note: expand "Object" > expand "click" > expand 0 > right click on "handler" > click on "Function definition".

Method 2:

Install a Chrome Extension called Visual Event. It works wonderful.

Method 3:

Go to Google Chrome console, enter:

monitorEvents($('.current'), 'click');

Note: that $0 is a special dev tools variable which always points to the last element selected in the "Elements" tabs.

Method 4:
In Chrome, you can use getEventListeners.


  1. Open Developer Tools
  2. Select the element you're interested in
  3. Type this the console: getEventListeners($0)
  4. Hit enter.


An object mapping event names to their handlers should be returned. Note that $0 is a special dev tools variable which always points to the last element selected in the "Elements" tabs.

Method 5:

You can get findHandlersJS in github here. You can just copy and paste the raw javascript code to chrome’s console window and just start using it, or if you want to use it in your project just make sure you add it after jQuery

Go to Google Chrome console, enter:

findEventHandlers('click', '#myDiv');
Or
findEventHandlers('click', '*');

findEventHandlers.js:
var findEventHandlers = function (eventType, jqSelector) {
    var results = [];
    var $ = jQuery;// to avoid conflict between others frameworks like Mootools

    var arrayIntersection = function (array1, array2) {
        return $(array1).filter(function (index, element) {
            return $.inArray(element, $(array2)) !== -1;
        });
    };

    var haveCommonElements = function (array1, array2) {
        return arrayIntersection(array1, array2).length !== 0;
    };


    var addEventHandlerInfo = function (element, event, $elementsCovered) {
        var extendedEvent = event;
        if ($elementsCovered !== void 0 && $elementsCovered !== null) {
            $.extend(extendedEvent, { targets: $elementsCovered.toArray() });
        }
        var eventInfo;
        var eventsInfo = $.grep(results, function (evInfo, index) {
            return element === evInfo.element;
        });

        if (eventsInfo.length === 0) {
            eventInfo = {
                element: element,
                events: [extendedEvent]
            };
            results.push(eventInfo);
        } else {
            eventInfo = eventsInfo[0];
            eventInfo.events.push(extendedEvent);
        }
    };


    var $elementsToWatch = $(jqSelector);
    if (jqSelector === "*")//* does not include document and we might be interested in handlers registered there
        $elementsToWatch = $elementsToWatch.add(document); 
    var $allElements = $("*").add(document);

    $.each($allElements, function (elementIndex, element) {
        var allElementEvents = $._data(element, "events");
        if (allElementEvents !== void 0 && allElementEvents[eventType] !== void 0) {
            var eventContainer = allElementEvents[eventType];
            $.each(eventContainer, function(eventIndex, event){
                var isDelegateEvent = event.selector !== void 0 && event.selector !== null;
                var $elementsCovered;
                if (isDelegateEvent) {
                    $elementsCovered = $(event.selector, element); //only look at children of the element, since those are the only ones the handler covers
                } else {
                    $elementsCovered = $(element); //just itself
                }
                if (haveCommonElements($elementsCovered, $elementsToWatch)) {
                    addEventHandlerInfo(element, event, $elementsCovered);
                }
            });
        }
    });

    return results;
};

https://blinkingcaret.wordpress.com/2014/01/17/quickly-finding-and-debugging-jquery-event-handlers/
http://www.euperia.com/development/inspect-jquery-event-handlers/969
http://stackoverflow.com/questions/23472334/how-to-find-what-code-is-run-by-a-button-element-in-chrome-using-developer-tools
https://divshot.com/blog/tips-and-tricks/ignoring-library-code-while-debugging-in-chrome/
http://stackoverflow.com/questions/5198108/are-there-tools-techniques-to-debug-jquery-event-handlers

Tuesday, December 15, 2015

Debugging applications with strace

Debugging applications with strace

There are times, when we get an application and need to find out what it does fast. We don’t have the time to read the source code. Fortunately there are multiple tools to our rescue, one of which is the strace Linux utility. strace means system call trace, it shows us every system call the application does, such as opening or reading a file, writing data to a network socket. It’s not a magic pill, it won’t show the internal working of the application, but it’s still very useful to find out what it does externally (IO operations and such).

The basic use of strace is to run an application directly:

strace ls /proc

You’ll get is a list of system calls the process has done:

execve("/bin/ls", ["ls", "/proc"], [/* 19 vars */]) = 0
brk(0)                                  = 0x1097000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0bb0334000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=22620, ...}) = 0
mmap(NULL, 22620, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0bb032e000
close(3)                                = 0
open("/lib64/librt.so.1", O_RDONLY)     = 3
...

What you will most probably interested in are the stat, open, read, write, readv, writev, recv, recvfrom, send and sendto operations. Adding a filter for those makes the strace much more useful:

proxy / # strace -e trace=open,read,write,readv,writev,recv,recvfrom,send,sendto ls /proc

open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib64/librt.so.1", O_RDONLY)     = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\"\0\0\0\0\0\0"..., 832) = 832
open("/lib64/libcap.so.2", O_RDONLY)    = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\26\0\0\0\0\0\0"..., 832) = 832
open("/lib64/libacl.so.1", O_RDONLY)    = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340#\0\0\0\0\0\0"..., 832) = 832
open("/lib64/libc.so.6", O_RDONLY)      = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\356\1\0\0\0\0\0"..., 832) = 832
open("/lib64/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\\\0\0\0\0\0\0"..., 832) = 832
open("/lib64/libattr.so.1", O_RDONLY)   = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \26\0\0\0\0\0\0"..., 832) = 832
open("/proc", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
write(1, "1      13239  14532  22092  2209"..., 1761      13239  14532  22092  22094  22096  247  447  574  8517   cpuinfo  fairsched   filesystems  kmsg     locks    mounts  self  swaps  sysrq-trigger  uptime      version  vz
) = 176
write(1, "13238  14496  14533  22093  2209"..., 16913238  14496  14533  22093  22095  22097  446  559  649  cmdline  devices  fairsched2  fs     loadavg  meminfo  net     stat  sys    sysvipc   user_beancounters  vmstat
) = 169

As you can see, the strings are truncated to a given length, so you don’t see everything. Adding the -s parameter lets you specify the string truncation length:

strace -s 999 ls /proc
As a result you’ll now see a lot more information at the cost of readability. This about covers directly running the application.

There however is one major pitfall with directly runnin strace: SUID doesn’t work. If you want to run a SUID binary like su, sudo, suexec, etc it simply won’t work as expected.

So what if we want to strace an already existing process? Nothing easier than that, the -p flag does just that:

strace -p 14681

strace will attach the process and show you what it does. Keep in mind that printing out a lot of information slows the process down.

If you need to track multiple processes (for example multiple processes of a webserver) you can just add multiple -p flags:

strace -p 20557 -p 20558 -p 2055

An other way to follow multiple processes is using the -f flag to follow forks. (Forks are when a process spawns an other process.)

strace -f -p 20557

This about covers the basic usages of strace. To get more detailed information about a specific system call, use man syscallname. Needless to say you can only attach processes that run under your username if you are not root.

Examples

Let’s see an example. I have created a hello world application and want to trace it on my local Apache installation. First I get the process ID’s of Apache:

root@janoszen-imac:~# ps aux | grep apache | grep -v grep

root      6883  0.0  0.2 132136  8560 ?        Ss   13:18   0:00 /usr/sbin/apache2 -k start
www-data  6888  0.0  0.1 132616  6732 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6889  0.0  0.1 132200  5696 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6890  0.0  0.1 132600  6712 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6891  0.0  0.1 132160  5056 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6892  0.0  0.1 132160  5056 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6894  0.0  0.1 132160  5056 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6895  0.0  0.1 132160  5056 ?        S    13:18   0:00 /usr/sbin/apache2 -k start
www-data  6896  0.0  0.1 132160  5056 ?        S    13:18   0:00 /usr/sbin/apache2 -k start

The second columns contains the process ID’s (PID’s), which have to be used for strace. To create a list for strace you can use the following line:

root@janoszen-imac:~# ps aux | grep apache | grep -v grep | awk ' { print $2 } ' | xargs -i echo -n ' -p {}'
-p 6883 -p 6888 -p 6889 -p 6890 -p 6891 -p 6892 -p 6894 -p 6895 -p 6896

Next step, run the strace and do a single request:

root@janoszen-imac:~# strace -e trace=open,read,write,readv,writev,recv,recvfrom,send,sendto -s 999 -p 6883 -p 6888 -p 6889 -p 6890 -p 6891 -p 6892 -p 6894 -p 6895 -p 6896


Process 6883 attached - interrupt to quit
Process 6888 attached - interrupt to quit
Process 6889 attached - interrupt to quit
Process 6890 attached - interrupt to quit
Process 6891 attached - interrupt to quit
Process 6892 attached - interrupt to quit
Process 6894 attached - interrupt to quit
Process 6895 attached - interrupt to quit
Process 6896 attached - interrupt to quit
[pid  6892] read(8, "GET /test.php HTTP/1.1\r\nHost: stuff.localhost\r\nUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nReferer: http://stuff.localhost/\r\nCache-Control: max-age=0\r\n\r\n", 8000) = 361
[pid  6892] open("/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  6892] open("/var/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  6892] open("/var/www/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  6892] open("/var/www/stuff.localhost/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  6892] open("/var/www/stuff.localhost/htdocs/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  6892] open("/var/www/stuff.localhost/htdocs/test.php/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOTDIR (Not a directory)
[pid  6892] open("/var/www/stuff.localhost/htdocs/test.php", O_RDONLY) = 9
[pid  6892] open("/dev/urandom", O_RDONLY) = 9
[pid  6892] read(9, "\255\263\316-\306C\273\2", 8) = 8
[pid  6892] open("/dev/urandom", O_RDONLY) = 9
[pid  6892] read(9, "9\326|\367v2\21\315", 8) = 8
[pid  6892] open("/dev/urandom", O_RDONLY) = 9
[pid  6892] read(9, "5\5\305,`J\201 ", 8) = 8
[pid  6892] writev(8, [{"HTTP/1.1 200 OK\r\nDate: Thu, 19 Apr 2012 11:29:29 GMT\r\nServer: Apache/2.2.20 (Ubuntu)\r\nX-Powered-By: PHP/5.3.6-13ubuntu3.6\r\nVary: Accept-Encoding\r\nContent-Encoding: gzip\r\nContent-Length: 32\r\nKeep-Alive: timeout=5, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\n\r\n", 273}, {"\37\213\10\0\0\0\0\0\0\3", 10}, {"\363H\315\311\311W\10\317/\312IQ\4\0", 14}, {"\243\34)\34\f\0\0\0", 8}], 4) = 305
[pid  6892] read(8, 0x7fa392c8e048, 8000) = -1 EAGAIN (Resource temporarily unavailable)
[pid  6892] write(6, "stuff.localhost:80 127.0.0.1 - - [19/Apr/2012:13:29:29 +0200] \"GET /test.php HTTP/1.1\" 200 305 \"http://stuff.localhost/\" \"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0\"\n", 200) = 200

As you can see, the first read() will show the request from the browser. Next the server reads the .htaccess files, which points out why using .htaccess files is a bad idea in a high performance solution. Finally the server reads the PHP file (and passes control to PHP). PHP then does some initialization on its own, that’s why it accesses /dev/urandom. Next you see the server write the response to the client and write to the access log.

As you can see, strace gives you a good idea about what the application does externally. I use strace with a wide variation of software, most of the time debugging PHP with it when the interpreter isn’t very helpful. I hope it helps getting on the trail of errors quickly. (Let me know, if it does.)

Reference:

http://www.janoszen.com/2012/04/19/debugging-applications-with-strace/

Sunday, December 13, 2015

銷售是一種態度,也是一種能力,銷售冠軍的 50條 黃金經驗

銷售是一種態度,也是一種能力,銷售冠軍的 50條 黃金經驗

1、當業績不好的時候,我會做兩件事情,一是盡可能地見大量的客人,二是主動去拜訪已經購車的老客戶。為了接觸到盡可能多的客人,在車展上,只要是表現出一丁點兒興趣的客戶,我都會上前遞名片,盡可能地和對方多聊幾句。

2、我不斷告誡自己,單靠外表和感覺無法看透客人,不論對方是誰,我都一視同仁,盡力做到最好,提供自己能提供的最完美的服務。

3、既然做了銷售,就要賣得比其他任何人都多,畢竟工作有目標才有動力,才會充滿樂趣。

4、既然橫豎都要工作,我當然希望可以開心地工作,而我的快樂同樣也會感染到客人,成就一次輕松、愉悅的對話。

5、在與客人交談的過程中,我發現,必須要以車子的相關話題作為切入點來進行對話,否則客人會覺得索然無味。

6、強調品質。我經常和客人說,德國本來就是一個質樸剛健,散發著匠人氣質的國家,而寶馬公司除了生產汽車之外,也是飛機引擎的知名制造商,所以車子的發動機性能是非常優秀的,而且每個零部件都經過了精雕細琢,追求完美。

7、勾起原來就有興趣的客人進一步了解商品的欲望,引起興趣缺乏的客人的強烈好奇心,是銷售的關鍵工作。要做到這一步,首先自己要對商品有一個深入的了解,準確記憶必要的數據,在任何時候都能對答如流,是至關重要的。

8、沒有比銷售自己為之著迷的產品更令人歡欣雀躍的了。

9、我心裏很清楚那些願意聽我介紹,與我交流的客人有多麽重要,我只想讓他們滿意,不想辜負他們的好意和願望。所以,不管是投訴、咨詢,還是稍稍有點難辦的要求,我都會站在客人的立場,盡自己最大的努力去幫助解決。

10、無論大小事,客人都願意找我接洽,而我總是讓客人覺得他隨時都可以找我商量,任何時候我都是可以靠得住的。

11、我一直覺得,對現有客人的售後跟蹤服務是一項很重要的工作,是最可能讓客人感到心滿意足的一個環節。

12、腦子裏只有“努力工作”四個字的人根本就沒有功夫理會心中的不安;但人如果**心、沒有一點不安的話,活動量就會減少,適度的工具或不安感有百利而無一害。

13、客人多是有一定身份的人,他們非常敏感,只要有一點點不對勁,他們都能準確地感受到,不管是什麽客人,不管來過幾次,我都會對他們的光臨表示高興和感謝。

14、銷售工作的出發點是奉獻精神,當我思考“怎樣才能讓客人滿意”這一問題的時候,我發現只有一個答案,那就是努力奉獻。懷著一顆感恩的心,不惜耗費時 間和精力,是通向客人內心深處的最佳捷徑。

15、客人能為我們抽出那麽多的時間,我們要為此心懷感激,可是,不少銷售人員總是很在意自己的時間,這根本就是本末倒置,客人給予的機會,給予的時間, 才是我們最值得珍惜的東西。

16、我一直不敢偷懶,因為你根本不知道會在哪裏偶然地就被客人看到,誰都有可能成為我們的下一位客人,所以絕對不可以讓他們看到我們偷懶的樣子。

17、我經常和客人聊很多東西,但我不會主動向他推銷任何東西,我和客人會私底下聊很多東西,就算不買車,也會時不時地見面聊聊天,然後,就像忽然想起來似的,客戶會主動提到買車,換車,接下來自然是水到渠成的事情了。

18、我不太善於說話,我根本模仿不來那些機靈,帥氣又幽默感十足的銷售人員的說話方式。即便是這樣,我的客人卻很喜歡我,為什麽會這樣子呢?我覺得,主要原因是我對客人充滿了熱情,始終保持尊敬,這種態度在客人面前是不會說謊的。

19、我發現,言多必失,不得要領卻自以為是地侃侃而談反而會引起客人的反感。能說會道並不是銷售的必要條件。我們一個勁兒地重復那些網上即可輕易查 看到的信息,客人聽了也不會有任何感覺,反倒會過多地耗費了客人寶貴的時間,不如鼓勵客人多說,我們用心傾聽。

20、就算不善言辭,能夠熱情地介紹產品就夠了,就算是木訥,只要充滿激情,就能打動客人。

21、要想充滿激情,必須真正地從心底裏喜歡自己正在銷售的商品。商品有優點,也有缺點,如果做不到連缺點都喜歡的話,是不可能滿懷激情地將產品介紹給客人的。

22、當客人對產品表現是滿意,對銷售人員也表現出非常滿意的時候,才可以靈活地使用價格優惠這一手段。如果客人要求我優惠5萬元,我卻無法做到,我 就會說:優惠5萬元可能比較困難,不過我會努力提供一個很接近的成交條件,關鍵是你要喜歡我們的產品,對我的服務也滿意。

23、要成為客人最終所選擇的銷售人員,我們必須比別人更加努力,如果和客人的人際關系、信賴關系等方面都無法優於別人,客戶是不會在第一時間就想起我們來的。

24、銷售這一行肯定有贏得客人信任的機會,決不可錯過任何一次機會。我們要一步一個腳印地去對待每一位客人,做好每一件事情,讓客人覺得事情交到我們手上是沒有任何需要擔心的地方的。

25、我從來沒有關過手機,不管是睡覺的時候,還是休息日,留給客人號碼的手機一直處於待機狀態,我一直充滿自信地對客人說“我手機24小時開機,有 什麽事兒您隨時來電話”,這句話總是能給客人帶來很大的安心感。而只要接到電話,不論什麽時候,我都會全力以赴,哪怕只能為客人做一點點事情,讓客人稍微 安心一點,那也是一種服務。

26、不管是聯系客人還是對客人的來電做出反饋,超出客人預計地迅速,往往會收到意想不到的效果。

27、做任何事情都要領先一步,機會就會相應的增加許多,要做第一個帶產品目錄拜訪客戶的銷售人員,一定要比任何人都快,每一步都走在前面。

28、每次接待客戶的最初三分鐘裏,首先要心懷感激的和客人寒暄:“非常感謝您在酷暑之中抽出時間來我們店”或者“感謝您從那麽多家店裏選中了我們”,甚至感謝客人百忙之中來到我們店,這些都是很好的寒暄方式,總能讓溝通氣氛一下子變得融洽起來。

29、銷售首先應該讓客人感到舒服,同一種商品,客人總是傾向於從感覺不錯的人手中購買。

30、對我來說,大多數來看寶馬車的客人都屬於有足夠財力用在購買高檔車的群體。他們或者是有社會地位,有高收入的成功人士,或者是真心愛車的人士,從各種不同的角度,我都能找到每一位客人值得尊敬的地方。

31、我發現開車來的客人多少都會因為搞不清楚停車的地方而感到不安,我就時刻註意展廳門外的動向,一旦發現情況就立刻飛奔出去引導。

32、單靠站著和客人聊一會兒是不可能把車子賣出去的,站著閑談不會有什麽進展,要拉近與客人之間的距離,讓兩者關系更進一步,我們必須要請客人坐下來面對面地詳談。

33、為了做到真心實意地關心客人,我經常向客人詢問三個問題“您為什麽會來看這輛車子呢?”“要怎樣才能像您這樣擁有購買這輛車的能力呢?”“您都經歷了什麽才取得這樣的成功呢?”34、我很少花大量時間去介紹我們的產品,我會盡量多地介紹我們的公司情況。我還會和客戶說寶馬到底是一個怎樣的品牌。我會和客人說我到寶馬汽車總部 工廠看到的情況,講公司的整個工作氛圍,歷史傳統和社會地位,講每一輛車是如何生產出來的。這些內容都是在產品目錄中沒有的,也是客人喜歡聽到的。

35、我經常熱情而全面地向客人講述我自己心目中的寶馬,直到客人被我所感染,他們會對我說“看來你真的很喜歡寶馬汽車嘛。”我不僅向客人介紹公司、 品牌故事以及產品,也要讓客人知道我們對自己所銷售的產品和自己的這份工作是充滿了熱愛的。但是我不會主動和他們聊宗教、政治、健康以及股票類的話題,我 試著聊過,但是吃過不少虧,所以現在幾乎不聊了。

36、當客人拘泥於報價,拘泥於價格,拘泥於優惠金額的時候,我就會習慣性的想想為什麽會這樣呢?我甚至會直接詢問客人“您為什麽總是拘泥於價格呢? 是不是我哪裏做得不好?”“您為什麽那麽介意於成交優惠呢?是不是我們的產品有哪些方面讓您不滿意?”當我向客戶提出這樣的問題的時候,他就會把內心的真 實想法告訴我了。所以,我發現,客戶的價格優惠或成交條件往往只是一個表面現象而已,我要做的是深入發掘客戶內心隱藏的本意。

37、在接待客人的時候,我一直保持視線位置盡量放得比客人低,遇到個子高的人,我會刻意將身體稍微前傾,做出向客人請教的姿勢。在保持上述姿勢的前提下,要註意客人對什麽感興趣,當客人有問題的時候,我會準確地給予回答,如果客人沒有問題,我就主動的上前詢問他的看法。

38、銷售人員沒有必要長得很帥氣,但是產品一定要時刻保持在最佳狀態。我們做銷售的不能提高產品本身的性能,也不能增加新的功能,但我們可以將產品最完美的一面呈現給客人,這就足夠了。

39、跳過試乘試駕環節的銷售人員似乎大有人在,可我一直都很重視這一環節,因為試乘試駕是讓客人愛上這輛車的最好方法,也是一下子拉近客人與銷售人員之間距離的做好機會。我覺得:一次試乘試駕=三次接待。

40、賣房子的時候最佳的洽談環境是在房子裏,賣車也是如此,畢竟銷售的是汽車,還是和客人坐在車裏談論汽車能取得更好的效果。

41、我覺得報價或者給優惠這些工作沒有什麽難處,就算是最新的銷售新人都能勝任。但是順利地說服客人試乘試駕,並在這一過程中通過車子來展示自己,卻 沒有那麽容易,所以每次試乘試駕我都給予12分的重視。

42、關註客人本身的事情是最基本的接待之道。客戶與銷售人員之間最愉快的話題之一就是客人的成功歷史。我經常問客人為什麽會考慮購買寶馬車,從而打開客人的話匣子。

43、不管是什麽商品,不管是什麽價格,客人都有自己的購買理由和動機,喜悅也由此而生。無視這些,只是一味的向客人介紹目前的優惠促銷活動,或者徑自希望客人允許自己報價的行為,又能怎麽樣呢?我一直都覺得這是很不可取的做法。

44、在客人面前,我們只能毫無保留地展示真實的自己,老實、拼命、流著汗拼命努力的自己,我們只要靠這些就足以贏得客人的認可。

45、不懂就是不懂,不知道的就去查閱資料,去請教別人,正是這種誠懇的態度讓我贏得了一個又一個客人的認可。那種以自己的知識壓制客人,用一種“連這個都不知道嗎”的態度來銷售的銷售人員是做不長久的。保持誠懇與謙虛的態度是非常重要的。

46、不管我們怎麽著急,如果不能讓客人身心放松、心情舒暢、他們是不會將心裏話合盤托出的。而要讓客人盡快吐露心聲,我們銷售人員就要盡量地以一種 自然的狀態和客人交談,讓客人沒有任何壓力,以便可以盡快找到彼此之間更多的共同點,比如出生地、學校、工作、興趣愛好或者所認識的某一位明星等。

47、客人快言快語的話,我就講話快一點兒,如果客人說話慢條斯理,我講話卻像一挺機關*的話,就很不協調,我時刻註意這一點,配合好客人的說話節奏。如果銷售人員口齒過於伶俐,講話時沒有任何停頓,客人就會容易因為沒有思考的時間而焦慮不安,結果適得其反。

48、我們一定要以絕佳的狀態來迎接客人,銷售人員的精氣神兒不足的話,就會在氣勢上輸給了客人,客人來店也會覺得掃興、無聊,從而失去購買興致,他就會想盡快地離開,去找“一家氣氛更好的店面”。無法讓客人由衷地感到來對了地方的話,客人是不會掏腰包購買的。

49、不管我們做得多麽好,客人也有不滿意的時候。不管客人多麽生氣,總歸有的事情能做到,有的事情做不到的。他說連一個小時也等不了,其實只是氣話,只 要我們認真對待,讓客人看到我們的確是在盡全力地想辦法解決問題,客人還是會諒解我們的。我不會向客人做出自己能力範圍之外的承諾,我會清楚地告訴他我能 做什麽,做不到什麽,以及接下來他應該考慮什麽,把這三點告訴他,他基本上都能理解我們的難處。

50、這麽多年來,什麽銷售方法我都用過,有一點是最值得肯定的,沒有哪位客人會從情緒消沈的銷售人員那裏購買商品。所以,你沒有自信不要緊,但一定要精神抖擻!

Reference:

http://blog.xuite.net/rlre1100/blog/302214341

Friday, December 11, 2015

【好物介紹】把瀏覽器當虛擬平台?

每次要跑虛擬機時,都要有一個Hypervisor,不管是原生或寄居架構,但不管是哪一種架構,總要有一個硬體平台吧?總要分配CPU、記憶體或磁碟空間吧?下面這個Linux,卻是真正把VM的層次拉高到最上層:瀏覽器。這是一個用Javascript重寫的Linux核心,而Javascript的執行平台正是瀏覽器!曾經有人懷疑這只是一個模擬Linux的介面而已,但現在已證實是真正的Linux核心了。


Fabrice Bellard是誰應該不用介紹了,是ffmpeg、QEMU的原創人,高中時就開發出LZEXE這個壓縮軟體,不但是有名的電腦工程師,也是有名的數學家,這邊可以看到Fabrice Bellard的維基介紹。

這個用Javascript寫出來的Linux不但可以執行,更可以用來學習Linux的指令,如vi等。大家就到

http://bellard.org/

到這邊來玩玩吧!

Reference:
http://vaemon.com/article/1363.html
http://www.softwarequalityconnection.com/2011/03/fabrice-bellard-portrait-of-a-superproductive-programmer/

===

A PC emulator in Javascript (a recent browser is required): how much time takes your browser to boot Linux ?
2700 billion decimal digits of Pi computed with a desktop computer.
Analog and Digital TV (DVB-T) signal generation by displaying an image on a PC display.
QEMU is a generic machine emulator and virtualizer.
FFMPEG, the Open Source Multimedia System. I launched this project in year 2000 and led it during several years.
TCC is a tiny but complete ISOC99 C compiler which enables you to use C as scripting language. TCC has its roots in the OTCC project. The TCCBOOT boot loader demonstrate the speed of TCC by compiling and launching a Linux kernel in less than 15 seconds.
QEmacs (for Quick Emacs) is an emacs clone I began to learn Unicode rendering algorithms, text buffers manipulation and XML/HTML/CSS parsing.
OTCC is a very small self-compiling compiler for a subset of C I wrote to win the 2001 edition of the International Obfuscated C Contest.
TinyGL: a Small, Free and Fast Subset of OpenGL.
An online Scientific Web Calculator.
Pi formulas, algorithms and computations.
tiny C program to print the biggest known prime number.

19 ffmpeg commands for all needs

ffmpeg is a multiplatform, open-source library for video and audio files. I have compiled 19 useful and amazing commands covering almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more.

Getting infos from a video file
ffmpeg -i video.avi
Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg
This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.
Turn a video to X images
ffmpeg -i video.mpg image%d.jpg
This command will generate the files named image1.jpg, image2.jpg, …
The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.
Encode a video sequence for the iPpod/iPhone
ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4
Explanations :
  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 128kb/s
  • Video codec : mpeg4
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4
Explanations :
  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 32kb/s
  • Video codec : xvid
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Explanations :
  • Source video : source_video.avi
  • Audio bitrate : 192kb/s
  • output format : mp3
  • Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 128k -ar 44100 -b 512k -r 15 -s 640x480 -f flv video_finale.flv
Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
Or:
ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg
Explanations :
  • target pal-dvd : Output format
  • ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
  • aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg
Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

Reference:
http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs