Wednesday, November 27, 2013

美国兰德公司对中国人的评价

美国兰德公司是一家著名的非盈利的研究机构,为美国官方提供“客观的分析和有效的解决方案”。最近,他们公布了一份对中国现状分析报告,即有肯定,也有严厉批评,值得国人反省。本文观点来自兰德公司亚太政策中心。
  
   如果20世纪的中国是一个富裕和统一的国家,我们会有一个完全不同的第一次世界大战,我们就不会有第二次世界大战而是第二次欧洲大战。中国能够阻止日本侵 略或者打败日本。美国在这些冲突上的花费从根本意义上会减少很多,因为珍珠港事件不会发生。我们和整个世界,更不用说10亿中国人,一个多世纪以来,已经 为中国的弱小付出了惨重的代价。世界需要一个健康的中国。
  中国的需求对日本走出衰退起到了促进作用。日本状况给世界经济带来了风险。关于这一点,怎么说都不夸张。日本巨额的债务会产生多米诺骨牌效 应,逐渐波及到全世界。在中国有力的帮助下,危险似乎已经过去。中国全球化给美国带来了很多影响。最明显的是,中国成为美国商品最大的市场。
  
   可口可乐早就完成了那个看上去像是神话的目标:卖10亿瓶可口可乐;曾经嘲笑中国梦的通用在中国卖了很多的别克汽车,在困难时期,中国带来的利润占通用利 润的很大一部分;中国联想购买IBM个人电脑业务,挽救了这个垂死部门的工作岗位。中国提供更低价的生活必需品给美国人的生活水平做出了很大的贡献,尤其 是对我们不是那么富裕的居民而言。有迹象表明由于能够购买中国低价的出口货物,低收入美国人的生活水平可能提高了5%到10%。
  
   中国金融体系的不合理意味著中国建造了垂死企业,导致巨大的生产力过剩。近些年来,中国财政政策上的反复无常导致过度建造,对铁、铝、水泥和其他原材料产 生了巨大的需求。日本人和现在的中国人看上去似乎会买下世界上所有的东西,但是当你看到他们的财政状况的潜在问题时,你会发现一个黑洞。日本人在90年代 陷入了这样一个黑洞,至今还在努力地爬出来。中国人很多年后仍将会为目前这种无节制的狂热的购买行为感到心痛。
  
   目前,中国面临著巨大的挑战。中国的银行是我们所知道的世界上最糟糕的银行。中国每一代,都有相当于美国规模的人口从农村涌入城市。每年,都有1200— 1300万新工人加入就业大军。在制造业,生产力对就业的影响比我们国家要严重得多。到2020年,中国人口老龄化会使工作人口与不工作人口的比率成为世 界上最糟糕的,比日本更甚。如果没有特效的新政策的话,中国的经济在那个时期就会狠狠地撞墙。到2020年,以我们的标准来看,它会是一个非常穷的国家。
  
   中国人缺乏诚信和社会责任感。中国人不了解他们作为社会个体应该对国家和社会所承担的责任和义务。普通中国人通常只关心他们的家庭和亲属,中国的文化是建 立在家族血缘关系上而不是建立在一个理性的社会基础之上。中国人只在乎他们直系亲属的福址,对与自己毫不相关的人所遭受的苦难则视而不见。毫无疑问,这种 以血缘关系为基础的道德观势必导致自私,冷酷,这种自私和冷酷已经成为阻碍中国社会向前发展的最关键因素。
  
   中国从来就没有成为一个法制社会,因为中国人的思维方式与守法行为格格不入。中国人老想走捷径。他们不明白这样一个事实:即成就来自于与努力工作和牺牲。 中国人倾向于索取而不给予。他们需要明白一个道理:生活的真蒂不在于你你索取多少而在于你能给予社会和你的人类同胞多少。
  
   大多数中国人从来就没有学到过什么是体面和尊敬的生活意义。中国人普遍不懂得如何为了个人和社会的福址去进行富有成效的生活。潜意识里,中国人视他们的生 活目的就是抬高自己从而获得别人的认知。这样一来,一个人就会对"保有面子"这样微不足道欲望感到满足。"面子"是中国人心理最基本的组成部分,它已经成 为了中国人难以克服的障碍,阻碍中国人接受真理并尝试富有意义的生活。
  
   这个应受谴责的习性使得中国人生来就具有无情和自私的特点,它已成为中国落后的主要原因。
  
   中国人没有勇气追求他们认为正确的事情。首先,他们没有从错误中筛选正确事物的能力,因为他们的思想被贪婪所占据。再有,就算他们有能力筛选出正确的事情,他们也缺乏勇气把真理化为实践。
  
   中国人习惯接受廉价和免费的事物,他们总是梦想奇迹或者好运,因为他们不愿意付出努力,他们总想不劳而获。很少有中国人明白一个事实,就是威望和成就是通 过一步步努力的工作和牺牲实现的,不付出就没有所得。简单来说,如果是为了谋生,那一个人只有去索取;但如果是为了生活,一个人必须要去奉献。
  
   由于在贫穷的环境下生长并且缺少应有的教育,大多数中国人不懂得优雅的举止和基本的礼貌。他们中的大多数人着装笨拙粗鄙却不感到害羞。他们在青少年时所受的教育就是如何说谎并从别人那里索取,而不是去与别人去分享自己的所有。
  
   中国是一个物产丰富的国家。但无限制生育政策所带来恶果使得中国成为了无限廉价劳动力的输出国。这些输出也包括那些受过教育的劳力输出,除了他们的教育水平,实则和其他一般苦力没有本质上的区别。
  
   中国大规模生产的便宜产品降低了输入这些产品的地区的商业信用度。由于技术落后,管理失败,中国制造的单位能耗要比发达国家如日本,美国高出很多。因此, 随着出口额的增加,中国在扩大生产的同时丧失着宝贵的能源。同时,这种行为也严重的污染了环境,使中国变为全世界最不适宜人类居住的国家。
  
   目前中国正在遭受着资本主义社会2大邪恶的折磨,即环境的破坏与人性的丧失。由于中国人天生的贪婪的本性,它们可以毫无保留的接受资本主义的阴暗面即无止 境的追求利润,忽视人的尊严。中国人对西方的技术与产品狂热追求却对西方管理文化所强调的坦率,直接,诚实这些品质漠不关心。
  
   由于中国文化不鼓励敢于冒险这种优良品质,所以中国人极力避免冒险,他们也不想寻求机会来改善自己的生活。中国人对于生活的平衡性和意义性并不感兴趣,相 反他们更执迷于对物质的索取,这点上要远远胜于西方人。大多数中国人发现他们不懂得"精神灵性","自由信仰"以及"心智健康"这样的概念,因为他们的思 想尚不能达到一个生命(补:即肉体和灵性的并存)存在的更高层次。他们的思想还停留在专注于动物本能对性和食物那点贪婪可怜的欲望上。
  
   在中国人的眼中,受教育不是为了寻求真理或者改善生活质量,而只是身份和显赫地位的象征和标志。中国的知识分子从别人那里得到尊敬并不是因为他们为了别人 的幸福做过什么,而只是因为他们获得占有了相当的知识。事实上,他们中的大多数只不过是一群仅仅通晓考试却从不关心真理和道德的食客。
  
   中国的教育体系很大程度上已经成为一种失败和耻辱。它已经不能够服务于教育本应所服务的对象:社会。这个教育体系不能提供给社会许多有用的个体。它只是制造出一群投机分子,他们渴望能够受益于社会所提供的好处却毫不关心回报。
  
   中国可以培养出大批的高级能人才,但却很少可以培养出合格的可以独立主持的管理级专家。服务于一个公司或者社会,光有技术是不够的;还需要有勇气,胆量, 正直和诚实的领导才能,这恰恰是大多数中国人所缺少的品性。正如亚瑟.史密斯,一位著名的西方传教士一个世纪前所指出的,中国人最缺乏的不是智慧,而是勇 气和正直的纯正品性。这个评价,虽然历经百年,如今依旧准确诊断出中国综合症的病因。
  
   大多数中国毕业生对选择出国并为外国工作不会感到内疚,事实上他们首先欠下了中国人民在教育上为他们所做出的牺牲。随着传统文化价值观的破坏和逐步衰弱,大多数的中国人,包括受过教育的人都徘徊在精神和内心世界的路口,像迷失的狗一样不知何去何从。

