Monday, December 06, 2010

host the Primary Domain from a subfolder

http://helpdesk.hostmonster.com/index.php/kb/article/000347

# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]

quite usefull

Friday, November 26, 2010

Android kernel dependency

                =============
                A N D R O I D
                =============

Copyright (C) 2009 Google, Inc.
Written by Mike Chan <mike@android.com>

CONTENTS:
---------

1. Android
  1.1 Required enabled config options
  1.2 Required disabled config options
  1.3 Recommended enabled config options
2. Contact


1. Android
==========

Android (www.android.com) is an open source operating system for mobile devices.
This document describes configurations needed to run the Android framework on
top of the Linux kernel.

To see a working defconfig look at msm_defconfig or goldfish_defconfig
which can be found at http://android.git.kernel.org in kernel/common.git
and kernel/msm.git


1.1 Required enabled config options
-----------------------------------
After building a standard defconfig, ensure that these options are enabled in
your .config or defconfig if they are not already. Based off the msm_defconfig.
You should keep the rest of the default options enabled in the defconfig
unless you know what you are doing.

ANDROID_PARANOID_NETWORK
ASHMEM
CONFIG_FB_MODE_HELPERS
CONFIG_FONT_8x16
CONFIG_FONT_8x8
CONFIG_YAFFS_SHORT_NAMES_IN_RAM
DAB
EARLYSUSPEND
FB
FB_CFB_COPYAREA
FB_CFB_FILLRECT
FB_CFB_IMAGEBLIT
FB_DEFERRED_IO
FB_TILEBLITTING
HIGH_RES_TIMERS
INOTIFY
INOTIFY_USER
INPUT_EVDEV
INPUT_GPIO
INPUT_MISC
LEDS_CLASS
LEDS_GPIO
LOCK_KERNEL
LkOGGER
LOW_MEMORY_KILLER
MISC_DEVICES
NEW_LEDS
NO_HZ
POWER_SUPPLY
PREEMPT
RAMFS
RTC_CLASS
RTC_LIB
SWITCH
SWITCH_GPIO
TMPFS
UID_STAT
UID16
USB_FUNCTION
USB_FUNCTION_ADB
USER_WAKELOCK
VIDEO_OUTPUT_CONTROL
WAKELOCK
YAFFS_AUTO_YAFFS2
YAFFS_FS
YAFFS_YAFFS1
YAFFS_YAFFS2


1.2 Required disabled config options
------------------------------------
CONFIG_YAFFS_DISABLE_LAZY_LOAD
DNOTIFY


1.3 Recommended enabled config options
------------------------------
ANDROID_PMEM
ANDROID_RAM_CONSOLE
ANDROID_RAM_CONSOLE_ERROR_CORRECTION
SCHEDSTATS
DEBUG_PREEMPT
DEBUG_MUTEXES
DEBUG_SPINLOCK_SLEEP
DEBUG_INFO
FRAME_POINTER
CPU_FREQ
CPU_FREQ_TABLE
CPU_FREQ_DEFAULT_GOV_ONDEMAND
CPU_FREQ_GOV_ONDEMAND
CRC_CCITT
EMBEDDED
INPUT_TOUCHSCREEN
I2C
I2C_BOARDINFO
LOG_BUF_SHIFT=17
SERIAL_CORE
SERIAL_CORE_CONSOLE


2. Contact
==========
website: http://android.git.kernel.org

mailing-lists: android-kernel@googlegroups.com

Sitex 2010

Sunday, November 14, 2010

mount share folder to local on arch

mount -t vboxsf Share /mnt/share

Thursday, November 11, 2010

吴敬琏:十二五最紧迫的是全面改革

http://finance.sina.com.cn/leadership/crz/20101111/03208934075.shtml
这个竟然没有被和谐掉?!

--------

  他,最早在国内提出并倡导市场经济理论;他,是经济理论界"市场经济论"和"整体改革论"的主要代表人物;他,因坚持市场化改革被称为"吴市场";他,是吴敬琏。

  舆论把华尔街妖魔化了

  新京报:今年有部叫做《华尔街》的纪录片很火,我看了好几遍了。你是这部片子的总顾问对吧?

  吴敬琏:对,片子的导演李成才是我的老朋友,他拍《大国崛起》时我们就认识了。

  新京报:平时工作和研究那么忙,怎么会想起做一部纪录片呢?

  吴敬琏:成才要拍片子我肯定要支持;美国的经济学家很多也做演说,做讲座。

  另外,我感觉金融危机后,舆论把华尔街妖魔化得比较厉害,这样不好。我希望有一种理性的声音和态度。

  新京报:如果让你用一句话介绍华尔街,你会怎么介绍?

  吴敬琏:我不会用这种方式介绍,现在社会太复杂,你把他简化了以后,一定有歧义。

  新京报:你觉得华尔街最值得我们学习的地方是什么?

  吴敬琏:不断地变革。

  股市正常化信息需对称

  新京报:《华尔街》中讲述了美国市场发展史,如果和美国股市相比,你觉得当前的中国股市处于哪个历史阶段?

  吴敬琏:十九世纪末期吧,美国人管那个时代叫强盗贵族时代。比如,那时候美国开发西部,如果谁承修了一条铁路,铁路两边的地就给他了,然后找银行、政府给钱,铁路其实不是他自己的钱修的,还占了大片的土地。

  有一本书就叫《强盗贵族》,就一个一个地讲他们的故事,包括摩根、洛克菲勒、斯坦福(均为华尔街大佬)等等。

  这本书后来得了普利策奖。

  新京报:为什么认为我们的股市处于那个时期?

  吴敬琏:股市要正常化,政府监管、证券公司以及媒体,都需要解决信息不对称的问题。但是他们都可能发生扭曲。政府监管尤其要解决信息不对称,但是如果有些官员想的不是这个,他们想的是寻租,就会利用各种行政许可、审批来寻租。

  高西庆(中投公司总经理)写过一篇文章谈两种监管路线:一种监管路线的要点是强制性的信息披露制度,这样来解决信息不对称的问题;另一种叫实质性审批制度。中国就是用的后一种制度,后一种制度很容易造成权力寻租。

  私募好多不真正做私募

  新京报:你刚才讲到寻租,能举个例子吗?

  吴敬琏:比如现在私募基金的问题就非常严重。我感觉,私募基金好多都不是真正做私募基金了。

  私募基金和风险投资的价值就在于,能够帮助你改善整个企业的战略、管理,所以一般都培育好几年,平均大概要五六年。但目前我们的私募基金不是这样。现在有个说法叫做"临门一脚",就是你条件都具备了,我就找你了,我要入股。

  新京报:证券公司存在这种情况吗?

  吴敬琏:证券公司本来是中介,因为他本来可以有研究班子,可以研究股票,然后给投资者说买哪个股票能够赚钱。就像《华尔街》里讲的那家,他把他们的分析全部公布到网上,就能起到很好的作用。可中国有些证券公司和投资银行不是这样,他们操纵市场、内幕交易,都干。为什么罗斯福当时要分业经营呢,就是因为他玩这些东西。

  新京报:没有监督的权力会导致腐败。

  吴敬琏:对,所以这里面就是人性的问题。"文化大革命"想把人性改了,想通过运动斗私批修把人性净化了,结果搞得一塌糊涂。

  媒体是信披的重要一环

  新京报:我记得你以前曾经提过一个"权贵资本主义"的说法。

  吴敬琏:现在仍然是这个说法。权贵资本主义就是官僚资本主义。这种情况越来越严重了。

  新京报:你觉得在这种情况下,媒体应该做些什么?

  吴敬琏:媒体的作用很重要,是信息披露里面的重要一环。前不久我给《凤凰周刊》写祝词,我说"在四十年代的时候,中共领导人毛泽东,和党报延安《解放日报》、重庆《新华日报》都高度评价了罗斯福的四大自由。但是我觉得现在看起来,罗斯福的四大自由还是有局限性。

  现在看来一个最重要的自由,就是信息传播的自由"。

  媒体在促进信息对称上,可以起到很好的作用。但是媒体在起这个作用的时候,又会有人利用这样一个职能谋求个人私利。所以《华尔街日报》的母公司道琼斯有一个守则,守则里面对于员工的个人投资规定得非常严格:持股时间不得短于六个月。

  最紧迫任务是全面改革

  新京报:你最近在经济增长模式方面写了一些文章,提了些建议。

  吴敬琏:主要是产业升级方面吧,现在看来在产业升级方面,广东的决心比较大。

  新京报:为什么这么说?

  吴敬琏:产业升级,我并不太看好转移。要升级原地增加知识含量,增加技术含量,改进产品,就可以。

  新京报:看来你不支持"腾笼换鸟"这个说法。

  吴敬琏:我觉得"腾笼换鸟"这个说法有危险。我在广东其实也讲到了这些。

  腾笼以后,凤凰不来怎么办?后来他们也改了说法,叫"筑巢引凤"什么的。

  新京报:"十二五"规划中,你认为最紧迫的任务是什么?

  吴敬琏:一个全面的改革。经济上,主要就是要减少政府、国企控制的资源,要实现民进国退;司法上,要保证法律面前,人人平等,司法的审判要保证独立性。

  保护创新需要具体措施

  新京报:说到法律面前人人平等,搜狐董事长张朝阳曾经抱怨过,现在中国的经济环境保护创新很不够,搜狐被人剽窃创意最终起诉,结果被判各打五十大板。你怎么看?

  吴敬琏:我赞同张朝阳要保护创新的呼吁。我也挺好奇,他以前赚钱赚得很多,然后吃喝玩乐了,好像不太关心这些宏观的事,但近年这方面的表态不少,是个积极的表现。

  2003年我们做过调查,大多数的出口企业都说人民币不能升值,因为我们只有微薄的利润。但是在浙江,有一个老板就说,近期不升值,好。长期看,三五年如果继续这样,要出大事儿。因为没有人搞技术革新了。

  新京报:不搞技术革新了都怎么办?

  吴敬琏:像浙江北部这些服装出口什么的,一点创新都没有,样子都不改。怎么形成的?

  就是开始有少部分人搞了设计了,很少很少,然后呢,别人就抄。抄了以后,搞设计的当然不干了,不干就闹。闹到当地政府,政府就出来说"大家都是中国人,都是乡亲嘛,别打了,大家共享"。共享的结果,就是不再创新了。以至于形成一种风气,大家都等着,你要创新,我就抄。这样几年下来以后,问题就大了。

  新京报:"十二五"规划里也有很多鼓励创新的内容。

  吴敬琏:现在需要有具体措施,具体内容。现在司法地方化非常严重,我在你这儿搞一个发明,我拿着这个发明跑了,只要跑到另外一个地方,那个法院就会支持他。另外一种情况就是国企有些是政企不分的,就会获得行政力量来保护。

  应允许民间银行运行新京报:其实地方的民营企业发展不起来,金融业是不是也有原因?

  吴敬琏:应该反省,我们的正规金融为什么不够发达,民营企业没有办法拿到资金。

  新京报:你觉得正规金融不发达的原因是什么?

  吴敬琏:还是国有垄断。

  管制太严了。过度管制其实是不好的。

  新京报:前一段时间有传闻说,阿里巴巴想开一个银行。

  吴敬琏:我觉得很好。

  新京报:听说到监管层,这事就没下文了。

  吴敬琏:宁波的民营银行准备多少年了,五年以上了,还没有上市。

  新京报:不让民营银行上市,担心什么?

  吴敬琏:不知道,有一个专门的组织,由一百多位经济学家组成,专门去跟监管部门谈,应该允许民间银行运行。他们说可以,这样,你们来改造信用社。

  新京报:这好像是金融系统中比较显著的不良资产?

  吴敬琏:对,但是这些人说资产倒不怕,就是文化改不了。

  新京报:是国有银行的文化?

  吴敬琏:对,信用社其实也是国有的。

  保护中小企业要落实制度

  新京报:大量的创新其实来自中小企业,但是中小企业似乎压力很大。你怎么看这个现象?

  吴敬琏:今年第三季度以后国务院制定了"新36条",但是总的来说改善得不够好。1998年应对亚洲金融危机的时候,那些措施落实得比较好。所以,到了1999年、2000年,中小企业有一个急速增长。当时国企下岗职工有几千万,很快就解决了就业。

  现在保护中小企业,政府还是应该要从制度上来落实,光是号召大家要重视,恐怕还是不够的。

  新京报:你认为应该从哪里突破呢?

  吴敬琏:我说一个小事。

  我们有些地方,民间办了一些小额贷款、微小贷款,最高限额2万、3万那种微小贷款,民间办得不错,但是资金量有限。吴晓灵(人民银行原副行长,全国人大财经委副主任)就提出来过,建议我们的国有大银行对这些小额贷款公司做批发。

  如果让国有大银行去做几千块钱的贷款成本太高,这种贷款国有大银行很难做。吴晓灵建议国有大银行批发,比如说贷100万给一个声誉比较好、经过审核的小额贷款公司,然后由它再去做零售。

  转变方式要创造创新

  新京报:你对"十二五"规划有什么建议?

  吴敬琏:老有人问我"十二五"会怎么样。其实"十二五"基本的调子和方向和"十一五"是一样的。

  我们其实有很好的"十一五"规划,但是执行的情况并不理想。

  世界增长委员会主席、诺贝尔奖获得者迈克尔。斯班斯,前段时间受邀做"十二五"研究,我跟他座谈了几次。他看了我们的"十一五",听了发改委的一些司长、秘书长讲"十一五"的过程以后,他评价非常高。但是他说,为什么这个上面写的东西看来并没有发生。其实,落实是最根本的问题。

  新京报:你认为该如何落实呢?

  吴敬琏:"十一五"的时候就讨论过,经济发展方式要转变。其实,"九五"计划里面就提到经济方式转变的问题了。为什么"九五"没有落实呢?所以看起来,转变经济发展方式有制度性障碍。

  新京报:制度性障碍体现在哪里?

  吴敬琏:大概有四个:第一,把GDP增长看作政绩的首要标志,追求高GDP;第二,政府掌握了太多的资源控制权力,各级政府,比如土地、贷款。这两条一来,各级政府都运用资源的权力去搞政绩工程、形象工程,方式就转变不过来了;第三,财政体制。财税体制迫使各级政府官员都要去搞GDP,不然它日子很难过;第四,价格扭曲。各种资源价格太低,就鼓励人们浪费资源。

  要转变增长方式,就要提高技术含量,要鼓励创造创新,要提高附加值。

  本报记者阳淼

  "货币超发必然 制造股市泡沫"

  货币超发有两个原因:一个是为了刺激经济,一个是为了人民币不升值,去收购美元,收购外汇。你看最近升值很快,如果升值到了位就不需要发票子去买外汇了。

  Q:你认为明年中国经济是否会出现明显的通胀情况?

  A:目前我们国家处于货币超发的状态,这必然会造成通胀,制造股市泡沫,抬高房价。超发有两个原因:一个是为了刺激经济,一个是为了人民币不升值,去收购美元,收购外汇。你看最近升值很快,如果升值到了位就不需要发票子去买外汇了。

  中美两国存在经济结构差异,美国储蓄率很低,是入超国家,中国是出超国家,因为我们有大量的人需要就业。这样造成的后果就是外汇多了,自然要求升值。要求升值就得压制它不升值,就得发钞票,去买外汇。

  Q:你对自己所在的行业在2011年的发展有怎样的预测?

  A:我们的资本市场比起九十年代还是有进步的。进步的动力来自多种多样的力量。比如说,有来自知识分子、中产阶级,以及一些有改革思想的和政治抱负的官员。但目前阻碍改革的力量也非常大。这两股力量现在还看不出来是谁强谁弱,只能说希望这个健康的趋向变得更强。

  Q:目前还在世的人中,你对谁的印象比较深刻?

  A:有一些人吧。比如梁小民不错,他能够把经济学说得很通俗,他写的那些短文也挺好。