中日东海之战,美国是否会参战?

战争是流血的政治,政治是不流血的战争。无论哪一种,都是为了一个最终目的---
“国家利益”。

没有利益可得的战争是打不起来的,即使偶然爆发了,也不会长久。

所谓中日爆发战争,美国必然参战,中国必败的说法,都是日本人在狐假虎威的吓唬中
国人。从利益的角度分析就可以知道这一点。因为中美爆发大规模冲突,得利最多的就
是日本,一来日本可以借机摆脱美国的控制,成为正常国家,自由的扩军和发展核武器
,二来可以严重削弱中国,为日本发动下一次侵华战争做好铺垫,三来日本还不必付出
任何代价。

同样的,从利益分析的角度就可以知道,这种说法不可能是美国提出来的,且不说中国
还在大把的购买美国国债,为美元背书,也不提美国在中国大把的投资,光是跟中国爆
发全面核战争这条,就足以让美国80%的民众和政治家摇头了。美国当年那么仇视苏联
,还没有悍然挑起跟苏联的全面战争。现在跟中国经济上是全面合作,金融方面急需中
国支持,凭什么要为了一个小日本去跟中国拼命?关于核战争的游戏规则,我已经在转
帖的黄金童的《核乌云笼罩下的台海大国战争游戏规则》里面说过了,链接在此

http://www.mitbbs.com/article_t0/Military/40686973.html

比较符合美国利益的做法,是推翻中共政府,让中国的生产基地永远处于美国的操控之
下,实现美国消费,中国生产,中国制造的产品全部用美元结算,然后美元借助这一点
继续把持世界经济一百年。美国最想避免的,就是跟中国爆发全面战争,因为第一,这
样就意味着中国会抛掉全部的美国国债,这对美国经济也好,美元也好,都是致命的打
击;第二,有导致全面核战争的危险,美国有可能亡国或者解体;第三,美国的物价因
为没有了中国产品的牵制,会进入恶性膨胀的阶段,有可能导致美国发生革命,或者法
西斯化。以上三条全部不符合美国的国家利益。因此美国不可能考虑跟中国爆发全面战
争。最多是让中国跟周边国家发生摩擦和小规模冲突,冲突规模掌握在美国手中,这样
既可以消耗中国,又可以借机大把的向中国周边国家出售军备,又可以让东亚的热钱出
逃美国来托底美国经济,更重要的是还可以让亚洲国家互相憎恨,无法形成一个统一的
经济体,无法抛弃美元使用亚元。

因此,本熊推断,东海必有战争,但是必然是在中日之间展开。中国是为了打服日本,
杀一儆百,给今后的和平崛起建立一个和平稳定的周边环境;日本是试图借助战争打掉
中国崛起的势头,同时拉美国下水,借机实现自己国家的正常化和扩军;美国希望中日
交恶,阻止亚洲经济一体化。

其中,日本对于挑动战争最为迫切,因为日本非常明白,过了这村就没这店了。基本上
2020年以后,日本就
彻底没希望了。

损失最大的会是日本,因为日本有两个误判。

1,日本低估中国的军事实力,以为自己的高科技海空军可以轻松打败中国海空军。实
际上这并非是基于事实,而是基于日本100多年前日清战争留下的美好感觉。面对中国
,日本由于受到美国的严格限制,在海、陆、空、天和电磁五个较量纬度上都不占优势
,唯一占优势的其实就是几个狭小的科目,譬如反潜和扫雷。真的发生战争,日本可以
动用的飞机没用中国多,可以打击中国大陆飞机场的手段几乎没有,面对中国的三代半
战机,可以匹敌的战机基本没有,面对中国的超音速反舰导弹的饱和攻击,可以有效对
付的军舰没有,面对中国的战术核武器就更不用提了,简直就是王八进食堂---开宰
的货。日本之所以这么硬,就是基于第2个误判。

2,日本认定美国必然参战。日本认为美国会为了遏制中国崛起而跟中国开战。因为他
们高估了美国的实力,低估了中国的实力。现在实际上美国对中国的需要大于中国对美
国的需要。前面已经分析了,跟中国开战,并不符合美国的利益。相反,美国更希望中
日发生冲突,自己好继续维持在亚洲的存在,同时防止产生亚元。

因此,战争一旦开始,日本就会发现中国海空军再加上二炮,对于弱小的自卫队而言,
简直是一场噩梦。中国军队会上来就通过巡航导弹和弹道导弹的饱和攻击废掉日本的机
场,导致日本海上自卫队缺少空中掩护。然后中国海军航空兵的超音速导弹饱和攻击,
让海上自卫队连中国军舰的影子都见不到,就见阎王了。最让日本跌眼镜的会是,美国
仅仅是做做样子,派航母和B2到日本近海和关岛转一圈,就坐着不动。日本自己眼巴巴
盼望的中美两个巨兽之间的大战没有发生。结果是日本不得不自己掏钱重新从美国购置
军备,背负更加沉重的财政负担,同时还不得不把变成正常国家的美梦再往后推迟30年。

这还不是最糟糕的,最糟糕的会是中国空军和北海、东海、南海三大舰队没完没了的轮
战,不停的到冲绳叫战,要求日本归还琉球主权,不然就轰炸和袭扰冲绳。日本进也不
是(没钱),退也不是(民
族主义需求),苦不堪言。在连续10年的断断续续的地区冲突中逐渐被收拾的国穷民贱
,逐步
菲律宾化,接着日本新娘遍布中国沿海的富裕城市,日本天皇在无力回天的万分绝望中
迎来一个全新的GDP相当于美国数倍的盛世中国和一支比美国海军还要强大的多的多的
中国远洋舰队,唯一能考虑跟中国谈的话题就是如何解释自己的国家在过去150年里面
对中国的所作作为。。。。。。。

Sunday, November 24, 2013

Josef koudelka



"Koudelka's work petrifies and transforms. It converts tears into stone and stone into wounds; it sees the soul through its hardships. The moment that he captures contains centuries. The space that the image encloses opens the field of the universe, both inside and out. It is the theatre of opaque skies, where humanity is so minuscule, and yet such a vast mystery."  - Dominique Edde











Thursday, November 21, 2013

无题

把一些话说出来了,心里终于没有那么压抑。现在就希望黎明会终有一天出现。

Wednesday, November 20, 2013

无题

最近每当接近下班都很害怕。害怕家里的寂静,害怕心里的煎熬。太阳何时才再出现呢?

很想和她讲和,结束这场冷战。但是心里面那个懦弱的我却萎缩不前,就这样任凭这个状态一天一天地拖下去。真的不想把情况进一步弄僵,然而我的身心却一再逃避,逃避,以为有一天所谓问题都会自己解决。

Tuesday, November 19, 2013

无题

明明很爱她,却不知如何是好。

Saturday, November 16, 2013

Gary Winogrand

Recently I started reading a photobook on Gary Winogrand's works. He is one of the most important photographers of America in the twentieth century. His works was mostly shot on the streets of New York city, during 1950s and 1960s, documenting the transformation of the country in the post-war era. His pictures, often shot with a wide angle lens, present the viewer with lots of juxtapositions of fragments of facts about a scene, but leaving the viewer to interpret what is actually happening. Women, are one of Winogrand's favorite photographic subjects.

Here are some of my favorites from Winogrand.







Tuesday, November 12, 2013

Sunday, November 10, 2013

A good street photography photo

"A good street photography photo is either a documentary of something interesting, or an interesting way of documenting something ordinary."

- Severin Koller

More photos from Severin Koller

I really enjoy the works from the austrian photographer, Severin Koller. Most of his photos were taken with films. Here are some of his photos found from the Leica Camera Blog.

His black and white images are rich in soul and stories. On why he prefers shooting film on the street, here is what he said:

"There are subjects I only capture because I know it will look beautiful with black-and-white film and there are those I don’t even consider photographing since they will only work in color. Needless to say, a lot of images can work both ways. Also, my personal approach is focused on a timeless look."

" Also, it takes me several minutes of work to do that on the computer, while a black-and-white negative is what it is. If you have endless possibilities of changing and manipulating photographs, then you can easily miss the point of what photography is about. You’re not a good photographer when you have to manipulate your photographs."







Thursday, November 7, 2013

Konica Hexar AF

Some nice photos taken with Konica Hexar AF by Severin Koller.









Monday, November 4, 2013

Daido Moriyama







" Cities are enormous bodies of people's desires, and as I search for my own desires within them, I slice into time, seeing the moment. That's the kind of camera work that I do."

-- Daido Moriyama

Sunday, November 3, 2013

Wednesday, August 28, 2013

The curious one



When all the brain-washed look to one direction, the curious one looks the other way.

Thursday, August 15, 2013

Struggling to survive


Vega Omer's famous black and white photo, "Struggling to survive". Very powerful message.

Wednesday, June 5, 2013

Understanding aperture: The 3 types, when to use them, and why

Aperture can feel like a tricky beast at first. But once you have a sense of what it is — the idea of depth of field — it’s time to look at how to put these tools to use for your own vision with photography.
Even though f-stops number from f/1.4 to upwards of f/22, aperture can be divided into three major sections, each with its own distinct use. Which section and corresponding f-stop you choose becomes up to you, and your vision.


Storytelling
What it is: Storytelling aperture is considered to be f/13 and up, as high as f/22, or f/29 on some lenses. If you can recall, the higher the f-stop, the smaller the aperture, and the greater depth of field. This means the image should have front-to-back sharpness.
Uses: This is often used in landscape photography, where you want the foreground just as much in focus as the background. If you’re telling a story, then you need a foreground object, a middle ground, and a background, all of which “lead” your viewer through the image. This could be a dirt road (foreground) leading up to a barn (middle) with puffy white clouds behind (background). It could be a jagged rock (foreground) in a calm, clear lake (middle) backing into the Grand Tetons (background).
Alternative uses: Higher f-stops are often used at night because the tiny pin-hole aperture makes any point of light (i.e., a streetlamp) turn into a starburst. To compensate though, the shutter speed needs to be long and therefore a tripod is necessary.
Do not use for: Faces. Higher f-stops are simply not flattering on the human face.
Drawbacks: When everything is in focus, you need to make sure your viewer knows exactly what your subject is. If it’s not going to be the object most in focus, then you have to use leading lines, composition, and/or light to reveal the subject of the image.
Remember: The higher the f-stop, the less the light. Therefore you need to lower your shutter speed (or use Av and the camera will do it for you), which could mean that you need a tripod if it goes under 1/50. Alternatively, you can boost your ISO, but this adds noise to the image.
Best lens: A wide angle lens (roughly 10mm-20mm) will allow you to fit the whole story into the scene.


The sweet spot
What it is: The range is roughly f/7.1 – f/11. It is said, and overall believed to be true, that f/9 or f/11 are the “sweet spots” on any given lens. That means they have optimum sharpness, contrast, colour, and least amount of lens distortion or aberration.
Uses: These stops are great for street photography and shooting on the move. Overall they are sharp, usually give nice contrast, and generally maximize the optics of the lens in use. They can be put to use for landscapes, street scenes, scenes with people in them, or any other situation in which your “subject” might change quickly (say from a purple door, to a man pushing a cart, with little time to change settings).
Alternative uses: Sunrises and sunsets, where you want overall sharpness and contrast. Also, night scenes where you’re not looking for starbursts but want good sharpness.
Don’t use for: Faces. Even f/7.1 still isn’t the most flattering for portraits.
Remember: Both “storytelling” and “sweet spot” apertures will be hard to work with inside, under shade, or any time the light starts to drop. Same as with “storytelling,” it is up to you to make sure the viewer knows what the subject of the image is, using techniques other than isolation.
Best lens: If you are aiming for street photography, a semi-zoom is the best bet (e.g., 24mm-70mm or 18mm-200mm) to allow you to pull out and back in, as your subjects change. However, in terms of shooting at f/9 or f/11, it’s the sweet spot on nearly any lens.
Isolation
What it is: Apertures under f/5.6, all the way down to f/1.2. The lower the f-stop, the more wide open the aperture, the more shallow the depth of field.
Uses: The main use of a wide aperture is to isolate a subject. When you focus in on your subject — say, a person’s face — the background will blur. This blur can range from slightly out of focus (e.g., f/4) to completely unrecognizable (e.g., f/1.4). When the subject is isolated, it’s very clear to the viewer what the subject of the photo is, which can make for very strong images. It is flattering on faces because of the softer focus, but be sure to focus on the eyes!
Other uses: Lenses that are 2.8 and under are called “fast” lenses. This is because when you have the ability to drop down to f/2.8, f/2, f/1.4, or even f/1.2, your shutter speed can remain high enough to ensure sharpness and clarity. This comes in especially handy in low-light situations: Where kit lens users (often stuck at f/4) will have to attach a flash, boost their ISO (and increase noise), or whip out a tripod, those with “fast glass” can drop down to f/2.8 or f/1.4 and continue shooting (to an extent).
Another use is to create a lovely “bokeh” behind your subject — points of light which become pretty ovals when out of focus. Lastly, it’s useful for shooting situations which require the fastest possible shutter speed, such as macro, sports, or wildlife, so a fast lens is necessary to ensure sharpness, focus, and clarity.
Don’t use for: Landscapes or any scene requiring overall sharpness.
Remember: When opening up to f/2.8, or especially f/1.8 or f/1.4, your focal area — where there is sharpness — becomes very, very small. Even on a face, you can have sharp eyes, but lose sharpness on the mouth or hair (which can look lovely when done creatively). You therefore need to be very accurate that you are nailing your focus on your subject (especially if a face). A portrait with one blurry eye is never a good thing. Another thing to note is that you can create extra blur / bokeh by putting distance between your subject and the background (the closer the background, the more in focus; the farther away, the less in focus).
Best lens: Depends on the end goal. If you’re into travel portraits — where sometimes there is a bit of distance between you and a subject — a fast lens with a bit of zoom is handy, such as 24mm-70mm f/2.8. If you’re really into intimate portraits, the 50mm f/1.8 or f/1.4 is beautiful on faces, though you will have to move your feet to get the right composition.
For shooting wildlife, you need both zoom and a fast aperture, so things start to get pricey. Still, if it’s your thing, a 70-200mm f/2.8 is the way to go (which is also good for travel / street portraits, but overall it’s best to ask rather than try to sneak a shot).

Sunday, May 5, 2013

Numerical Solution to Ordinary Differential Equations

Ordinary differential equations (ODEs) are commonly encountered in scientific and engineering analysis. The simplest form of ODEs is the 1st order ODEs:

y' = f(y, x)

Here, y(x) is the function dependent on x, and it is the function that we want to solve for. X is the independent variable. The left hand side of the equation is the first order derivative of the function y, while the right hand side of the equation is a function that links the derivative to some combination of y and x. Function y is also known in ODEs as the solution function, while function f(y, x) is known as the flow function.

In generally, ODEs can be more than 1st order. It can be readily shown that, any ODEs (of any order) can be rewritten as a system of 1st order ODEs. Take the motion equation for the harmonic oscillator as an example:

x(t)'' = -k/m*x(t)

This equation can be rewritten as two 1st order ODEs:

 x' = F1(x,v,t) =v
v' = F2(x,v,t)=-k/m*x

Here, the harmonic oscillator 2nd order ODE is rewritten as a system of two 1st order ODEs, where there are two solution variables, x and v, two flow functions, F1 and F2, and one independent variable, t.

Numerical solutions to ODEs are readily achievable through discreet integration. The idea is that given an initial condition, i.e. y(x=x0), one can approximately compute the value of y at the next step, i.e. y(x=x0+h), assuming h is sufficiently small. The most straightforward solution is the Euler method. Takes the simplest, 1st order ODE as an example, at any given step, one can approximate the next step as:

y(n+1) = y(n) +h*f(y(n),x(n))

The essence of the Euler equation shown above is that, the next y value can be approximated by the current y value y(n), plus the step size times the derivative (slope) of the current x location, x(n). This is quite a crude estimation, because the derivative of y could change as x changes from x(n) to x(n+1). However, as a first order approximation, sometimes the Euler method is good enough, and its advantage is that it's easy to understand.