Friday, October 22, 2010

VIM cook

http://www.oualline.com/vim-cook.html

Vim Cookbook

by Steve Oualline

This is the Vim cookbook page. It contains short recipes for doing many simple and not so simple things in Vim. You should already know the basics of Vim, however each command is explained in detail.

Each set of instructions is a complete package. Feel free to pick and choose what you need.

Contents

Character twiddling
Interactively replacing one word with another
Interactively replacing one word with another (command line method)
Replacing one word with another using one command
Moving Text (Vi style commands)
Moving Text (Visual mode)
Copying a block of text from one file to another
Copying a block of text from one file to another (Visual Method)
Sorting a section (Vi Style)
Sorting a section (Visual Method)
Dealing with Makefile and other SOB files
Formatting a text paragraph
Finding a procedure in a C program
Drawing comment boxes
Reading a man page
Removing carriage returns from MS-DOS file
Trimming the blanks off an end of line
Oops, I left the file write protected
Changing "Last, First" to "First Last"
How to edit all the files containing a given word
How to edit all the files containing a given word using the built-in grep


Character twiddling

If you type fast your fingers can easily get ahead of your mind. Frequently people transpose characters. For example the word "the" comes out "teh".

To swap two characters, for example "e" with "h", put the cursor on the cursor on the "e" and type xp.

The "x" command deletes a character (the "e") and the "p" pastes it after the cursor (which is now placed over the "h".)


Interactively replacing one word with another (n. method)

Suppose you want to replace every occurrence of the word "idiot" with the word "manager". But you want the chance to review each change before you do it.

Here's what you do:

1. 1G Go to the top of the document
2. /idiot<enter> Find the first occurrence of the word "idiot"
3. cwmanager Change the word (cw) to manager.
4. n Repeat the last search (find the next idiot.)
5. . Repeat the last edit (change one word to manager)
(If you do not want to change the word, skip this step.)

Repeat steps 4 and 5 until you have replaced all occurred.

The Virgin What!?

A church had just bought their first computer and were learning how to use it. The church secretary decided to set up a form letter to be used in a funeral service. Where the person's name was to be she put in the word "<name>". When a funeral occurred she would change this word to the actual name of the departed.

One day, there were two funerals, first for a lady named Mary, then later one for someone named Edna. So the secretary used global replace to change "<name>" to "Mary." So far so good. Next she generated the service for the second funeral by changing the word "Mary" to "Edna." That was a mistake

Imagine the Minister's surprise when he started reading the part containing the Apostle's Creed and saw, "Born of the Virgin Edna."


Interactively replacing one word with another (command line method)

Suppose you want to replace every occurrence of the word "idiot" with the word "manager". But you want the chance to review each change before you do it.

Execute the command:

:%s/\<idiot\>/manager/gc 

This command will make the change and pause after each change to give you a chance to confirm it. You can enter "y" to accept the change or "n" to not accept it.

The parts of this command are:

: Enter command mode
% Perform this command on all lines (% is a synomim for the first to last line.)
s The short form of the :substitute command.
/\<idiot\>/ This text specifies the text we are looking for wand want. The \< tells Vim to match a word start and the \> tells Vim to match the end of a word.
/manager/ The replacement text
gc The flags. These are
g
Global -- Change every occurance, not use the first one on each line
c
Confirm -- Ask before making each change

Replacing one word with another using one command

Suppose you want to replace every occurrence of the word "idiot" with the word "manager". No confirmation needed because all idiots are managers.

Use the command:

:%s/\<idiot\>/manager/g 

The parts of this command are:

: Enter command mode
% Perform this command on all lines (% is a synomim for the first to last line.)
s The short form of the :substitute command.
/\<idiot\>/ This text specifies the text we are looking for wand want. The \< tells Vim to match a word start and the \> tells Vim to match the end of a word.
/manager/ The replacement text
g Global flag -- This flag tells Vim to change every occurance on the line, not use the first one.

Moving Text (Vi style commands)

Suppose you want to move a paragraphs from the top of the document to the bottom. There are several ways of doing this. In this example, we do it using Vi style command. In the next section Moving Text (Visual mode) we do it using using the Vim visual commands.

To do the move the commands:

Command Explaination
1.   Move the cursor to the top of the paragraph you want to move.
2. ma Place a mark named "a" at this location. (Vim will give you no indication that this command has been executed. In other words, the screen will not change.)
3.   Move the cursor to the bottom of the paragraph to be moved.
4. d'a Delete to mark "a". This puts the deleted text in a cut buffer.
5.   Move the cursor to line where the text is to go. The paragraph will be placed after this one.
6. p Paste the text in below the cursor.

Moving Text (Visual Method)

Suppose you want to move a paragraphs from the top of the document to the bottom. There are several ways of doing this. In this example, we do it using the Vim Visual mode. In the previous section Moving Text (old method) we do it using using the Vi style commands.

To do the move the commands:

Command Explaination
1.   Move the cursor to the top of the paragraph you want to move.
2. v Start visual mode. (If you want to move only full lines, use the V command which starts visual line mode.
3.   Move the cursor to the bottom of the paragraph to be moved. The text to be moved will be hightlighted.
4. d Perform a visual delete. In other words delete the highlighted text.
5.   Move the cursor to line where the text is to go. The paragraph will be placed after this one.
6. p Paste the text in below the cursor.

Copying a block of text from one file to another (Vi Style)

There is more than one way to copy text between files. In this section we use the more triditionally Vi commands. In the next section Copying using visual mode, we perform the same operations using the Visual mode.

To copy a block of text between files execute the commands:

Command Explaination
1.   Edit the file containing the text you want to copy.
2.   Go to the top line to be copied.
3. ma Mark this line as mark "a".
4.   Go to the bottom line to be copied
5. y'a Yank (y) the text from the current cursor location to the mark "a" ('a)
6. :split second-file Open another window containing the second file. (This the file in which the text is to be inserted.)
7.   Go to the line where the insert is to occur. The text will be place after this line.
8. p Put the text after the cursor.

Copying a block of text from one file to another (Visual Method)

There is more than one way to copy text between files. In this section we use the newer visual mode commands. See the previous section for the older Vi Style of doing things.

To copy a block of text between files execute the commands:

Command Explaination
1.   Edit the file containing the text to be copied.
2.   Go to the top line to be copied.
3. v Start visual mode. If you want to copy a block of full lines, use V to go start Visual Line Mode
4.   Go to the bottom line to be copied. The text to be copied will be hightlighted.
5. y Yank (y) the text.
6. :split second-file Open another window containing the second file. (This the file in which the text is to be inserted.)
7.   Go to the line where the insert is to occur. The text will be place after this line.
8. p Put the text after the cursor.

Sorting a section (Vi Style)

Frequently you will be editing a file with a list of names in it. For example, a list of object files that make up a program.

For example:

	version.o  	 	pch.o		 	getopt.o 	 	util.o		 	getopt1.o	 	inp.o		 	patch.o		 	backupfile.o 

This list would be nice in alphabetical order. Or at least ASCII order. To alphabetize this list execute the commands:

Command Explaination
1.   Move the cursor to the first line to be sorted.
2. ma Mark the first line as mark a.
3.   Move to the bottom of the text to be sorted.
4. !'asort The ! command tells Vim to run the text through UNIX command. The 'a tell the editor that the text to be worked on starts at the current line and ends at mark a. The command that the text is to go through is sort.

The result looks like:

	backupfile.o 	getopt.o 	 	getopt1.o	 	inp.o	 	patch.o		 	pch.o		 	util.o		 	version.o  	 

Warning

In actual practice what you in most Makefiles (file that are used by UNIX to control compilation) looks more like:

OBJS = \         version.o       \         pch.o           \         getopt.o        \         util.o          \         getopt1.o       \         inp.o           \         patch.o         \         backupfile.o 

Notice that the backslash (\) is used to indicate a continuation line. After sorting this looks like:

OBJS = \         backupfile.o         getopt.o        \         getopt1.o       \         inp.o           \         patch.o         \         pch.o           \         util.o          \         version.o       \ 

The names are in order, but the backslashes are wrong. Don't forget to fix them using normal editing before continuing.

OBJS = \         backupfile.o    \         getopt.o        \         getopt1.o       \         inp.o           \         patch.o         \         pch.o           \         util.o          \         version.o 

Sorting a section (Visual Method)

Frequently you will be editing a file with a list of names in it. For example, a list of object files that make up a program.

For example:

	version.o  	 	pch.o		 	getopt.o 	 	util.o		 	getopt1.o	 	inp.o		 	patch.o		 	backupfile.o 

This list would be nice in alphabetical order. Or at least ASCII order. To alphabetize this list execute the commands:

Command Explaination
1.
Move the cursor to the first line to be sorted.
2. V Enter visual line mode
3.
Move to the bottom of the text to be sorted.
4. !sort The ! command tells Vim to run the hightlighted text through UNIX command. The command that the text is to go through is sort.

Warning

Check out the sort warning section for a short description of the problems that can result from using this command.

Dealing with Makefile and other SOB files

One problem with the file format used by the UNIX make command is that it's extremely fussy.

For example, the following is correct:

        prog: prog.c                 cc -g -o prog prog.c 

The following is not:

        prog: prog.c                 cc -g -o prog prog.c 

At first glance you might think that these two are exactly. But look closer. The "cc" line of the first one begins with a tab. The second one begins with eight spaces. (You can't tell the difference between a space and a tab when it's printed on the screen! You need a better video card.)

So how are you supposed to tell them apart especially when one the screen (or the printed page) they look exactly the same.

The answer is you can't. You might think that's a bit unfair. Especially when make works on the first one but not the second. But who every said UNIX was fair.

Fortunately Vim has a mode that tells you exactly what's in your file. Executing the command

	:set list 
puts you into this mode. When the display is set into "list mode" all characters print. Tabs show up as "^I" and the end of line shows up as $. So in list mode, our two examples look like:
        prog: prog.c$         ^Icc -g -o prog prog.c$ 

and

        prog: prog.c$                 cc -g -o prog prog.c$ 

From this it's easy to see which line has the tab.


Formatting a text paragraph

The Vim editor is not a word processor. Boy is it not a word processor. There are a couple of things you can do to make things better for you when editing text.

Word processors automatically wrap when you type a line that's longer than the margins. The Vim editor lets make a line as long as you want. By executing the command:

        :set wrapmargin=70 

you can tell Vim to automatically break lines when the run longer than 70 characters. (You can adjust this number to whatever line length you want.)

This makes entering text much easier. It doesn't solve the problem of editing. If you enter a paragraph and then decide to delete half the words on the first line, Vim will not reformat the text.

You can force a reformat of a paragraph by executing the commands:

Command Explaination
1.   Move to the top of the paragraph.
2. gq} The "!" command tells Vim to pipe a section of text through a filter. The } tells Vim that the section of text for the pipe command is a single paragraph.
3. fmt -70 The UNIX command fmt is a primitive formatter. It performs word-wrapping well enough for text documentation. The -70 tells fmt to format lines for 70 characters per line.

Finding a procedure in a C program

The Vim program was designed by programmers for programmers. You can use it to locate procedures within a set of C or C++ program files.

But first you must generate a table of contest file called a "tags" file. (This file has been given the obvious name tags.) The ctags command generates this table of contents files.

To generate a table of contents of all the C program files in your current working directory, use the command:

        $ ctags *.c 

For C++ use the command:

        $ ctags *.cpp 

If you use an extension other than .cpp for your C++ files, use it instead of .cpp.

Once this file is generated, you tell Vim that you want edit a procedure, and it will find the file containing that procedure and position you there. For example if you want to edit the procedure write_file use the command:

        $ vim -t write_file 

Now suppose as you are looking at the write_file procedure that it calls setup_data and you need to look at that procedure. To jump to that function, position the cursor at the beginning of the word setup_data and press Ctrl+]. This tells Vim to jump to the definition of this procedure. This repositioning will occur even if Vim has to change files to do so.

Note:

If you've edited the current file and not saved it, Vim will issue a warning and ignore the Ctrl+] command.

Drawing comment boxes

I like to put a big comment box at the top of each of my procedures. For example:

	/******************************************************* 	 * Program -- Solve it -- Solves the worlds problems.  * 	 *     All of them.  At once.  This will be a great    * 	 *   program when I finish it.                         * 	 *******************************************************/ 

Drawing these boxes like this is tedious at best. But Vim has a nice feature called abbreviations that makes things easier.

First, you need to create a Vim initialization file called ~/.vimrc. (At first this may look like a ex initialization file. It is. The Vim command is actually a mode of the ex editor.)

The ~/.vimrc file need to contain the lines:

        :ab #b /************************************************         :ab #e ************************************************/ 

These command define a set of Vim abbreviations. What's a Vim abbreviation? Its a word that stands for another word. When Vim see the abbreviation, it will expand it to the full word. In this case we've defined an abbreviation called #b that expands to the beginning line of a comment box. The #e abbreviation does the same thing.

So to create a comment box enter #b<enter>. The screen looks like:

        /************************************************ 
Enter the comments, including the beginning and ending "*" characters. Finally end the comment by typing #e<enter>. This causes the ending comment to be entered.

Note:

This page was written in Vim. So how did we enter the #b and #e? Easy, we typed in #bb and the deleted a character. (We couldn't enter #b or it would have been expanded.)

Some other useful commands that programmer may want to put in their ~/.exrc include:

	:set autoindent 	:set autowrite 	:ab #d #define 	:ab #i #include 	:ab #b /************************************************ 	:ab #e ************************************************/ 	:ab #l /*----------------------------------------------*/ 	:set sw=4 

The autoindent setting causes Vim to indent new lines by a similar amount to the one next to them. This is very useful for entering programs. The autowrite setting tells Vim to write the old file out when switching from one file to another.

The abbreviations #d, #i, and #l, define useful terms for programmers.

Finally, the command set sw=4 sets the shift width (the number of characters text is moved sideways for the shift command (<< and >>)).

This is very useful if you use a 4 space indentation for your C or C++ programs. (Studies at Rice University have shown this to be the best indentation size.)


Reading a man page

You can use the Vim editor to browse through text files. One of the most useful set of files to browse through is the man pages. To do this we assemble a pipeline of three command.

The first is man which gets the page. The next one, ul turns the underline and bold escape codes into something readable, and finally we use Vim to broswe the file.

So our command is:

$ man subject | ul -i | vim - 

The man page will be generated and then displayed in the Vim window. You can now use your normal editing commands to browse the files.


Removing carriage returns from MS-DOS file

If you ever try to edit a MS-DOS file, you'll notice that each line ends with a ^M character. This is caused by the funny way that MS-DOS treats the end-of-line. (For some background on this problem take a look at The EOL Story.

To remove the ^M characters from a MS-DOS file, enter the command:

	:1,$s/{Ctrl+V}{Ctrl+M}//{Enter} 