The Euler method can be easily extended to solve any ODEs with more than 1st order. As shown earlier, any ODE can be rewritten as a system of 1st order ODEs:

Y' = F(Y, x)

Here, vector notion is used to simplified the presentation of an ODE system. Y is a vector of all the solution variable in the system, while F is the vector of all the flow functions in the system. Therefore, Y is also known as the solution vector, while F is known as the flow vector. For example, in the harmonic oscillator example, Y=(x,v), and F=(F1(x, v, t), F2(x, v, t)).      

Applying the Euler method to an 1st ODE system is very similar to a single 1st order ODE:

Y(n+1) = Y(n) + h*F(Y(n), x(n))

Here, Y and F are both vector, while, h and x are scalar. The equation above in fact represents a set of equations. The vector notation is just to simplify the presentation of them. 
The disadvantage of the Euler method, despite its simplicity and intuitiveness, is that it's quite unstable, and tends to produce large error. In the next blog entry, we will introduce another method, the Runge-Kutter method, which is the work house for most of numerical analysis of ODEs.

Friday, May 3, 2013

Block comment and uncomment codes in VIM

In VIM, it is quite easy to comment/uncomment a block of lines.

To comment a block of lines:
a. Ctrl-V and mark the block of lines to be commented out;
b. shift-I and write the text that you want to prepend to each line, e.g. #
c. press escape.

To uncomment a block of lines:
a. Ctrl-V and go down vertically until the last commented line;
b. press x.

Thursday, April 25, 2013

Memory Segmentation of a Compiled Program

When a program is compiled and executed, it is loaded into the computer memory as binary codes.
Such binary codes of one program is structured in five segments, in the memory space. Each segment represents a special portion of the memory that is set side for a certain purpose.

Figure 1



The five segments of program memory are shown in figure 1. The first segment is called the Text segment, or Code segment. This is where the assembled machine language instructions of the program are located. Once started, the cpu will read and execute these instructions, one at a time. The register EIP always points to the next instruction to be executed. The execution of the instructions is not necessarily linear in the memory space, since the flow of execution is often redirected by control structures and functions.

The Data and Bss segments, are used to stored global and static variables. Specifically, the data segment is filled with initialized global and static variables, whereas the bss segment is filled with their  uninitialized  counterparts. Both data and bss segments are of fixed sizes.

The next segment down in the memory axis is the  Heap segment. It is a segment of memory that a programmer can directly control. Blocks of memory in this segment can be allocated and used. The size of the heap is dynamic, and it can be managed by allocator and deallocator algorithms. This means a programmer using the heap allocation functions can reserve and free memory on the fly. The growth of the heap moves downward toward higher memory addresses.

The last segment, Stack segment, is a very important a unique segment that deserves more explanation. In a modern program where a lots a functions are called by the main function, The flow of the instruction execution is managed by a mechanism call stack frame. When a function is called by the program, the program needs to remember a few things: the address of the next instruction to run after the function call is finished, the set of local variables associated with this function, the parameters passed to this function during this call. All of these information is stored collectively in the block of memory called stack frame. Each function call will create a stack frame in the stack segment. Figure 2 shows the content of one stack frame.

Figure 2


In the stack frame shown in Figure 2. Starting from the bottom of the stack, parameters passed to the functioned called are stored. The address of the instruction that the execution flow will return after the function call finish is stored above the parameters. The next slot up (lower address) is the so-called saved framed pointer, which is the address of the frame pointer of the previous stack frame. The address of this slot is stored in the EBP register, which always stores the frame pointer of the CURRENT stack frame. Above the saved frame pointer, the local variables are stored. The top of the current stack frame is always pointed by another register, ESP. If the function in question is calling another function, then the value in ESP will become the value of the frame pointer in the next stack frame. After the call of the function, the current stack frame will be popped out, and the previous stack frame then becomes the current stack frame.

Monday, April 15, 2013

US Imperialism and China

US imperial dreams, however, are hardly confined to setting the Middle East ablaze. Imperial ambitions—rooted in the capitalist logic of endless expansion—are inherently limitless. Thus, we see the US today readying to propel the greater Middle East into the abyss, while simultaneously “pivoting” to the Asia-Pacific in order to “contain” a rising China.

US imperialism, however, is destined for defeat (and sooner rather than later). The US, after all, can only use its immense military power to keep potential competitors in check for so long. The universal law of change cannot be held at bay by the barrel of a gun in perpetuity. As Lenin asked and answered in his pamphlet Imperialism: “Is it ‘conceivable’ that in ten or twenty years’ time the relative strength of the imperialist powers will have remained unchanged? Absolutely inconceivable.”

But imperial powers are always dangerously deluded by the strength of their power—impervious to its ultimate limits. As a George W. Bush administration official once remarked to the journalist Ron Suskind: “’We’re an empire now, and when we act, we create our own reality. And while you’re studying that reality—judiciously, as you will—we’ll act again, creating other new realities, which you can study too, and that’s how things will sort out. We’re history’s actors…and you, all of you, will be left to just study what we do.”
(One would be mistaken to believe that such hubris is not as present in the Obama White House as it was in the Bush administration.)

Such arrogance from the power elite—indicative of imperial rot—is but a byproduct of the imperialist imperative of endless expansion and conquest. And it is this very imperative that today compels US imperialism towards igniting a military conflagration in the Middle East threatening to ensnare the global powers. “A great cemetery,” as Luxemburg warned nearly a century ago, awaits such a triumph of barbarism."

A few months ago, James Baker remarked on the Charles Rose show that America is Greece if the dollar were not a reserve currency. Yet the US refuses to reduce Pentagon expenditure even though investment on infrastructure construction is much more productive. Obama's current strategy is that the US could pursue its war policies indefinitely as long as no Americans are killed. That is the reason why drones are extensively used all over the world. However, I firmly believe that this empire building policy is unsustainable and sooner or later the US will follow the Soviet Union as the next country that collapses economically due to military overspending.

Here is what Paul Craig Roberts (an editor of the Wall Street Journal and an Assistant Secretary of the U.S. Treasury) wrote recently:  "Why is Washington ramping up a new cold war?

The answer begins with President Eisenhower’s warning to the American people in his last public address about the military/industrial complex in 1962. I won’t quote the warning as it is available online. Eisenhower pointed out to Americans that unlike previous wars after which the US demilitarized, after World War II the cold war with the Soviet Union kept the power and profits flowing into the military/industrial complex, now known as the military/security complex. President Eisenhower said that the flow of power and profit into the military/industrial complex was a threat to the economic wellbeing and liberty of the American people.

No one paid any attention, and the military/security complex was glad to be rid of the five-star general war hero president when his second term expired."

"In other words, the problem with hot wars is that the need not to win them in order to keep them going (Korea, Vietnam, Iraq, Afghanistan are all long-term wars never won) in order that the profits and power continue to flow to the military/security complex demoralizes the US military and creates the world-wide impression that the “world’s sole superpower” cannot even defeat a few thousand insurgents armed with AK-47s, much less a real army.

In Iraq and Afghanistan more US soldiers have died from demoralization and suicides than from combat. In Iraq, the US was humiliated by having to end the war by putting the Sunni insurgents on the US military payroll and paying them to stop killing US troops. In Korea the US was stopped by an army of a backward third world country that lived on rice. What would happen today if the US “superpower’s” militarily confronted China, a country with an economy on which the US is dependent, about equal in size to the US economy, operating on its home territory? The only chance the evil in Washington would have would be nuclear war, which would mean the destruction of the entire world by Washington’s hubris.

Fortunately, profits are more important to Washington than ending life on earth. Therefore, war with China will be avoided, just as it was avoided with the Soviet Union.

However, China will be presented by Washington and its prostitute media, especially the New York Times, Washington Post, and Murdoch’s collection of whores, as the rising threat to America. The media story will shift the importance of America’s allies from Europe to countries bordering the South China Sea. American taxpayers’ money, or newly printed money, will flow into the “new alliance against China.”

China’s rise is a great boon to the US military/security complex, which governs america in which there is a pretense of “freedom and democracy.” China is the profitable replacement for the “Soviet threat.” As the days go by, the prostitute media will create in the feeble minds of Americans “The CHINA Threat.”

Soon whatever little remains of the US living standard will be sacrificed to Washington’s confrontation with China, along with the seizure of our pensions and personal savings in order to deter “the China threat.”
If only Americans were an intelligent people. Then they might have some prospect of holding on to their incomes, remaining wealth, and liberty. Unfortunately, Americans are so thoroughly plugged into the Matrix that they present as a doomed people, incapable of thought, reason, or ability to comprehend the facts that the rest of the world sees clearly."

All this hype about Iran, China, etc. is all designed to ensure that the Pentagon does not get hit by budget cuts!!!

Sunday, April 14, 2013

GNU Developer Tools

Here are a few debugging tools from the GNU developer toolkit. They are commonly available in most of the Linux distribution. My Linux box runs Ubuntu 12.10.

1. objdump: display hexadecimal and assembly representations of machine languages of an executable.

typical usage: objdump -D 'name-of-the-executable'

You need to understand assembly language to be able to tell what's in output.

2. gdb: debugger to allow programmer to step through a compiled program and examine program memory and processor registers.

A GDB session can be launched as followed:

gdb -q 'name-of-the-executable'

Then one can interactively enter commands to control the start, pause, quit the program, or set breakpoints and examine register values. Common commands used in gdb are:

-break 'function_name': set breakpoint at the entry of a function
-run: start the program (until breakpoint)
-disassemble function: disassemble a function into assembly language
-info registers: see the values in the registers
-info register name-of-register: see the values stored in a particular register
-x/Nxw $name-of-register: examine the content of the memory, pointed by the register. N indicates the number of words to after that starting address.
-x/i: examine the assembly instruction pointed by an address.
-x/s: examine the string pointed by an address.
-continue: continue (until the next breakpoint or the end of the program)
-quit: quit the program

3. Hexdump: to display the hexadecimal content of a file. Common options:

- hexdump -C filename: to display the content of the file in hex, one byte at a time, followed by character

- hexdump -x filename: to display the content of the file in hex, two bytes at a time.

Thursday, March 28, 2013

中国房市泡沫化

中国的房价很明显已经泡沫化。数据(见图)显示,北京房价是当地人民平均年收入的30倍。相比之下,纽约才8倍。房价收入比靠前的国家基本都是腐败落后,贫富分化严重的国家(除了罗马)。任志强说中国的房价是由市场决定。这个没错。但是这个所谓市场是富人和官商勾结的市场,不是平民百姓的市场。



Wednesday, March 27, 2013

HDI Development in Korea

Korea has experienced dramatic changed in the last three decades, specifically in economic development. Although the rate of its economic growth is similar to China, its improvement in education and health clearly outpaces those of China (see figure 1).


Tuesday, March 26, 2013

日本材料技术的世界领先地位

材料学的水平极大程度决定一个国家的最高新科技的水平。好的装甲需要好材料,导弹的外壳需要好材料,飞机发动机叶片需要更优异的材料,最高精尖的军用雷达半导体元器件也需要更好的材料。
而 在材料方面,日本已经甩开了第二名美国极大的身位,剩下的俄罗斯中国之类已经远远不在一个档次,这里以人类的最高精尖的三种材料技术——制作洲际弹道导弹 喷管和壳体以及飞机骨架的高强度碳纤维材料;制作最高性能主动相控阵军用雷达的宽禁带半导体收发组件材料;制作最新式涡轮发动机涡轮叶片的高性能单晶叶 片。
三种顶级科技说明日本远远领先于其他地球国家的最顶级科技。
1,首先是最新式的涡轮发动机叶片的五代单晶材料。
因为涡轮叶片工作环境极为恶劣,并且要在极度高温高压下保持数万转的高转速,所以对于高温高压下的抗蠕变性能的要求是非常高的。这个目前科技最好的解决方法就是让晶体约束朝一个方向伸展,使其材料相比于常规材料来说无晶界,这可以大大提升高温高压下的强度和抗蠕变性能。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
目前人类科技的单晶材料共有五代。
我 们可以发现,越到后面一代,已经没有美国和英国的影子了,老毛子那更是不知道甩到猴年马月去了。如果说四代单晶还有法国作为西方的希望苦苦支撑的话,那么 第五代单晶就是东瀛的独舞——人类最顶级的单晶材料,就是日本的第五代单晶TMS-162/192,日本是目前世界上唯一一个能制造第五代单晶材料的国 家。
有些人可能不知道这意味着什么,我们贴出美国F-22和F-35使用的F119/135发动机的涡轮叶片材料CMSX-10三代高性能单晶作为对比。
我们可以看到,三代单晶的典型代表CMSX-10的抗蠕变性能如下:1100度,137Mpa,220小时。这是西方的顶级水平了。
日本的第五代TMS-162呢?同样条件,寿命高达959小时,接近1000小时寿命,相比于美国材料寿命足足达到4倍有余。
事实上,在这个伟大的技术革新面前,传统的材料学和发动机技术的欧洲顶尖水平公司RR已经选择了屈服。英国罗罗大批进口日本的单晶材料用于制造自己的Trent系列发动机。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
2,再看碳纤维材料。
众所周知,碳纤维因为质量轻巧,强度极高而被视为理想的导弹,特别是最顶尖的洲际弹道导弹材料。包括美国侏儒以及三叉戟D5还有法国M51的新式洲际弹道导弹都用碳-碳和碳-树脂复合材料用于制造洲际导弹的壳体和喷管。在这项技术上日本同样领先于世界水平。
碳纤维分为两种——高强度和高拉伸模量
上面的是日本东丽公司的碳纤维材料,下面是美国大力神公司的
其中IM7被用作制造三叉戟D5的壳体。
而东丽的T1000强度高达7060mpa,拉伸模量在高强度碳纤维中也很高(达到了284Gpa),这些都超过了美国的IM9的美国最高水平。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
碳纤维目前勉强处于同一水平线的只有美日(虽然美国相对较差),其他国家与这两个国家相比都不值一提。
我们来看看俄国人到达了一个怎么样的水平吧
纤 维复合材料特别是碳纤维有机复合材料,在现代飞机上获得了广泛应用。与西方比较俄罗斯这种材料,研究及应用时间稍晚一些,上世纪70年代才着手研究。当时 前苏联国家石墨结构材料研究所、全苏聚合物纤维研究所,以及今日的全俄航空材料研究院,生产出拉伸强度2500~3000MPa、拉伸模量250GPa的 高强度碳纤维,以及模量400~600GPa的高模量碳纤维。后来又研究出4000~5000MPa的中模量碳纤维。总体上看俄罗斯的碳纤维产品,性能水 平不如美日水平高。从高强度纤维产品来看,俄罗斯的YKH、BMH比目前通用的,T300大约低1000Mpa。俄罗斯高模量纤维400~600GPa, 与日本M40J、M60J相近。在中模碳纤维方面与美国的,T800H及T1000G有一定差距,在模量相同的条件之下,后者的强度高出 500~1000MPa。
俄国人最强的水准也不过5000mpa封顶,和美日完全不是一个档次,这还是毛子的实验室水平。
业 内专家告诉记者,目前,全世界碳纤维生产厂家中日本的东丽、东邦和三菱3家公司,代表着目前世界上最先进水平。我国碳纤维的质量、技术和生产规模与 国外差距很大,其中高性能碳纤维技术更是被西方国家垄断和封锁。我国虽然经过多年研究和试生产,但至今尚未掌握高性能碳纤维的核心技术。从技术研发到产业
化难度更大,因此碳纤维要真正实现国产化需要一个漫长的过程。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
可以看到,中国的T800级别的碳纤维也只能在实验室里生产。
而日本的远远强于T800的T1000碳纤维已经走入了市场大量制造了。
事实上,T1000只是东丽80年代的制造水平。可见美日在碳纤维领域领先其他国家20年以上。
3,再看看雷达。
大 家知道,主动相控阵雷达的最关键技术就在于一个个T/R收发组件。事实上,AESA雷达就是数千个收发组件单元组建成一台整的雷达。而T/R组件就是由少 则一个,多则4个MMIC半导体晶片材料封装而成。这个芯片是将雷达的电磁波收发组件集成起来的一个微型电路,既负责电磁波的发出,也负责接收。而这个芯 片就是在整个半导体晶元上蚀刻出电路来的。所以,这个半导体晶圆的晶体生长是整个AESA雷达最关键的技术部分。
这就是F-35的诺斯罗普.格鲁曼公司的APG81雷达的MMIC芯片,APG81雷达由数千个一模一样的这样的MMIC芯片组成。这个芯片是以GaAs为基体蚀刻构筑的。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
但是事实上,GaAs材料因为其禁带过窄,其击穿电压过低,其发射功率是上不去的。所以,迫切需要新一代宽禁带的半导体材料。而这个材料目前已经找到了,就是GaN材料。
而GaN材料的晶体生长是非常困难的,目前也是东瀛率先攻克了GaN薄膜的大规模制造工艺。
1994 年日本日亚化工突破了GaN材料成核生长的关键技术,不久P型GaN采用退火技术得以实现,随后GaNled研制成功。近几年,通过外延技术的提 升,GaNLED的内量子效率大大提升,结合粗化、倒装、PSS衬底等提高光输出效率的技术,GaN基LED已广泛应用于全彩显示、交通信号灯、汽车灯 具、液晶背光、室内照明和路灯照明等领域,半导体照明已经日臻成熟,走进千家万户。
目前,绝大部分GaN基 LED均采用价格相对低廉的蓝宝石为衬底材料制备。然而,蓝宝石衬底与GaN材料有高达17%的晶格失配度,如此大的晶格失配造成了很高的位错密度,导致 GaNLED中的非辐射复合中心增多,限制了其内量子效率的进一步提升。SiC衬底与GaN材料的晶格适配度只有3%,远小于蓝宝石衬底与GaN材料间的 晶格适配度,因此在SiC衬底上外延生长的GaN材料的位错密度会更少,晶体质量会更高,同时SiC的热导率(4.2W/cm.K)远大于蓝宝石,有利于 器件在大电流下工作。
但是SiC衬底的制备难度较高,外延生长GaN的成核也具有一定难度。因此,SiC衬底上 制备GaNLED的技术仅限于以美国CREE为代表的少数掌握SiC衬底囗制备技术的公司手中。目前,美国Cree公司生产的GaNLED封装成白光后, 流明效率已经超过200lm/W,远远超过其他同行厂家。
美国由于无法大规模制造SiC基体的GaN材料,所以求助于日本。可以预见,下一代美国的雷达的材料都将是Made in Japan。
[ 转自铁血社区 http://bbs.tiexue.net/ ]
日前LED上游大厂美国Cree表示,该公司已与三菱化学签订独家授权合约。根据双方协议,三菱化学将可制造、贩卖独立的氮化镓(GaN)基板,并有权签订类似专利范围的再授权协议(similarly-scoped sublicenses)。
据了解,三菱化学光电事业部门总经理Yasuji Kobashi在声明中指出,上述授权合约可望帮助该公司在光电产品领域中拓展氮化镓基板业务。
事 实上,美国F-22的雷 达用日本技术从来就不是什么秘密。早在90年代初,也是日本率先攻克GaAs晶圆的生长工艺,逼着美国购买日亚化工的GaAs晶圆技术用以制造F-22的 APG77雷达。正是日本日亚化工向美国的半导体材料制造的技术许可和转让,美国才得以在90年代后半期发力,利用军用雷达的AESA革命甩开其他国家。

美国富人控制舆论

美国富人控制舆论,核心是压制平民的独立思维.有六种兵器.

1)让政治辩论变得丑陋.金钱+语言游戏=摧毁所有独立思维的平台.让你厌倦,绝望和怀疑自己 的思维.