This command starts with a colon (:) to tell Vim to enter ex mode. All ex start with a line number range, in this case its from the first line (1) to the last ($). The slash indicates the start of the "from text". The {Ctrl+V} tells Vim to treat the next character as a regular character even if it's a special one. The next character is {Ctrl+M}. (This would be treated as {Enter} without the {Ctrl+V}.) The next slash ends the "from text". What follows is the "to text" enclosed by slashes. In this case it's nothing (//).

Trimming the blanks off an end of line

Some people find spaces and tabs at the end of a line useless, wasteful, and ugly. To remove whitespace at the end of every line, execute the command:

	:1,$s/[ <tab>]*$// 

The colon (:) tells Vim to enter ex command mode. All ex commands start with a line range, in this case, the entire file (line 1 to the last line: $).

The first set of slashes enclose the "from text". The square brackets indicate that either character can be a match. So [ <tab>] matches either space or tab. The star (*) means that the previous character specification (space or tab) can be repeated any of number times. The dollar ($ indicates an end of line.

So [ <tab>]*$ tells Vim to look for any number of spaces or tabs followed by an end of line.

These are then replaced by the text in the next set of slashes. This text is nothing, so the spaces and tabs are effectively removed.


Oops, I left the file write protected

Say your editing a file and you've made a lot of changes. This is a very important file and to preserve it from any casual changes, you've write protected it, even against yourself.

The Vim editor allows you to edit a write protected file with little or no warning. The only trouble is that when you try to exit using "ZZ" you get the error:

    file.txt	File is read only 

and Vim doesn't exit.

So what can you do? You don't want to throw away all those changes, but you need to get out of Vim so you can turn on write permission.

The trick is to execute the :shell command. This command takes you out of Vim by starting a command processor (shell) running under Vim

You can then write enable the file:

  	$ chmod u+w file.txt 
and get out of the shell, returning to Vim
	$ exit 

Finally you need to force Vim to write the file using the command:

	:w! 
(It still thinks the file is write protected so we need to use the force option (!) to convince it to try writing.)

Note:

It is a good idea to only spend as short a time as possible in a command processor started by the :shell command. That's because it's easy to forget that you're running under Vim. It's possible to start a shell, that starts Vim, that starts a shell, that starts Vim, that .... Using this method you can easily consume a lot of resources and generate a lot of confusion.

By keeping your :shell sessions short you can avoid lots of trouble.


Changing "Last, First" to "First Last"

You have a list of names in the form:

	Last, First 

How to you change them to:

	First Last 
It can be done with one command:
    :1,$s/\([^,]*\), \(.*$\)/\2 \1/ 
The colon (:) tells Vim that this is an ex style command.

The line range for this command is the whole file as indicated by the range 1,$.

The s (substitute) tells Vim to do a string substitution.

The old text is a complex regular expression. The \( ... \) delimiters are used to inform the editor that the text that matches the regular expression side is to be treated special.

The text in the first \( ... \) is assigned to \1 in the replacement text. The second set of text inside \( ... \) is assigned \2 and so on.

In this case the first regular expression is any bunch of characters that does not include a comma. The [^,] means anything but a comma, the * means a bunch (zero or more characters).

The second expression matches anything: .* up to the end of line: $.

The result of this substitution is that the first word on the line is assigned to \1 and the second to \2. These values are used in the end of the command to reverse the word.

The figure below shows the relationship between the \( \) enclosed strings and the \1, \2 markers.

	:1,$s/\([^,]*\), \(.*$\)/\2 \1/ 	      ^^     ^^  ^^   ^^^ ^  ^             	      ||     ||  ||   ||| |  +-----  String matched by  	      ||     ||  ||   ||| |          first \( \) 	      ||     ||  ||   ||| +--------- String matched by 	      ||     ||  ||   |||            second \( \) 	      ||     ||  ||   ||+----------- Slash separating  	      ||     ||  ||   ||             old/new strings 	      ||     ||  ++---++------------ Second \( \)  	      ++-----++--------------------- First \( \) 

The next figure breaks out the various parts of the regular expressions used in this example.

	:1,$s/\([^,]*\), \(.*$\)/\2 \1/ 		^^^^^  ^^  ^^^ 		|||||  ||  ||+--- The end of the line 		|||||  ||  |+---- Repeated 0 or more time 		|||||  ||  +----- Any character 		|||||  ||  +++--- Any character, repeated, 		|||||  ||             followed by EOL 		|||||  |+-------- The character space 		|||||  +--------- The character comma 		||||+------------ Repeated 0 or more times 		|||+------------- Closes the [] expression 		||+-------------- The character comma 		|+--------------- Match anything except the 		|                 next character 		+---------------- Starts a set of matches 		++++------------- Match anything but comma 		    +------------ Repeated 0 or more times 		       +--------- Followed by comma 

How to edit all the files containing a given word

This involves the fgrep as well as the special shell character backtick (`).

To edit all the C program files that contain the word indentation_level execute the command:

    $ vim `fgrep -l indentation_level *.c` 

The fgrep -l indentation_level *.c searches all the files ending with .c for the word and lists them out.

Since this command is enclosed in backtick (`) characters the results of the command (a list of files) takes the place of the command on the command line.

The Vim editor is then run on these files. The commands :n{Enter} and :rew{Enter} can then be used to browse through the files.

How to edit all the files containing a given word using the built-in grep

Start Vim.

Execute the command:

    :grep >word< >file-list< 

This finds the first location of word in the given files and positions the cursor on that line. You can use the command :cn to find the next occurance.

THC/DOC/ORC/BAF

THC:Terminal Handling Charges码头操作费  DOC:Document charges文件费  ORC:Original receipt charge原场地码头附加费  BAF:BUNKER ADJUSTMENT FACTORY油价调整指数附加费 

Friday, October 15, 2010

铁矿石进口权企业名单 2009

1 上海宝钢集团
2 鞍山钢铁集团公司
3 武汉钢铁(集团)公司
4 首钢总公司
5 马鞍山钢铁股份有限公司
6 唐山钢铁集团有限责任公司
7 江苏沙钢集团有限公司
8 湖南华菱钢铁集团有限责任公司
9 济南钢铁集团总公司
10 邯郸钢铁集团有限责任公司
11 莱芜钢铁集团有限公司
12 本溪钢铁(集团)有限责任公司
13 包头钢铁(集团)有限责任公司
14 攀枝花钢铁(集团)公司
15 安阳钢铁集团有限责任公司
16 南京钢铁股份有限公司
17 唐山国丰钢铁有限公司
18 广东韶关钢铁集团有限公司
19 天津铁厂
20 河北津西钢铁股份有限公司
21 建龙钢铁控股有限公司
22 宣化钢铁集团有限责任公司
23 新余钢铁股份有限公司
24 广西柳州钢铁(集团)公司
25 太原钢铁(集团)有限公司
26 广州钢铁企业集团有限公司
27 杭州钢铁(集团)公司
28 昆明钢铁集团有限责任公司
29 重庆钢铁(集团)有限责任公司
30 福建三钢(集团)有限责任公司
31 通化钢铁集团有限责任公司
32 山西海鑫钢铁有限公司
33 萍乡钢铁有限责任公司
34 酒泉钢铁(集团)有限责任公司
35 青岛钢铁控股集团有限责任公司
36 邢台钢铁有限公司
37 承德钢铁集团有限责任公司
38 石家庄钢铁有限责任公司
39 四川川威钢铁集团有限公司
40 水城钢铁(集团)有限责任公司
41 南昌钢铁有限责任公司
42 天津天钢集团有限公司
43 江阴兴澄特种钢铁有限公司
44 湖北新冶钢有限公司
45 唐山世纪晨晖钢铁制品有限公司(半钢)
46 长治钢铁(集团)有限公司
47 抚顺新抚钢有限责任公司
48 江苏永钢集团有限公司
49 河南济源钢铁(集团)有限公司
50 陕西龙门钢铁(集团)有限责任公司
51 河北敬业钢铁有限公司
52 新兴铸管股份有限公司
53 天津钢管有限责任公司
54 江苏苏钢集团有限公司
55 日照钢铁控制股集团有限公司
56 山东泰山钢铁有限公司
57 河北栾河实业有限公司
58 安阳永兴钢铁有限责任公司
59 湖南冷水江钢铁总厂
60 江苏雪丰钢铁股份公司
61 张钢制铁铸管有限公司
62 新疆八一钢铁集团有限责任公司
63 凌源钢铁集团有限责任公司
64 华西钢铁公司
65 德龙钢铁有限公司
66 西林钢铁集团有限公司
67 河北普阳钢铁公司
68 中天钢铁集团有限责任公司
69 山西宇晋钢铁有限公司
70 河北文丰钢铁有限公司
71 中化国际(控股)股份有限公司
72 中国通信建设总公司
73 上海上实国际贸易(集团)有限公司
74 福建三安集团有限公司
75 中建材集团进出口公司
76 中化物产股份有限公司
77 四川川投国际贸易有限公司
78 瑞钢联集团有限公司
79 中国瑞联实业集团有限公司
80 中达国际经贸集团有限责任公司
81 浙江物产集团公司
82 江苏省对外经贸股份有限公司
83 延边天池工贸有限公司
84 上海市五金矿产进出口公司
85 唐山市福翼物资有限公司
86 安徽省技术进出口股份有限公司
87 山东九羊实业股份有限公司
88 秦皇岛太行贸易有限公司
89 中国五矿集团公司
90 中国中信集团公司
91 中基宁波对外贸易股份有限公司
92 厦门国贸集团股份有限公司
93 上海久茂对外贸易有限公司
94 大连东展集团有限公司
95 新疆阿拉山口口岸工贸股份有限公司
96 天津中联进出口贸易有限公司
97 青岛新兴东方进出口总公司
98 中国外运山东有限公司
99 上海埃力生(集团)有限公司
100 江苏省华贸进出口有限公司
101 中储发展股份有限公司
102 上海�隆进出口有限公司
103 山西省冶金物资总公司
104 青岛华青进出口有限公司
105 俊安(天津)实业有限公司
106 日照中瑞物产有限公司
107 宁波百丰选矿有限公司
108 南金兆集团有限公司
109 陕西北冶人和贸易有限公司
110 中国中钢集团公司
111 深圳市南天辉进出口有限公司
112 山东省国际贸易集团中心
113 山东万宝贸易有限公司
114 山东华信工贸有限公司
115 山西大晋国际(集团)股份有限公司
116 北台钢铁(集团)进出口有限责任公司
117 沈阳东方钢铁有限公司
118 山西三联正丰国际贸易有限公司

Thursday, October 14, 2010

CIF

什么是CIF?http://baike.baidu.com/lemma-php/dispose/view.php/64850.htm

【到岸价格】
注意了CIF不能称之为到岸价,这是不准确的。

长期以来,人们习惯于把国际贸易中的FOB价格条件称为离岸价格,从而也把价格术语中包含运费与保险费的CIF说成到岸价。甚至在一些正规媒体的文章中也不时出现这样的说法。如在谈到中国大豆的国际市场竞争力时,经常有报道说,中国大豆的离岸价(FOB)高于国外进口转基因大豆的"到岸价"(CIF)等等。

FOB价格说成离岸价格是符合其含义的形象说法,因为FOB价格包含的是出口产品在越过船舷之前的所有成本与费用,风险也在装运港的船舷由卖方转移给买方,但把CIF价说成是到岸价格说成就是一种不科学的说法了。人们之所以误称CIF为"到岸价"是由于从表面上看CIF价格术语的确包含至目的港的运费和保险费,人们只是单纯地从价格构成来为其命名。

国际贸易中真正意义上的到岸价应该是DES,而不是CIF,从交货地点来看,按《国际贸易术语解释通则》以及其他两个有关贸易术语的国际惯例解释。CIF价格条件下的卖方叫过地点不是目的港,而是装运港。它是一种典型的象征性交货价格术语。卖方只要按期在约定地点完成装运,并向卖方提交合同约定的提单等有关单据就算完成了交货义务。至于货物何时抵达目的港,除非卖方在合同中做了明确的承诺,卖方不对货物的抵港时间承担任何责任。而真正意义上的到岸价格DES价格术语的含义是卖方要在规定的时间和地点将符合合同规定的货物提交买方,不能以交单代替交货。

CIF不是到岸价还因为CIF的风险转移界限也是装运方船舷而不是目的港。例如,采用CIF价格术语成交的合同,如果载货船舶在尚未驶离装运港就触礁沉没了,买方是无法向卖方提交索赔的,理由是越过船舷后的风险已转移至买方,买方只能依据保险合同合同向保险公司进行索赔。这说明卖方对于风险并不负责至目的港,即到岸的价格术语是DES。在此术语下,风险在货物被置于买方实际控制之下时转移,此前的风险完全由卖方承担。如上述案例中,如果使用的DES而不是CIF,买方就可以在货物没有抵港之前不必考虑也误需承担任何风险,这才符合到岸价格的真正含义。

另外,在CIF的条件下,由装运港至目的港的保险属代办性质,卖方只需按规定会惯例承担正常保险费用。如果没有特别规定,卖方只需投买最低的保险险别就算是完成了CIF的保险义务;而在真正的到岸价DES条件下,卖方是为自己的利益投买保险的,他要根据自己货物的情况来确定投保金额与保险险别,以及考虑是否加保各种附加险而支付保险费。

再者,CIF术语中的F 是指运费freight,按《国际贸易术语解释通则规定,CIF合同中卖方的义务是按照通常的条件及惯驶的航线,负责租船或订舱并支付运费。但这里所说的运费只是正常的运费,在运输中载货船舶可能遇到恶劣天气,船上的机器可能出现故障,需要避风或修理,也可能由于转船或绕汉等发生的运费称为不正常运费。在CIF条件下,不正常运费均应由买方承担。如国内某公司以CIF纽约价格条件向美国出口某商品,在投保一切险的基础上加保了战争险和罢工险。在载货船舶尚未抵达纽约港前,船方获悉纽约港正在罢工,不能靠岸卸货,于是便将货物卸在纽约港附近的一个港口。一个月后,纽约港罢工结束,货物又由该港转运到纽约港,但增加了1500美元的运费,对这笔额外运费的负担问题各方之间产生了争议,对保险公司来说,虽然接受了罢工险的投保,但因罢工改港卸货多增加的运费属于间接损失,所以保险公司拒绝赔偿,而承运人依据提单的免责条款也可以不负责任。卖方在CIF价格条件下负担的是正常运费,在货物越过船舷后风险与费用就都转移出去了,不必再考虑货到目的港前的任何偶然事件所引起的额外运费。争议的最终结果是1500美元的额外运费只能由买方自己承担了。由此看来,船舶在没有到岸时,发生的运费仍需买方承担。所以,没有理由称CIF为到岸价。

【离岸价格】free on board

以货物装上运载工具为条件的价格。又称装运港船上交货价格。根据国际商会修订公布的《1980年贸易术语解释的国际通则》,卖方必须做到以下几点:①负责在合同规定的装运港和装运期内,按港口惯例将货物装上买方指定的船上,并及时向买方发出装船通知。②负担货物越过船舷以前的各项费用和风险。③办理出口手续,并提供合同规定的各项单证。买方必须做到以下几点:①负责租船订舱和支付运费,并将船名及装货日期通知卖方。②负担货物自越过船舷时起的一切费用和风险。③接受卖方提供的有关单证,并支付货款。美国、加拿大等一些国家在国际贸易中,对离岸价格的解释与国际商会有所不同。由于各国的港口对离岸价格有不同的解释和习惯,因此凡大宗货物按离岸价格条件成交时,买卖双方在装货费用由谁负担等问题上一定要有明确规定,分清责任,防止误解。在一定条件下,进口采用离岸价格对进口国有一定的好处。在离岸价格条件下,进口国可选择本国的船舶运输,向本国保险公司投保,这样可避免肥水外流,商业风险相对较小。

外贸交易术语



买卖双方所承担的运输、保险责任互相对应、即 FCA 和 FOB 一样,由买方办理运输, CPT 和 CFR 一样,由卖方办理运输,而 CPT 和 CFR 一样,由卖方承担办理运输和保险的责任。

  CPT 、 FCA 、 CIP 与传统的 FOB 、 CFR 、 CIF 相比较。有以下三个共同点:

  (1)都是象征性交货,相应的买卖合同为装运合同;

  (2)均由出口方负责出口报关,进口方负责进口报关;

  (3)买卖双方所承担的运输、保险责任互相对应、即 FCA 和 FOB 一样,由买方办理运输, CPT 和 CFR 一样,由卖方办理运输,而 CPT 和 CFR 一样,由卖方承担办理运输和保险的责任。

  由此而产生的操作注意事项,也是相类似的。

  这两类贸易 术语 的主要不同点在于:

  (1)适合的运输方式不同、CPT、 FCA 、 CIP 适合于各种运输方式,而 FOB 、CFR、ClF,只适合于 海运 和内河运输;

  (2)风险点不同。CPT、FCA、 CIP 方式中,买卖双方风险和费用的责任划分以“货交承运人”为界,而传统的贸易 术语 则以“船舷”为界;

  (3)装卸费用负担不同。CPT、FCA、CIP由承运人负责装卸,因而不存在需要使用贸易 术语 变形的问题

  (4)运输单据性质不同。 海运 提单具有物权凭证的性质,而航空运单和铁路运单等,不具有这一性质。

  所以,除了风险点不同之外,可以把CPT、FCA、CIP看成是 FOB、CFR、 CIF 方式从 海运 向各种运输方式的延伸。

常用外贸报价方式

介绍几种常见的外贸报价方式:EXW,FOB,CIF和CFR.
外贸报价方式一、工厂交货价(EXW=Ex Works):
交货地点:出口国工厂或仓库;
运  输:买方负责;
保  险:买方负责;
出口手续:买方负责;
进口手续:买方负责;
风险转移:交货地;
所有权转移:随买卖转移;
外贸报价方式二、离岸价(FOB=Free on Borad):
交货地点:装运港;
运  输:买方负责;
保  险:买方负责;
出口手续:卖方负责;
进口手续:买方负责;
风险转移:装运港船舷;
所有权转移:随交单转移;
外贸报价方式三、到岸价(成本 运费 保险费,CIF=Cost Insurance Freight):
交货地点:装运港;
运  输:卖方负责;
保  险:卖方负责;
出口手续:卖方负责;
进口手续:卖方负责;
风险转移:装运港船舷;
所有权转移:随交单转移;
外贸报价方式四、成本加运费(CFR=Cost Freight):
交货地点:装运港;
运  输:卖方负责;
保  险:买方负责;
出口手续:卖方负责;
进口手续:买方负责;
风险转移:装运港船舷;
所有权转移:随交单转移;
FOB、CIF、CFR这三种外贸报价方式的共同点:
01,卖方负责装货并充分通知,买方负责接货;
02,卖方办理出口手续,提供证件,买方办理进口手续,提供证件;
03,卖方交单,买方受单、付款;
04,装运港交货,风险、费用划分一致,以船舷为界;
05,交货性质相同,都是凭单交货、凭单付款;
06,都适合于海洋运输和内河运输;
FOB、CIF、CFR这三种外贸报价方式间的不同点:
01,FOB:买方负责租船订舱、到付运费;办理保险、支付保险;
02,CIF: 卖方负责租船订舱、预付运费;办理保险、支付保险;
03,CFR:卖方负责租船订舱、预付运费;买方负责办理保险、支付保险;

Wednesday, October 13, 2010

so low ?

at least 2.10 to keep population right ?

in reference to:

"According to latest 2010 statistics, Singapore’s resident total fertility rate (TFR) reached a level of 1.22 in 2009. The Chinese TFR was (1.08), followed by Indians (1.14) and Malays (1.82). Malay fertility-rate is ~70% higher than Chinese and Indians.[85]"
- Singapore - Wikipedia, the free encyclopedia (view on Google Sidewiki)

List of offshore financial center

http://en.wikipedia.org/wiki/List_of_offshore_financial_centres
---
Singapore is also one of them ...

in reference to:

"The following are designated as offshore financial centres by the IMF[1], the FSF and recently Ministry of Finance (Brazil)[2]:"
- List of offshore financial centres - Wikipedia, the free encyclopedia (view on Google Sidewiki)

Tax around the world

http://en.wikipedia.org/wiki/Tax_rates_around_the_world

in reference to:

"Singapore 17%[30] 3.5%-20% 7% (GST) Income tax in Singapore Goods and Services Tax (Singapore)"
- Tax rates around the world - Wikipedia, the free encyclopedia (view on Google Sidewiki)

Sunday, October 03, 2010

Corporate account in singapore


UOB 6226-6121
Initial $1K
Min $10k
Fee $15 / mth under 10K
Internet Access - free if using "pro" package
Transfer fees: In bank free, out of bank (in sing) $2 (giro?), wire min $30
Checks: 30 / mth, .50 after
Min period: 6 mos.
Security Device: $20 each (1 needed, so basically $20 set up fee)

DBS 6222-2200
Initial $3K
Balance Min $10k
Fee $15 / mth under $10K
Internet Access $30 setup + $30 / mth
Transfer fees: In bank free, out of bank (in sing) Giro .20, wire min $18
Checks: 30 / mth, .40 after
Min period: 6 mos.
Security Device: Free for 2, 2 required from internet


OCBC 6538-1111
Initial $5K
Min $10k
Fee $15 / mth under $10K
Internet Access - free
Transfer fees: ocbc to ocbc free, GIRO .20 /transcaction, wire min $30
Checks: 30 / mth, .50 after
Min period: 6 mos.
Security Device: Free for 1 (2 users needed), 2nd is $20


Standard Chartered 6743-3000
essential account
Initial $3K
Min - none
Internet Access - free
Transfer fees: internal free, giro free, meps $20, wire min $30
Checks: .30 check
Min period: 6 mos.
Security Device: Free for 1 (1 needed) 

Tuesday, September 28, 2010

注册离岸公司

http://www.midunshangwu.com/list/zhu-ce-li-an-gong-si.shtm

世界上一些国家和地区(多数为岛国)近些年纷纷以法律手段制订并培育出一些特别宽松的经济区域,这些区域一般称为离岸法区。而所谓离岸公司就是泛指在离岸法区内成立的有限责任公司或股份有限公司。如英属维京群岛、 纽埃岛、巴哈马群岛、塞舌尔群岛、巴拿马共和国、毛里求斯共和国等,允许国际人士在其领土上成立一种国际业务公司。当地政府对这类公司没有任何税收,只收 取少量的年度管理费,同时,所有的国际大银行都承认这类公司,为其设立银行帐号及财务运作提供方便。通常情况下,这类地区和国家与世界发达国家有很好的贸 易关系。

无论在上述任何一个国家或地区注册的海外离岸公司,均具有高度的保密性、减免税务负担、无外汇管制三大特点,因而吸引了众多商家与投资者选择海外离岸公司的发展模式。 离岸公司与 一般有限公司相比,主要区别在税收上。与通常使用的按营业额或利润征收税款的做法不同,离岸法区的政府只向离岸公司征收年度管理费,不再征收任何税款。而 且几乎所有的离岸法区均明文规定:公司的股东资料,股权比例,收益状况等,享有保密权利。而"离岸"的含义是指投资人的公司注册在离岸法区,但投资人不用亲临当地,其业务运作可在世界各地的任何地方直接开展。

海外离岸公司常见用途:

  • 贸易公司:直接的好处就是极为方便的资金运作和超低的税赋成本。
  • 控股公司:包括商业控股公司和以保持隐秘性为主要目的的私人控股公司。排名第一香港和第二的英属维尔京群岛都是著名的离岸地。
  • 国际投资:用于持有债券、股票以及交易等。
  • 其他用途:游艇持有公司、物业持有公司、资产保护公司、公众投资公司、知识产权拥有公司、运输公司、网络公司、保险公司等。

公司转口贸易

转口贸易又称中转贸易(intermediary trade)或再输出贸易(Re-Export Trade),是指国际贸易中进出口货物的买卖,不是在生产国与消费国之间直接进行,而是通过第三国转手进行的贸易。

公司转口贸易

什么是转口贸易

转口贸易又称中转贸易(intermediary trade)或再输出贸易(Re-Export Trade),是指国际贸易中进出口货物的买卖,不是在生产国与消费国之间直接进行,而是通过第三国转手进行的贸易。这种贸易对中转国来说就是转口贸易。 交易的货物可以由出口国运往第三国,在第三国不经过加工(改换包装、分类、挑选、整理等不作为加工论)再销往消费国;也可以不通过第三国而直接由生产国运 往消费国,但生产国与消费国之间并不发生交易关系,而是由中转国分别同生产国和消费国发生交易。转口贸易有货物集散地、仓库、堆栈之意,它属于再出口贸易 和过境贸易中间接过境的一部分。

转口贸易的发生,主要是有些国家(或地区)由于地理的、历史的、政治的或经济的因素,其所处的位置适合于作为货物的销售中心。这些国家(或地区)输 入大量货物,除了部分供本国或本地区消费外,又再出口到邻近国家和地区。如新加坡、香港、伦敦、鹿特丹等,都是国际著名的中转地,拥有数量很大的转口贸 易。它们通过转口贸易除了可以得到可观的转口利润和仓储、运输、装卸、税收等收入外,同时也推动了当地金融、交通、电讯等行业的发展。

转口贸易产生的条件

转口贸易(Entrepot Trade)是指两国的进出口贸易是通过第三国的中间商把货物转手来完成的贸易方式。这种贸易方式在生产国为间接出口,在消费国为间接进口,因而是一种间 接贸易方式。而对第三国来说,它将进口的货物再出口,所以是转口,又称再出口贸易。转口贸易已有数百年历史,伦敦、鹿特丹、新加坡是著名的转口贸易港。战 后转口贸易在香港、新加坡、日本、等地发展甚为迅速,并成为这些地区对外贸易的一个重要组成部分。

转口贸易对中间商所在国而言,一般必须具备两个条件:

①自然条件,即中转国的港口必须是深水港、吞吐能力强,地理位置优越,处于各国之间的交通要冲或国际主航线上;
②人为条件:要求中转国对中转地采取特殊的关税优惠政策和贸易政策,如自由港、自由贸易区等,使中转费用不致过高。同时,要求该地的基础设施、交通、金融和信息等服务系统发达且完备,以利于转口贸易的进行。

转口贸易的方式

转口贸易的形式多样,根据货物流通渠道的不同,可分为再出口贸易和单所处理贸易方式两种:

①再出口贸易(Re-export Trade)方式,是指出口商通过中间商与进口商发生买卖关系。而后将货物直接从出口国运往进口国的贸易方式。在这种情况下,货物并未在第三国通关进出 口,而中间商亦仅涉及交易单据的处理。这种单据处理贸易方式实际上是货物所有权的再出口。再出口贸易方式在转口贸易发展的初期较多发生。人们由于经验、通 讯设备等的缺管,转口贸易就通过两交货物的进出口来完成。随着转口贸易的发展,单据处理贸易的方式逐渐发展起来,为种方式可以避免货物在第三国通关进出口 的每秒杂手续,节省运费、保险费和手续费等费用,减少风险,还可缩短交货时间,有利于进口商抓信货物销售良机,从而实现较大的利润。因而单据处理贸易方式 逐渐取代再出口贸易方式,成为当今转口贸易的主要方式。转口贸易根据货物是否在中转地加工,可分为纯粹转口贸易和加工转口贸易两种。

②纯粹转口贸易。所谓纯粹转口贸易系指中转的第三国的中间商对进口的货物未经加工再出口。当然,中间商可以将进口货物在当地保税仓库进行分级、混装、加包装、贴标签等。这些活动并未改变原进口货物的形态、性质,结构或效用等,所以不属于加工的范围。

③加工转口贸易,指货物通关输入到中转国,红加工增值后再输往进口国的贸易方式。货物经过某种程度的加工,使加工后的货物与原来未经加工的货物在形 态、性质、结构或交用上发生某此变化,大气层以这种贸易方式不仅可以获得转口利润,还可获加工利润。加工转口贸易要求中转地有大量的劳动力,工资水平较 低,基础设施较好,并有保科仓库或保税区等,这样才能使商品加工成本低,具有国际竞争力。加工转口贸易可以对整批货物进行加工、装配等;也可以是从国处采 购某些零部件,与原有的设备配套装配成大型设备出口。

香港是典型的贸易转口港口,香港公司的转口贸易具有代表性,故以香港公司的转口贸易操作来做个简单的理解。香港是英美法系国家并且没有外汇管制!而 在英美法系国家的税务条例中,都适用“利润来源地征税法”。所以,如果您打算注册海外公司运转贸易,那就要和自己的海外客户所在国避开。注册香港有限公司 操作贸易比国内公司操作贸易具备优势的是两点:海外公司做贸易所产生的利润,可以合法免税;海外公司的帐户可以自由外汇资金流动。

案例说明:上海A公司有一批价值为70万美金的货物,准备以100万美金的价格卖给美国B公司。(对于无进出口权外贸企业,依然是委托外贸公司代理出口,流程不变,但是大大保密了自己的海外客户信息,详细操作可看之前信用证的解释)

※一般贸易出口运作
上海A公司<========>美国B客户
                100万
                               注:合同:========>
                                                            收款:<==========
分析: ①A公司盈利:100万–70万=30万,按照中国的税制进行完税。
      ②100万美金全部打到国内被结汇,汇率有损失。

※转口贸易出口运作(上海A公司通过一间香港离岸公司做转口)
上海A公司=================美国B客户
            \\                              //
         U$80万                          U$100万
                \\                     //
                     香港离岸公司
分析: ①A公司盈利:80万–70万=10万,按照中国的税制进行完税。
       ②C公司盈利:100万–80万=20万,根据香港税务法规定:业务不在香港本土发生,是无需向香港税务局交税的。受益20万美金留在香港公司帐户,不会被结汇且不会被打税。
       ③80万美金打到国内被结汇,汇率损失减少。

 


Friday, September 24, 2010

test

test posting

Tuesday, September 21, 2010

License in SG

www.spf.gov.sg for liquor lic

www.nea.gov.sg for food lic.

www.hsa.gov.sg for selling cig & cigar lic.

in reference to:

"www.spf.gov.sg for liquor lic www.nea.gov.sg for food lic. www.hsa.gov.sg"
- Singapore Expats Forum - View topic - Setting up a company. Need help (view on Google Sidewiki)

Wednesday, September 01, 2010

Using Top More Efficiently

http://www.linuxforums.org/articles/using-top-more-efficiently_89.html


For desktop users, monitoring resource usage is an important task. By doing this, we can locate system bottleneck, planning what to do to optimize our system, identifying memory leak and so on. The problem is, which software one should use and how to use it according to our need.

Among many monitoring tools that available, most people use "top" (a part of procps package). Top provide almost everything we need to monitor our system's resource usage within single shot. In this article, all the information are based on procps 3.2.5 running on top of Linux kernel 2.6.x

Here, we assume that procps package is already installed and run well in your Linux system. No previous experience with top is needed here, but if you had given it a try briefly, that would be an advantage.

Here are some challenges:

A. Interactive or batch mode?

By default, top is invoked using interactive mode. In this mode, top runs indefinitely and accepts keypress to redefine how top works. But, sometimes you need to post-process the top's output and this is hardly achieved using this mode. The solution? Use batch mode.

$ top -b

You will get output like below:

top - 15:22:45 up  4:19,  5 users,  load average: 0.00, 0.03, 0.00
Tasks: 60 total, 1 running, 59 sleeping, 0 stopped, 0 zombie
Cpu(s): 3.8% us, 2.9% sy, 0.0% ni, 89.6% id, 3.3% wa, 0.4% hi, 0.0% si
Mem: 515896k total, 495572k used, 20324k free, 13936k buffers
Swap: 909676k total, 4k used, 909672k free, 377608k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 16 0 1544 476 404 S 0.0 0.1 0:01.35 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/0
3 root 10 -5 0 0 0 S 0.0 0.0 0:00.11 events/0

Uh, wait, it runs repeatedly, just like interactive mode does. Don't worry, limit its repetition with -n. So, if you just want single shot, type:

$ top -b -n 1

The real advantage of this mode is you can easily combine in with at or cron. Together, top can snapshot resource usage at certain time unattendedly. For example, using at, we can schedule top to run 1 minute later.

$ cat ./test.at
TERM=linux top -b -n 1 >/tmp/top-report.txt
$ at -f ./test.at now+1minutes

Careful reader might ask "why do I need to set TERM environment before invoking top when creating new at job?". The answer is, top needs this variable set but unfortunately "at" isn't retained it from the time of invocation. Simply set it like above and top will work smoothly.

B. How to monitor certain processes only?

Sometimes, we are only interested on several processes only, maybe just 4 or 5 of the whole existing processes. For example, if you want monitor process identifier (PID) 4360 and 4358, you type:

$ top -p 4360,4358
OR
$ top -p 4360 -p 4358

Seems easy, just use -p and list all the PIDs you need, each separated with comma or simply use -p multiple times coupled with the target PID.

Another possibility is just monitoring process with certain user identifier (UID). For this need, you can use -u or -U option. Assuming user "johndoe" has UID 500, you can type:

$ top -u johndoe
OR
$ top -u 500
OR
$ top -U johndoe

The conclusion is, you can either use the plain user name or the numeric UID. "-u, -U? Those two are different?" Yes. Like almost any other GNU tools, options are case sensitive. -U means top will find matching effective, real, saved and filesystem UIDs, while -u just find matching effective user id. Just for reminder, every *nix process runs using effective UID and sometimes it isn't equal with real user ID. Most likely, one is interested in effective UID as filesystem permission and operating system capability are checked against it, not real UID.

While -p is just command-line option only, both -U and -u can be used inside interactive mode. Like you guess, press 'U' or 'u' to filter the processes based on their user name. Same rule is applied, 'u' for effective UID and 'U' for real/effective/saved/filesystem user name. You will be asked to enter the user name or the numeric UID.

{mospagebreak title=Fast or slow update?}

C. Fast or slow update?

Before we answer this question, let's take a short look on how top really works. Strace is your friend here:

$ strace -o /tmp/trace.txt top -b -n 1

Use you favourite text editor and load /tmp/trace.txt. What do you think? A lot of jobs for single invocation, that is what I think and maybe you'll agree. One of the jobs top must do in every iteration is opening many files and parsing their contents, as shown by the number:

$ grep open( /tmp/hasil.txt | wc -l

Just for illustration, in my Linux system, it yields 304. Closer look reveals that top iterates inside /proc directory to gather processes information. /proc itself is pseudo filesystem, meaning it doesn't exist on real disk but is created on the fly by the Linux kernel and live on RAM. Within directory such as /proc/2097 (2097 is a PID), Linux kernel exports information about related process and this is where top gathers processes information along with resource usage.

Also try these:

$ time top -b -n 1

This will give you illustration how fast top works on single round. In my system, this yields around 0.5-0.6 seconds. Look at "real" field, not the "user" or "system" field because "real" reflects the total time top needs to work.

So, realizing this fact, it will be wise to use moderate update interval. Browsing RAM based filesystem takes time too, so be wise. As rule of thumb, 1 to 3 seconds interval is enough for most users. Use -d in command line option or press "s" inside interactive mode to set it. You can use fractional number as interval, e.g: 2.5, 4.1 and so on

When we should faster than 1 seconds?


  • You need more samples during a time. For this need, better use batch mode and redirect standart output to a file so you can analyze it better.
  • You don't mind with extra CPU load carried by top. Yes, it is small but it is still a load. If your Linux system is relatively idle, feel free to use short interval, but if not, better preserve your CPU time for more important task.
  • One way to reduce top's work is by monitoring certain PIDs only. This way, top won't need to traverse all the /proc sub-directory. How about user name filtering? It won't do any good. User name filtering brings extra work for top, thus combining it with very short interval will increase CPU load.

    Of course, whenever you need to force the update, just press Space and top will refresh the statistic right away.

    {mospagebreak title=Fields we need}

    D. Fields that we need

    By default, top starts by showing the following task's property:

    FieldDescription
    PID : Process ID
    USER :Effective User ID
    PR : Dynamic priority
    NI :Nice value, also known as base priority
    VIRT : Virtual Size of the task. This includes the size of process's executable binary, the data area and all the loaded shared libraries.
    RES : The size of RAM currently consumed by the task. Swapped out portion of the task is not included.
    SHR : Some memory areas could be shared between two or more task, this field reflects that shared areas. The example of shared area are shared library and SysV shared memory.
    S : Task status
    %CPU : The percentage of CPU time dedicated to run the task since the last top's screen update.
    %MEM : The percentage of RAM currently consumed by the task.
    TIME+ : The total CPU time the task has been used since it started. "+" sign means it is displayed with hundreth of a second granularity. By default, TIME/TIME+ doesn't account the CPU time used by the task's dead children.
    COMMAND : Showing program names.

    But, there are more. Here, I will just explain fields that might interest you:

    FieldDescription
    nFLT (key 'u')

    Number of major page fault since the process is started. Technically, page fault happens when the task access a non existant page in its address space. A page fault is said as "major" if kernel needs to access the disk to make the page available. On the contrary, soft minor page fault means the kernel only need to allocate pages in RAM without reading anything from disk.

    For illustration, consider the size of program ABC is 8 kB and assume the page size is 4 kB. When the program is fully loaded to RAM, there will be 2 times major page fault (2 * 4 kB). The program itself allocates another 8 kB for temporary data storage in RAM. Thus, there will be 2 minor page fault.

    A high number of nFLT could mean:

    1. The task is aggressively load some portions of its executable or library from the disk.
    2. The task is accessing a page that is swapped ou

    It is normal if you see a high number of major page fault when a program is run for first time. On the next invocations, buffer is utilized so likely you will see "0" or low number of nFLT. But, if a program is continously triggerring major page fault, big chance your program needs larger RAM size than currently installed.

    nDRT (key 'v')

    The number of dirty pages since they are written back to the disk.

    Maybe you wonder, what is dirty page? First, a little bac ground. As you know, Linux employ caching mechanism, so everything that is read from disk is also cached in RAM. The advantage of this action is, subsequent read to the same disk block can be served from RAM thus reading completes faster.

    But it also costs something. If the buffer's content is modified, it needs to be synchronized. Thus, sooner or la this modified buffer (dirty page) must be written back. The failure on the synchronization might cause data inconsistency on related disk.

    On mostly idle to fairly loaded system, nDRT is usually below 10 (this is just a raw prediction)or mostly zero. If it is constantly bigger than that:

    1. The task is aggresively write something to file(s). It is so often that disk I/O can't keep up with it
    2. The disk suffers I/O congestion, thus even the task only modifies small portion of file(s), it must wait a bit longer to be synchronized. Congestion happens when many processes access the disk at a time but cache hit is low.

    These days, (1) unlikely happens because I/O speed is getting faster and less CPU demanding (thanks to DMA). So (2) has bigger probability.

    Note: On 2.6.x, this field is always zero without unknown reason.

    P (key 'j')

    Last used CPU. This field only has meaning in SMP environment. SMP here refers to Hyperthread, multi core or true multi processor. If you just have one processor (non multi core, not HT), this field will always show '0'.

    In SMP system, don't be surprised if this field change sometimes. That means, the Linux kernel tries to move your task to the other CPU which is considered less loaded.

    CODE (key 'r') and DATA (key 's')

    CODE simply reflects the size of your application code, while DATA reflects the size of data segment (stack, heap, variables but not shared libraries). Both are measured in kilobyte.

    DATA is useful to show how much your application allocates memory. Sometimes, it can also reveal memory leaks. Of course, you need better tool such as valgrind to differentiate between repetitive memory allocation or growing memory leaks if DATA continously climbs up.

    Note: DATA, CODE, SHR, SWAP, VIRT, RES are all measured in page size (4KB in Intel architecture). Read only data section is also calculated as CODE size, thus sometimes it is larger than the actual text (executable) segment.

    SWAP (key 'p')

    The size of swapped out portion of a task's virtual memory image. This field is sometimes confusing, here is why:

    Logically, you would expect this field really shows whether your program is partially swapped out and how much. But the reality shows otherwise. Even the "Swap used" field shows 0, you will be surprised that SWAP field of each tasks show greater than zero number. So, what's wrong?

    This comes from the fact that top use this formula:

                    VIRT = SWAP + RES or equal
    SWAP = VIRT - RES

    As explained previously, VIRT includes anything inside task's address space, no matter it is in RAM, swapped out or still not loaded from disk. While RES represents total RAM consumed by this task. So, SWAP here means it represents the total amount of data being swapped out OR still not loaded from disk. Don't be fooled by the name, it doesn't just represent the swapped out data.

    To display the above fields, press 'f' inside the interactive mode. Then press the related key (mentioned above inside the parentheses). Those keys toggle the related fields, so press once to show it, press again to hide it. To find out whether the fields are displayed or not, simply watch the series of letters on the first line (at the right of "Current Fields"). Uppercase means the fields is shown, lower case means the opposite. Press Enter after you are satisfied with the selection.

    Sorting use similar way. Press 'O' (upper case) followed by a key representing the field. Don't worry if you don't remember the key map, top will show it. The new sort key will be marked with asterisk and the letter will change to upper case, so you can notice it easily. Press Enter after you are finished

    {mospagebreak title=Multi view are better than one?}

    E. Multi view are better than one?

    In different situations, sometimes we want to monitor different system property. For example, at one time you want to monitor %CPU and cpu time spent by all tasks. At another time, you want to monitor resident size and total page faults of all tasks. Rapidly press 'f' and change the visible fields? I don't think this is a smart choice.

    Why don't you use Multiple Windows mode? Press 'A' (upper case) to switch to multi windows view. By default, you will see 4 different set of field groups. Each field groups has a default label/name:

    • 1st field group: Def
    • 2nd field group: Job
    • 3rd field group: Mem
    • 4th field group: Usr

    1st field group is the usual group you see in single window view, while the rest are hidden. Inside multi window mode, press 'a' or 'w' to cycle through all the available windows. Pay attention, switching to another window also change the active window (also known as current window). If you are not sure which one is currently the active one, just look at the first line of top's display (at the left of current time field). Another way to change active window is by pressing 'G' followed by windows number (1 to 4).

    Active window is the one which react to user input, so make sure to select your preferred window first before doing anything. After that, you can do anything exactly like you do in single window mode. Usually, what you want to do here is customizing field display, so just press 'f' and start customizing.

    If you think 4 is too much, just switch to a field group and press '-' to hide it. Please note, even you hide current field group, that doesn't mean you also change the active group. Press '-' once again to make current group visible.

    If you are done with multi window mode, press 'A' again. That also make active group as the new field group of single window mode.

    F. "How come there is only so few free memory on my Linux PC?"

    Come to same question? No matter how much you put RAM in your motherboard, you quickly notice the free RAM is reduced so fast. Free RAM miscalculation? No!

    Before answering this, first check the memory summary located on the upper side of top's display (you may need to press 'm' to unhide it). There, you will find two fields: buffers and cached. "Buffers" represent how much portion of RAM is dedicated to cache disk block. "Cached" is similar like "Buffers", only this time it caches pages from file reading. For thorough understanding of those terms, refer to Linux kernel book like Linux Kernel Development by Robert M. Love.

    It is enough to understand that both "buffers" and "Cached" repre- sent the size of system cache. They dynamically grow or shrink as requested by internal Linux kernel mechanism.

    Besides consumed by cache, the RAM itself is also occupied by application data and code. So, to conclude, free RAM size here means RAM area that isn't occupied by cache nor application data/code. Generally, you can consider cache area as another "free" RAM since it will be shrunk gradually if the application demands more memory.

    On the task point of view, you might wonder which field truly represent memory consumption. VIRT field? certainly not! Recall that this field represent everything inside task address space, including the related shared libraries. After reading top source code and proc.txt (inside Documentation/filesystem folder of kernel source's tree), I conclude that RSS field is the best field describing task's memory consumption. I said "best" because you should consider it as approximation and isn't 100% accurate on all time.

    G. Working with many saved configurations

    Wanna keep several different configuration of top so you can easily switch between preconfigured display? Just create symbolic link to the top binary (name it anything you like:

    # ln -s /usr/bin/top /usr/bin/top-a

    Then run the new "top-a". Do the tweak and press 'W' to save the configuration. It will be saved under ~/.top-arc (the format is your top alias name+'rc').

    Now run the original top to load your first display alternative, top-a for the second one and so on.

    {mospagebreak title=Conclusion}

    H. Conclusion

    There are numerous tricks to use top more efficiently. The key is by knowing what you really need and possibly a little good understanding of Linux low level mechanism. The statistics isn't always correct, but at least it is helpful as a overall measurement. All these numbers are gathered from /proc, so make sure it is mounted first!

    Reference:

    • Understanding The Linux Kernel, 2nd edition.
    • Documentation/filesystems/proc.txt inside kernel source tree.
    • Linux kernel source.


    --
    Demo:         http://groupon.gmimi.com
    Dev Blog:    http://blog.gmimi.com
    Gtalk/MSN:  micdim@gmail.com

    Tuesday, August 24, 2010

    How to use rsync for transferring files under Linux or UNIX

    http://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html

    How do you install and use rsync to synchronize files and directories from one location (or one server) to another location? - A common question asked by new sys admin.

    rsync is a free software computer program for Unix and Linux like systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction.

    So what is unique about rsync?

    It can perform differential uploads and downloads (synchronization) of files across the network, transferring only data that has changed. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection.

    How do I install rsync?

    Use any one of the following commands to install rsync.

    If you are using Debian or Ubuntu Linux, type the following command

    # apt-get install rsync
    OR
    $ sudo apt-get install rsync

    If you are using Red Hat Enterprise Linux (RHEL), type the following command

    # up2date rsync

    If you are using CentOS/Fedora Core Linux, type the following command

    # yum install rsync

    Always use rsync over ssh

    Since rsync does not provide any security while transferring data it is recommended that you use rsync over ssh . This allows a secure remote connection. Now let us see some examples of rsync.

    rsync command common options

    • --delete : delete files that don't exist on sender (system)
    • -v : Verbose (try -vv for more detailed information)
    • -e "ssh options" : specify the ssh as remote shell
    • -a : archive mode
    • -r : recurse into directories
    • -z : compress file data

    Task : Copy file from a local computer to a remote server

    Copy file from /www/backup.tar.gz to a remote server called openbsd.nixcraft.in
    $ rsync -v -e ssh /www/backup.tar.gz jerry@openbsd.nixcraft.in:~Output:

    Password:
    sent 19099 bytes received 36 bytes 1093.43 bytes/sec
    total size is 19014 speedup is 0.99

    Please note that symbol ~ indicate the users home directory (/home/jerry).

    Task : Copy file from a remote server to a local computer

    Copy file /home/jerry/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
    $ rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp
    Password

    Task: Synchronize a local directory with a remote directory

    $ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot

    Task: Synchronize a remote directory with a local directory

    $ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webroot

    Task: Synchronize a local directory with a remote rsync server

    $ rsync -r -a -v --delete rsync://rsync.nixcraft.in/cvs /home/cvs

    Task: Mirror a directory between my "old" and "new" web server/ftp

    You can mirror a directory between my "old" (my.old.server.com) and "new" web server with the command (assuming that ssh keys are set for password less authentication)
    $ rsync -zavrR --delete --links --rsh="ssh -l vivek" my.old.server.com:/home/lighttpd /home/lighttpd

    Read related previous articles

    Other options - rdiff and rdiff-backup

    There also exists a utility called rdiff, which uses the rsync algorithm to generate delta files Using rdiff. A utility called rdiff-backup has been created which is capable of maintaining a backup mirror of a file or directory over the network, on another server. rdiff-backup stores incremental rdiff deltas with the backup, with which it is possible to recreate any backup point. Next time I will write about these Utilities :)

    rsync for Windows server/XP

    Please note if you are using Windows, try any one of the program:

    1. DeltaCopy
    2. NasBackup

    10 UNIX Command Line Mistakes

    http://www.cyberciti.biz/tips/my-10-unix-command-line-mistakes.html

    Anyone who has never made a mistake has never tried anything new. -- Albert Einstein.

    Here are a few mistakes that I made while working at UNIX prompt. Some mistakes caused me a good amount of downtime. Most of these mistakes are from my early days as a UNIX admin.

    userdel Command

    The file /etc/deluser.conf was configured to remove the home directory (it was done by previous sys admin and it was my first day at work) and mail spool of the user to be removed. I just wanted to remove the user account and I end up deleting everything (note -r was activated via deluser.conf):
    userdel foo

    Rebooted Solaris Box

    On Linux killall command kill processes by name (killall httpd). On Solaris it kill all active processes. As root I killed all process, this was our main Oracle db box:
    killall process-name

    Destroyed named.conf

    I wanted to append a new zone to /var/named/chroot/etc/named.conf file., but end up running:
    ./mkzone example.com > /var/named/chroot/etc/named.conf

    Destroyed Working Backups with Tar and Rsync (personal backups)

    I had only one backup copy of my QT project and I just wanted to get a directory called functions. I end up deleting entire backup (note -c switch instead of -x):
    cd /mnt/bacupusbharddisk
    tar -zcvf project.tar.gz functions

    I had no backup. Similarly I end up running rsync command and deleted all new files by overwriting files from backup set (now I've switched to rsnapshot)
    rsync -av -delete /dest /src
    Again, I had no backup.

    Deleted Apache DocumentRoot

    I had sym links for my web server docroot (/home/httpd/http was symlinked to /www). I forgot about symlink issue. To save disk space, I ran rm -rf on http directory. Luckily, I had full working backup set.

    Accidentally Changed Hostname and Triggered False Alarm

    Accidentally changed the current hostname (I wanted to see current hostname settings) for one of our cluster node. Within minutes I received an alert message on both mobile and email.
    hostname foo.example.com

    Public Network Interface Shutdown

    I wanted to shutdown VPN interface eth0, but ended up shutting down eth1 while I was logged in via SSH:
    ifconfig eth1 down

    Firewall Lockdown

    I made changes to sshd_config and changed the ssh port number from 22 to 1022, but failed to update firewall rules. After a quick kernel upgrade, I had rebooted the box. I had to call remote data center tech to reset firewall settings. (now I use firewall reset script to avoid lockdowns).

    Typing UNIX Commands on Wrong Box

    I wanted to shutdown my local Fedora desktop system, but I issued halt on remote server (I was logged into remote box via SSH):
    halt
    service httpd stop

    Wrong CNAME DNS Entry

    Created a wrong DNS CNAME entry in example.com zone file. The end result - a few visitors went to /dev/null:
    echo 'foo 86400 IN CNAME lb0.example.com' >> example.com && rndc reload

    Failed To Update Postfix RBL Configuration

    In 2006 ORDB went out of operation. But, I failed to update my Postfix RBL settings. One day ORDB was re-activated and it was returning every IP address queried as being on its blacklist. The end result was a disaster.

    Conclusion

    All men make mistakes, but only wise men learn from their mistakes -- Winston Churchill.

    From all those mistakes I've learnt that:

    1. Backup = ( Full + Removable tapes (or media) + Offline + Offsite + Tested )
    2. The clear choice for preserving all data of UNIX file systems is dump, which is only tool that guaranties recovery under all conditions. (see Torture-testing Backup and Archive Programs paper).
    3. Never use rsync with single backup directory. Create a snapshots using rsync or rsnapshots.
    4. Use CVS to store configuration files.
    5. Wait and read command line again before hitting the dam [Enter] key.
    6. Use your well tested perl / shell scripts and open source configuration management software such as puppet, Cfengine or Chef to configure all servers. This also applies to day today jobs such as creating the users and so on.

    Mistakes are the inevitable, so did you made any mistakes that have caused some sort of downtime? Please add them into the comments below.