2)提供注意力寄托.竞技体育,娱乐圈提供注意力的避难场所,也促进政治厌倦.

3)政治正确性的控制.如反犹太,社会主义和不爱国等帽子.

4)平 常积累媒体credibility,关键时候用来造假愚众。用"市场决定论"回应对媒体的质疑.

5)留余地.关键问题上放一点讨论空间,非关键问题上全面 放开,作为民主自由的证据.

6)大力宣传极少数平民变富翁的故事,让99%的人对American dream保持希望.

Saturday, March 16, 2013

Raspberry Pi + Ardunio

In a few weeks I will acquire a Raspberry Pi kit and Ardunio UNO kit for my own embedded system exploration. Will report back when I get them.

Here is a list of materials needed for this project:

1. Raspherry Pi model B: to serve as the master brain in the system. The Pi has an ARM microprocessor and standard IOs, much as a regular computer. It also comes with a Linux distribution (Raspbian), and support programming with Python (my favorite programming platform).

2. Ardunio UNO R3: to serve as a slave brain in the system. The Pi is a full fledge OS, but not perfect to perform real time work, such as, accurate timing. Ardunio has a microcontroller on it (ATmega328), which is capable of real time work. The on-the-chip ADC can be used to sense the physical world (through sensor add-ons).

3. Some basic electronics components such as: resistors, transistors, capacitors, jumper wires and so on.

4. Some interesting sensors will be great. I am thinking as least a temperature sensor, an accelerometer, a camera or a photo cell. 

5. I also need a way to control motors, if I decide to build some robotics or automation stuff. A motor controller and some stepper motors will be necessary.

6. For home automation application, I might also need a relay board with a bunch of 120VAC relays controllable with the digital IO from the Pi. The advantage of doing it with the Pi, instead of the ardunio is that one can control the Pi and hence the relays remotely on the web.

7. Neither the Pi or Arduino has built-in DAC. If I want to build a real-time function generator (probably better off with Arduino since it's a real-time system), a DAC is needed.

8. Of course, I definitely need a multi-meter on my bench to measure voltage and stuff.

Embedded System

An embedded system stands for a microprocessor embedded in a device to control its functions. It's very similar to a computer, in that input data can be processed and output. The major difference is, unlike a computer, an embedded system does not have a human sitting in front of a monitor and keyboard to tell it what to do. An embedded system is likely located inside a microwave, or a robotic machinery, to perform certain, but routine tasks. There are usually a few buttons to operate an embedded system, such as "start", "stop", for example. But other than that, it's mostly an autonomous machine running on its own schedule and going through a same set of instructions repeatedly.

One scheme of running an embedded system is to use service scheduling. Once the power button is on, an initialization routine will load a list of service to be executed based on a pre-determined schedule. Such list is something like this:

1. Clean the floor, every 1 hours, starting 5 mins from now
2. Clean the toilet, every 2 hours, starting 10 mins from now
3. Clean the window, every 3 hours, starting now
...

Basically, the schedule contains information of when to do what and how often.

Once the list is loaded, upon hitting the "start" button, the embedded system will start running this permanent loop:

while (1)
{
      if "someone presses 'stop'"
             goto end;
      run_the_list();
}

end:
      exit();

The permanent loop will make sure the machine will ignore everything else happening in the world, faithfully focuses on the tasks scheduled on the service list, until someone presses the "stop" button, or it runs out of power.




Saturday, March 9, 2013

Marijuana vs Tobacco

Written by Noam Chomsky

Ask ourselves a simple question: how come marijuana is illegal, but tobacco legal? It can't be because of the health impact, because that's exactly the other way around. There has never been a fatality from marijuana use among 60 million reported users in the United States, whereas tobacco kills hundreds of thousands of people every year. My strong suspicion, that I don't know how to prove it, is that marijuana is a weed, you can grow it in your backyard, so there's nobody who would make any money off it if it were legal. Tobacco requires extensive capital inputs and technology, and it can be monopolized, so there are people who can make a ton of money off it. I don't really see any other difference between the two of them, frankly-except that tobacco is far more lethal and far more addictive.

Friday, March 8, 2013

More update on ion column design

In the last week or so, I carried out some more systematic study on electrostatic lens design. The overall goal of designing a lens is to meet the following criteria:

- achieve minimum spherical and chromatic aberration coefficients
- have the ability to focus with practical high voltage power supplies
- minimize the probability of micro-discharging between neighboring elements
- has to be manufacturable
- accommodate other physical restrictions, as such field of view, delfection, and etc.

The first step is optimizing the lens geometry for minimal aberrations. Basic geometrical factors include the thickness and bore size of each element, and the gaps between elements. To study the effect of one geometrical factor, one needs to systematically vary that factor, then compute the axial potential field distribution from it. Aberration coefficients can then be evaluated from the axial field. Python is a very convenient tool here for "glueing" multiple smaller modelling programs together. For each geometrical factor, I wrote a .py script to automate the parameter variation, and the extraction of the aberration coefficients.

Once a french ion optics researcher gave a talk at Zeiss, on the FIB that he designed. He stressed that it is simply impossible to design a FIB that can do everything, meaning that achieving the best resolution, and at the same time being a material hogging machine. I was not quite sure what he meant at the time. With more hands-on experience on column design, it becomes more obvious to me that some lenses have to be optimized for low current probes, while others have to be tweaked for larger current probes. Often times the two types of optimizations contradict each other, pushing one to an extreme will inadvertently compromise the other. As a result, at the beginning of a column design, one have to set out and ask, what is the end application of the column? Is it for high resolution imaging which usually uses a small probe size and probe current? Or for high-throughput material modification that would require a higher probe current?

I charged to design a condenser lens, which will magnify a source into a cross-over, and an objective lens that demagnify the the cross-over into a probe. The initial assessment of the column built out of the combination of the two lenses is promising, in terms of resolution performance.

Wednesday, March 6, 2013

Essential Navigation in Vim

This article is written by SathiyaMoorthy.

This article is part of the ongoing Vi / Vim Tips and Tricks series. Navigation is a vital part of text editing. To be very productive, you should be aware of all possible navigation shortcuts in your editor. In this article, let us review the following 8 Vi / Vim navigation options.
  1. Line navigation
  2. Screen navigation
  3. Word navigation
  4. Special navigation
  5. Paragraph navigation
  6. Search navigation
  7. Code navigation
  8. Navigation from command line

1. Vim Line Navigation

Following are the four navigation that can be done line by line.
  • k – navigate upwards
  • j – navigate downwards
  • l – navigate right side
  • h – navigate left side

By using the repeat factor in VIM we can do this operation for N times. For example, when you want to
go down by 10 lines, then type “10j”.

Within a line if you want to navigate to different position, you have 4 other options.
  • 0 – go to the starting of the current line.
  • ^ – go to the first non blank character of the line.
  • $ – go to the end of the current line.
  • g_ – go to the last non blank character of the line.

2. Vim Screen Navigation

Following are the three navigation which can be done in relation to text shown in the screen.
  • H – Go to the first line of current screen.
  • M – Go to the middle line of current screen.
  • L – Go to the last line of current screen.
  • ctrl+f – Jump forward one full screen.
  • ctrl+b – Jump backwards one full screen
  • ctrl+d – Jump forward (down) a half screen
  • ctrl+u – Jump back (up) one half screen

3. Vim Special Navigation

You may want to do some special navigation inside a file, which are:
  • N% – Go to the Nth percentage line of the file.
  • NG – Go to the Nth line of the file.
  • G – Go to the end of the file.
  • `” – Go to the position where you were in NORMAL MODE while last closing the file.
  • `^ – Go to the position where you were in INSERT MODE while last closing the file.
  • g – Go to the beginning of the file.

4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:
  • e – go to the end of the current word.
  • E – go to the end of the current WORD.
  • b – go to the previous (before) word.
  • B – go to the previous (before) WORD.
  • w – go to the next word.
  • W – go to the next WORD.

WORD – WORD consists of a sequence of non-blank characters, separated with white space.
word – word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word
  • 192.168.1.1 – single WORD
  • 192.168.1.1 – seven words.

5. Vim Paragraph Navigation

  • { – Go to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph beginnings.
  • } – Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.

6. Vim Search Navigation

  • /i – Search for a pattern which will you take you to the next occurrence of it.
  • ?i – Search for a pattern which will you take you to the previous occurrence of it.
  • * - Go to the next occurrence of the current word under the cursor.
  • # - Go to the previous occurrence of the current word under the cursor.

7. Vim Code Navigation

% – Go to the matching braces, or parenthesis inside code.

8. Vim Navigation from Command Line

Vim +N filename: Go to the Nth line of the file after opening it.
vim +10 /etc/passwd

Vim +/pattern filename: Go to the particular pattern’s line inside the file, first occurrence from first. In the following example, it will open the README file and jump to the first occurrence of the word “install”.
vim +/install README

Vim +?patten filename: Go to the particular pattern’s line inside the file, first occurrence from last. In the following example, it will open the README file and jump to the last occurrence of the word “bug”.
vim +?bug README

Importing Python Modules

Importing Python Modules

January 07, 1999 | Updated February 02, 2001 | Fredrik Lundh

Introduction #

The import and from-import statements are a constant cause of serious confusion for newcomers to Python. Luckily, once you’ve figured out what they really do, you’ll never have problems with them again.
This note tries to sort out some of the more common issues related to import and from-import and everything.

There are Many Ways to Import a Module #

Python provides at least three different ways to import modules. You can use the import statement, the from statement, or the builtin __import__ function. (There are more contrived ways to do this too, but that’s outside the scope for this small note.)
Anyway, here’s how these statements and functions work:
  • import X imports the module X, and creates a reference to that module in the current namespace. Or in other words, after you’ve run this statement, you can use X.name to refer to things defined in module X.
  • from X import * imports the module X, and creates references in the current namespace to all public objects defined by that module (that is, everything that doesn’t have a name starting with “_”). Or in other words, after you’ve run this statement, you can simply use a plain name to refer to things defined in module X. But X itself is not defined, so X.name doesn’t work. And if name was already defined, it is replaced by the new version. And if name in X is changed to point to some other object, your module won’t notice.
  • from X import a, b, c imports the module X, and creates references in the current namespace to the given objects. Or in other words, you can now use a and b and c in your program.
  • Finally, X = __import__(‘X’) works like import X, with the difference that you 1) pass the module name as a string, and 2) explicitly assign it to a variable in your current namespace.

Which Way Should I Use? #

Short answer: always use import.
As usual, there are a number of exceptions to this rule:
  • The Module Documentation Tells You To Use from-import. The most common example in this category is Tkinter, which is carefully designed to add only the widget classes and related constants to your current namespace. Using import Tkinter only makes your program harder to read; something that is generally a bad idea.
  • You’re Importing a Package Component. When you need a certain submodule from a package, it’s often much more convenient to write from io.drivers import zip than import io.drivers.zip, since the former lets you refer to the module simply as zip instead of its full name. In this case, the from-import statement acts pretty much like a plain import, and there’s not much risk for confusion.
  • You Don’t Know the Module Name Before Execution. In this case, use __import__(module) where module is a Python string. Also see the next item.
  • You Know Exactly What You’re Doing. If you think you do, just go ahead and use from-import. But think twice before you ask for help ;-)

What Does Python Do to Import a Module? #

When Python imports a module, it first checks the module registry (sys.modules) to see if the module is already imported. If that’s the case, Python uses the existing module object as is.
Otherwise, Python does something like this:
  1. Create a new, empty module object (this is essentially a dictionary)
  2. Insert that module object in the sys.modules dictionary
  3. Load the module code object (if necessary, compile the module first)
  4. Execute the module code object in the new module’s namespace. All variables assigned by the code will be available via the module object.
This means that it’s fairly cheap to import an already imported module; Python just has to look the module name up in a dictionary.

Tuesday, March 5, 2013

Common standard modules in Python

os – functions for various operating system operations

os.path – functions for manipulating directory/folder path names

sys – functions for system-specific programs and services

time – functions for program timing and returning the current time/date in various formats

filecmp – functions for comparing files and directories

tempfile – functions for automatic creation and deletion of temporary files

glob – functions for matching wildcard-type file expressions (e.g., "*.txt")

shutil – functions for high-level file operations (e.g., copying, moving files)

struct – functions for storing numeric data as compact, binary strings

gzip, bz2, zipfile, tarfile – functions for writing to and reading from
various compressed file formats

pickle – functions for converting any Python object to a string that can be written to or subsequently read from a file

hashlib – functions for cryptography / encrypting strings

socket – functions for low-level networking

popen2 – functions for running other programs and capturing their output

urllib – functions for grabbing data from internet servers

ftplib, telnetlib – functions for interfacing with other computers through ftp
and telnet protocols

audioop, imageop – functions for manipulating raw audio and image data (e.g.,
cropping, resizing, etc.)

Saturday, March 2, 2013

A few ways to check hacker attacks on Linux machines

Professional hackers probably will not leave obvious fingerprints. But there still benefits to check if your Linux server is under attack from malicious hackers. Here are a few ways to check.

1. /var/log/auth.log file. This log file logs all the log in information in and out of the system, including system processes, and users log in.

grep 'Failed password' /var/log/auth.log: this command checks if someone is trying to brute force a login via password enumeration;

grep 'Accepted password' /var/log/auth.log: this command checks if anyone managed to log into the system without your knowledge.

2. lastlog command. This command, extracts information from the auth.log file and display them to the terminal. It also shows system processes as well. So if you are only interested as human login, we can use the following command line to filter out system processes:

lastlog | sed '/Never/d' | less


Friday, March 1, 2013

Useful log files in Linux

=> /var/log/messages : General log messages
=> /var/log/boot : System boot log
=> /var/log/debug : Debugging log messages
=> /var/log/auth.log : User login and authentication logs
=> /var/log/daemon.log : Running services such as squid, ntpd and others log message to this file
=> /var/log/dmesg : Linux kernel ring buffer log
=> /var/log/dpkg.log : All binary package log includes package installation and other information
=> /var/log/faillog : User failed login log file
=> /var/log/kern.log : Kernel log file
=> /var/log/lpr.log : Printer log file
=> /var/log/mail.* : All mail server message log files
=> /var/log/mysql.* : MySQL server log file
=> /var/log/user.log : All userlevel logs
=> /var/log/xorg.0.log : X.org log file
=> /var/log/apache2/* : Apache web server log files directory
=> /var/log/lighttpd/* : Lighttpd web server log files directory
=> /var/log/fsck/* : fsck command log
=> /var/log/apport.log : Application crash report / log file

Recent Progress in Ion Optics Column Design

Recently, through mostly self-learning and vivid discussion with Dr. Ray Hill, I've made quite some progress in understanding the technique and work flow in designing an electrostatic-lens-based, ion optics column for charged particle apparatus.

First, I've managed to learn how to model an electrostatic lens, and to calculate its axial potential distribution with First Order Finite Element Method (FO-FEM). Knowing the potential, one can easily calculate the lens' paraxial optical properties, such as focal length, focus voltage, third-order spherical aberration and first order chromatic aberration.

A typical column design starts with designing the most critical elements in the column - the lenses. Two lenses are usually employed in an ion optics column. Lens design involves optimizing the geometry of the lens, such as bore sizes, electrode thickness and gap sizes between neighbouring electrodes to minimize spherical and chromatic aberration coefficients, within the physical boundaries set by practical limits, such as focus voltage, breakdown stability and etc. I've been able to model the objective lens and understand the effects of each geometrical factor on the optical properties of the lens.

After lenses are designed, they can be put together to form a column. In a column, one cares about one thing: for a given probe current, what is the minimum probe size that can be achieved. This calculation can be done using the so-called "d50" method, with which the probe size can be calculated from a series of parameters: beam energy, energy spread, spherical and chromatic aberration, probe current, source brightness and angular source intensity. I've developed several python-based programs to iteratively compute the Probe Size vs Probe Current curve of a given ion column.


Tuesday, February 26, 2013

Setting up a Linux server at home

A little project that I took on today is to establish my newly built Linux box into a network server, which I can remotely login via SSH Secure Shell.

Here are the steps that I took to set the home VAIO machine as a Linux server for SSH access:

1. First I installed OpenSSH server on the home Linux box:
    "sudo apt-get install openssh-server"

2. After successful installation, the server should starts automatically. Then I tested the SSH on the server end:
    "ssh localhost"
    It should prompt me to enter a password for authentication.

3. Now the server is up and running. But in order to access this server from a remote computer (outside your home LAN), we need a static domain name for it. Usually under DHCP, the ip address of the home Linux box is changed from time to time. We can use dynamic DNS service to link the actual ip address to a given domain name. To do that, I logged on to www.no-ip.org, signed up for an account, and added xpennyhuang.no-ip.org as the domain name for the home Linux box. Then I downloaded and installed a client onto the Linux box, to update the dynamic ip address to the domain name (the name of the client package is called no-ip2, which requires a build from source).

4. One last step we needed to do to enable the SSH access is to correctly set the "Port Forwarding" for the SSH service. The idea is, my Linux box is connected to the internet with via a router. From the point of view of external hosts on the internet, my Linux box ip address is invisible to them. Therefore, in order to allow external hosts (a remote computer) to access my Linux box for certain services(eg. SSH here), we need to set up "Port Forwarding". This is done on the Verizon router page/Firewall Setting/Port Forwarding.

5. Finally, with everything setup as mentioned above, we can test the access from a remote PC. I tested with a Windows PC running SSH Secure Shell.

6. To start, stop or restart the SSH server, the following commands can be used.

-To start the server: $sudo service ssh start
-To stop the server: $ sudo service ssh stop
-To restart the server: $sudo service ssh restart

Monday, February 25, 2013

Linux system administative commands

Here are a few useful commands for system administration in Linux:

last : to show you the people who have logged into the computer today and the terminals they are/were using.

df -h: to show the utilization of the hard-drive capacity.

du -h: to show the size of a file, or a directory (including all sub-directories).

free:  to show how much RAM memory you have free on your system.

top: to show all active processes that are running in the system, and the resource they are hogging (cpu, memory)

ps: to show a list of processes running on the system. 

Sunday, February 24, 2013

Linux File System

Linux has its own rules in where to put things. Here is a list of the basic file system.

/: root, it is the origin of whole file system.

/bin: most of the basic programs related to day-to-day operation, such as 'cd', 'rm', or 'ls', are stored here.

/sbin: this folder also hosts executable programs, not intended for users, but meant to be run by the system.

/etc: this folder stores all the system configuration files.

/lib: this folder stores share library files which can be called upon by other programs, usually dynamically.

/boot: the kernal of the Linux OS is located in this directory.

/var: files with variable sizes, such as database, emails, log files and etc.

/tmp: temporary files that are created during programs' runtime are usually located here.

/dev: all devices, including hard-drives, monitors, CD-ROM, flash drives and etc., are mapped as files, and stored in the /dev folder.

/home: personal files for each users are stored in their respective directories under /home.

/usr: programs installed by users are installed here.

Embarking on Linux Journey...again.

Been a fan of UNIX/Linux for years since graduate school. My first encounter of Linux was the cluster that Bin and I built back in 2004-5 for numerical analysis and electron microscopy simulation. Later I awarded myself an Apple Powerbook that runs on MacOS X, which is also a flavour of UNIX. However, my UNIX/Linux journey came to a halt since late 2007, when I started working for first job, which did not require much programming skills. It only starts to come back recently as my current job involves some finite element method simulation of electro-optical systems.

A lucky coincidence is that, my wife's company gave her a new PC for her job, thus retiring her old Sony VAIO laptop. The VAIO has been gathering dust for months, and with a clunky 5-year-old Windows Vista running painstakingly slow. A random point in last couple evenings, I saw the word Ubuntu flying by. Immediately, I made the decision of turning my wife's retired VAIO, into a Linux machine, purely for relearning Linux, programming and numerical analysis. After about half an hour of installation, the VAIO laptop now boots with Ubuntu 12.10. A clean and stable system, and I don't have to worry about installing anti-virus software.

 The first few packages that I installed following the OS are:
-Vim, my favorite text editor
-Python, a great high-level scripting language that I recently started learning -Numpy, a numerical analysis module for Python
-Scipy, a scientific analysis module for Python
 -Matplotlib, a scientific plotting module for Python

I expect to use Python-Numpy-Scipy-Matplotlib to do a lot of things that other people do with Matlab on Windows PC. I am also glad to find that one can also install Microchip's MPLAB IDE and XC18 compilers on Linux (for PIC micro-controller programming). I will wait a little bit, but probably won't be long.