2009年7月19日星期日

货币战争读后感

最近拜读了宋鸿兵所写的货币战争,看完此书我的思绪有些乱,我需要假以时日来分析并形成自己的投资策略。
一 可以100%确定的事实
1 美联储是私人银行,美国政府无法控制
2 美国总统遇刺的比例高于美军诺曼底登陆一线部队
二 作者观点
1 美元货币体系崩溃只必然的
2 力荐中国储备黄金,逐步渗透人民币与黄金挂钩(这也是宋鸿兵被人指责为《潜伏》的现实版本的原因)
三 我值得反思的问题
1 金融市场不变的规则就是有人赔钱有人赚,可是关于次贷目前的媒体报道全是输家,到底谁是赢家?
2 从阴谋论角度看问题,此轮金融危机是国际银行家的剪羊毛行动,中国会以什么方式被剃毛?
3 从媒体得知,目前国外热钱通过地下钱庄6月净流入1222亿美元,这种地下钱庄是不是足以撼动我们外汇管制的金融长城?
4 如何保值?(外汇?黄金?股票?房地产?)

2009年7月15日星期三

再看Prision Break

最近天天在重温Prision Break.突然感觉PB的编剧如果改行做程序员的话,应该都是比较合格的.因为他们懂得如果做到健壮性(不能让观众看出什么BUG),扩展性(方便写续集),兼容性(续集之间剧情兼容),还能满足大众的需求(会迎合观众口味,比如应观众需求,Sara死了可以安排剧情让她复活).
如果一个程序员可以做到自己写出的程序具有健壮性,扩展性,兼容性,并且能根据用户需求改写代码,你说这种程序员是不是极品?

2009年7月14日星期二

科技园的大排档

科技园高薪南一道与科技南十路的交汇处形成了一个大排档, 售卖热干面, 肉夹馍, 米粉, 炒饭, 炒粉, 手抓饼, 寿司, 馅饼等快餐.这里似乎汇集了全国各地的口味小吃.我喜欢看他们颠炒大勺的动作,感觉很有生机.我不喜欢看他们那种渴望的眼神, 那种眼神让我感到生活的诸多无奈!老实讲, 我没有吃过这边大排档的东西, 因为我感觉卫生实在令人担心.但是我发在内心的敬佩, 因为他们都是DIY高手,1-2个人就完成了从生产到销售的所有工艺.他们手艺精湛, 因为比较麻烦的工艺(比如油炸, 面食) 他们都可以在条件十分苛刻的条件下游刃有余的完成; 他们动作敏捷因为速度代表着销售额; 他们耳聪目明, 因为他们要经常和城管玩猫捉老鼠的游戏.

2009年7月10日星期五

遥控Ubuntu8.04电脑攻略

原始帖
http://groups.google.com/group/szdiy/msg/4e2f708239d360a7


经过一段时间DIY,我可以用我家电视的遥控器遥控我的Ubuntu8.04 Linux系统了,目前可以实现鼠标移动,鼠标按键点击,下面把DIY的过程和经验分享给大家!

一 红外接收器制作
1 元器件:DB9串口(带外壳),4.7uF电解电容,100ma78L05稳压器,1N4148开关二极管,4.7K电阻,1738红外接收头
2 原理图:参考附件schematics.png

二 安装LIRC(ubuntu8.04)
https://help.ubuntu.com/community/InstallLirc/Hardy

三 分析摇控器按键编码
使用irrecord程序分析,最终形成我的遥控器配置文件lircd.conf (参考附件)

四 添加红外鼠标
在/etc/X11/xorg.conf添加LIRC鼠标设备,具体参考附件xorg.conf。

五 配置lircmd.conf文件
配置/etc/lirc/lircmd.conf来设定遥控器的按键与鼠标的移动方向和鼠标按键的对应关系,具体参考附件lircmd.conf。

六 Ubuntu8.04集成LIRC有BUG
安装LIRC后,默认启动顺序是先启动X再执行/etc/init.d/lirc,这样导致了启动X的时候找不到/dev/lircm文件,致使添加鼠标失败,具体调整办法如下:
anders@anders-desktop:~$sudo update-rc.d -f lirc remove
anders@anders-desktop:~$sudo update-rc.d lirc start 50 S .

七 用mode2/xmode2进行红外编码分析
启动xmode2程序,按动遥控器的按键,就可以看到红外方波了,是不是很COOL?具体参考附件图片xmode2.png

八 总结
红外接收器的元器件非常简单,但配合LIRC后却显得无比强大!可以完成红外编码分析和遥控电脑的功能。在玩弄这个LIRC过程中,我遇到很多问题,大都是从官方的文档和Mailing List获取帮助,最终得以解决。
下面给大家提几点注意事项:
1 LIRC不支持USB转串口这种方式,所以必须要把红外接收器连接到真正的串口上
2 在配置LIRC之前最好搞清楚原理,请参考http://www.lirc.org/html/technical.html#overview
3 出现问题请参考相关LOG信息进行DEBUG,比如我发现"六"中提及的BUG就是看到xorg的LOG才知晓的。

最后,祝大家DIY愉快!

2009年7月9日星期四

上班路上躲过一劫

今天照常去上班, 路到方鼎华庭时,在我身前半米处只见火星四射,惊得我一个寒颤!日啊!原来是楼上施工,电焊飞溅下的火星.想想有些后怕,要是火星飞溅刀我脑袋/身上,估计会被烫伤!阿弥佗佛,看来平日我行善积德让我躲过了一劫!
PS
方鼎华庭这狗屁楼盘是我来深圳一路看着成长的.由一个荒废多年的滥尾楼整容化妆成的!穿上个马甲我照样认识!

2009年4月10日星期五

2009年3月16日星期一

[转] 删除c/c++中注释的shell脚本

下面这个脚本实现了删除c/c++ source code中注释的功能。它接收一个命令行参数,该命令行参数或者是一个c/c++源文件,或者是一个目录。当参数是一个目录时,该脚本删除该目录下及子目录下所有源文件中的注释。

delcomment.sh
------------------------------------
#!/bin/bash

#delcomment.sh
#function: this shell script delete the comment in c/c++ source file


function del_comment_file()
{
#delete the comment line begin with '//comment'
sed -i "/^[ \t]*\/\//d" $file

#delete the commnet line end with '//comment'
sed -i "s/\/\/[^\"]*//" $file

#delete the comment only occupied one line '/* commnet */'
sed -i "s/\/\*.*\*\///" $file

#delete the comment that occupied many lines '/*comment
# *comment
# */
sed -i "/^[ \t]*\/\*/,/.*\*\//d" $file

}

function del_comment()
{
for file in `ls `; do
case $file in
*.c)
del_comment_file
;;
*.cpp)
del_comment_file
;;
*.h)
del_comment_file
;;
*)
if [ -d $file ]; then
cd $file
del_comment
cd ..
fi
;;
esac
done
}


DIR=$1

if [ ! -e $DIR ]; then
echo "The file or directory does not exist."
exit 1;
fi

if [ -f $DIR ]; then
file=`basename $DIR`
if [[ `echo $DIR | grep /` == $DIR ]]; then
cd `echo $DIR | sed -e "s/$file//"`
del_comment_file
else
del_comment_file
fi

exit 0;
fi

if [ -d $DIR ]; then
cd $DIR
del_comment
exit 0;
fi



------------------------------------
# delcomment.sh arg
注: 脚本delcomment.sh的参数可以:
(1) 当前目录下的文件;
(2) 目录;
(3) 带路径的文件。
(4) 原文 http://hi.baidu.com/zengzhaonong/blog/item/e85dbcccd844771300e92846.html

2009年3月5日星期四

BASH 笔记

2009年2月15日星期日

用SKYEYE来模拟uClinux

2009/02/23
发现之前做的网络提速工作有问题,其实速度主要和skyeye模拟ARM指令有关,skyeye里面有两套模拟ARM指令的方法;一个是ARMul_Emulate32, 另一个是ARMul_Emulate32_dbct, 我有拜读过dbct的算法,打算从dbct入手看看为何我用skyeye模拟网络速度这么慢的问题,不过编译skyeye提示我的gcc不支持inline x86 asm. 查看skyeye README说需要gcc3.3 / gcc3.4,于是我上网下载并编译了gcc3.4, skyeye还是提示我的gcc3.4不支持inline x86 asm,今天写了一段x86 asm的代码在我Office的Fedora6下编译过了, 回家看看ubunut下的gcc能否编译过, 要是过的话, 看来skyeye在检查inline x86 asm这个特性上有问题.
int main(void)
{
int x = 10, y;

__asm ("movl %1, %%eax;"
"movl %%eax, %0;"
:"=r"(y) /* y is output operand */
:"r"(x) /* x is input operand */
:"%eax"); /* %eax is clobbered register */
printf("x=%d, y=%d\n", x, y);
return 0;
}
PS: 晚上发现我的ubuntu gcc果然支持inline x86 asm,是skyeye的check-x86-asm.sh检测代码有问题,直接exit 0绕过检测,顺利编译带有dbct的skyeye,初步感觉效率有一点点提高吧 :-)

2009/02/15
kernel/softirq.c : 367
+// Anders 2009_0215,raise rx & tx riq priority
+if ((nr == NET_RX_SOFTIRQ) || (nr == NET_TX_SOFTIRQ))
+ raise_softirq(nr);
sudo nice -n -20 skyeye -e linux 本来ping可以控制在1s内有echo了,telnet也进去了,可以重新来过又是不行了,昙花一现的成功 :-(

2009年2月2日星期一

一个MODULE引起的血汗

采用让模组直接编译到内核的方式来进行编译,但是文件中却define了MODULE,我掉进了同一条河里.

//Anders 2008_0526, we don't need this macro.
//For this macro I spend 4 hours on tracing why xxx_init_module function doesn't execute. :-(
//Anders 2009_0203, havn't update this for xxx's new driver.
//For this macro, I spend 2 hours again :-(
//#ifndef MODULE
//#define MODULE
//#endif

2009年1月30日星期五

[uClinux-dev mailing list] 摘录之 "如何驾驭uclinux-dist开发包?"

挺不错的一个帖子,告诉大家如何驾驭uClinux-dist这套开发包.用skyeye模拟硬件,无须任何实体硬件资源,适合初学者入门!

Message: 8
Date: Fri, 30 Jan 2009 22:02:42 +1000
From: Greg Ungerer <gerg@snapgear.com>
Subject: Re: [uClinux-dev] why no-mmu cannot support binfmt_aout.c
To: uClinux development list <uclinux-dev@uclinux.org>
Message-ID: <4982EC62.8020408@snapgear.com
>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

loody wrote:
>> What target did you use as your base for this?
>> (What I really want to know is what is set in the
>> config.arch file).
>>
>> Regards
>> Greg
> Dear Greg:
> I use GDB/armulator.
> attach the config and config.arch for your reference.
> Thanks for your help,

Here is what I did:

1. downloaded uClinux-dist-20080808.tar.gz
2. downloaded arm-linux-tools-20061213.tar.gz
3. mkdir user/hello
4. vi user/hello/hello.c and put in it:

int main()
{
printf("hello world\n");
}

5. vi user/hello/Makefile and put in it:

all: hello

romfs:
$(ROMFSINST) /bin/hello

clean:
-rm -f hello *.elf *.gdb *.o

6. vi user/Kconfig, adding in the "Miscellaneous Applications section:

config USER_HELLO_HELLO
bool "hello"

7. vi user/Makefile, adding in a line:

dir_$(CONFIG_USER_HELLO_HELLO) += hello

8. configured uClinux-dist to build "GDB/ARMulator" selecting to
use a linux-2.6.x kernel, and selected the new "hello" program
for inclusion as well

9. make
10. cd images
11. cp .
12. run "skyeye -e linux" and see:

Your elf file is little endian.
arch: arm
cpu info: armv3, arm7tdmi, 41007700, fff8ff00, 0
mach info: name at91, mach_init addr 0x4189a0
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm7100 mmu ops
Loaded ROM boot.rom
exec file "linux"'s format is elf32-little.
load section .text.head: addr = 0x01008000 size = 0x00000190.
load section .init: addr = 0x010081a0 size = 0x0000ee60.
load section .text: addr = 0x01017000 size = 0x000ce870.
not load section .rodata: addr = 0x010e6000 size = 0x00000000 .
not load section .pci_fixup: addr = 0x010e6000 size = 0x00000000 .
not load section .rio_route: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_gpl: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_unused: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_unused_gpl: addr = 0x010e6000 size =
0x00000000 .
not load section __ksymtab_gpl_future: addr = 0x010e6000 size =
0x00000000 .
not load section __kcrctab: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_gpl: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_unused: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_unused_gpl: addr = 0x010e6000 size =
0x00000000 .
not load section __kcrctab_gpl_future: addr = 0x010e6000 size =
0x00000000 .
load section __param: addr = 0x010e6000 size = 0x00001000.
load section .data: addr = 0x010e8000 size = 0x00009f98.
not load section .bss: addr = 0x010f1fa0 size = 0x00008f20 .
not load section .comment: addr = 0x00000000 size = 0x000013b0 .
call ARMul_InitSymTable,kernel filename is linux.
start addr is set to 0x01008000 by exec file.
Linux version 2.6.25-uc0 (gerg@goober) (gcc version 3.4.4) #2 Fri Jan 30
21:38:07 EST 2009
CPU: Atmel-AT91M40xxx [14000040] revision 0 (ARMvundefined/unknown),
cr=00000000
Machine: Atmel AT91 EB01
Built 1 zonelists in Zone order, mobility grouping off. Total pages: 4064
Kernel command line:
PID hash table entries: 64 (order: 6, 256 bytes)
console [ttyS0] enabled
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 16MB = 16MB total
Memory: 15268KB available (832K code, 75K data, 60K init)
Mount-cache hash table entries: 512
io scheduler noop registered (default)
Atmel USART driver version 0.99
ttyS0 at 0xfffd0000 (irq = 2) is a builtin Atmel APB USART
ttyS1 at 0xfffcc000 (irq = 3) is a builtin Atmel APB USART
brd: module loaded
uclinux[mtd]: RAM probe address=0x1400000 size=0x103000
Creating 1 MTD partitions on "ROM":
0x00000000-0x00103000 : "ROMfs"
uclinux[mtd]: set ROMfs to be root filesystem
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 60K
Shell invoked to run file: /etc/rc
Command: hostname GDB-ARMulator
Command: /bin/expand /etc/ramfs.img /dev/ram0
Command: mount -t proc proc /proc
Command: mount -t ext2 /dev/ram0 /var
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: mkdir /var/empty
Command: cat /etc/motd
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|

GDB/ARMulator support by <davidm@snapgear.com>
For further information check:
http://www.uclinux.org/

Execution Finished, Exiting

Sash command shell (version 1.1.1)
/>




13. from the command line I run "hello":

/> hello
hello world
/>


All seems to work...

Regards
Greg

--
Anders Remark:

//-----tools & package-----
http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/
http://www.uclinux.org/uClinux/dist/uClinux-dist-20080808.tar.gz
//-----end of tools & package-----

//-----skyeye.conf-----
cpu: arm7tdmi
mach: at91
mem_bank: map=M, type=RW, addr=0x00000000, size=0x00004000
mem_bank: map=M, type=RW, addr=0x01000000, size=0x00400000
mem_bank: map=M, type=R, addr=0x01400000, size=0x00400000, file=boot.rom
mem_bank: map=M, type=RW, addr=0x02000000, size=0x00400000
mem_bank: map=M, type=RW, addr=0x02400000, size=0x00008000
mem_bank: map=M, type=RW, addr=0x04000000, size=0x00400000
mem_bank: map=I, type=RW, addr=0xf0000000, size=0x10000000
lcd: state=on
//-----end of skyeye.conf-----

2009年1月29日星期四

BASH练习之“目录轮回”

写了一个bash脚本当作练习内容,为bash添加了qu和hui命令.

qu "去"
hui "回"

anders@~#qu .tencent/
/home/anders /home/anders/.tencent/
anders@~/.tencent#qu qq
/home/anders /home/anders/.tencent/ /home/anders/.tencent/qq
anders@~/.tencent/qq#hui
anders@~/.tencent#hui
anders@~#

--------.bashrc-------
# anders bash exercise
declare -a FOLDER_ARRAY
export FOLDER_ARRAY
FOLDER_ARRAY[0]=$(pwd)

qu ()
{
dirname=$1

if [ $# -eq 0 ] || [ ! -d $1 ]; then
echo "usage:qu "
return
else
if [ ${dirname:0:1} != "/" ]; then
dirname=$(pwd)/$dirname
fi
FOLDER_ARRAY[${#FOLDER_ARRAY[@]}]=$dirname
cd $dirname
echo ${FOLDER_ARRAY[@]}
fi
}

hui ()
{
if [ ${#FOLDER_ARRAY[@]} -le 1 ]; then
echo "no back way"
return
else
unset FOLDER_ARRAY[$((${#FOLDER_ARRAY[@]}-1))]
cd ${FOLDER_ARRAY[$((${#FOLDER_ARRAY[@]}-1))]}
fi
}

2009年1月22日星期四

AP Hacking

[引言]

看着家里沉睡已久的AP成品, 突发奇想要玩玩里面的Linux, 可是更新完自己编译的系统后, AP就默默得睡着了,郁闷!只有一条路---把串口接出来!

[串口]

打开壳子发现了4个孔,貌似串口 TX RX GND VCC。产品都为了Cost Down所以串口部分都没做出来,需要自己加232转TTL的芯片才能让串口工作。

1. 华强北买串口公母转接头(方便串口转换)
2. taobao网购RS232转TTL转换器(本想去华强搞定此东西,不过走进赛格,商铺让我眼花缭乱,找了半天未果)
3. 从其他废旧板子中找到5pin排针,剪掉一pin,找美女帮我焊接到板之上, 都怪自己不会烙铁 :-(

哈哈, 串口有信息了, 提示内存不足, 只怪我的Image太大了!晕!看来非要把FLASH启下来重新来过.

[FLASH]

我没有系统的Loader, 找朋友把FLASH焊接下来,去烧录器上把2M的FLASH内容读了出来。我知道Loader是64K,所以我只需要前面的64K内容,用UltraEdit进入Hex编译模式选中COPY,然后到我的Fedora下用Cat把原是的Image(mini版本) cat到Loader后面,形成Loader+Image的文件,烧录到Flash中!好激动啊!系统马上可以动了!

[调试]

晕, 放上去什么反应都没有, 又劳驾朋友帮我重新焊接一次!但是系统继续没反应!时间也不早了, 不想继续麻烦朋友了, 下班回家!半夜我睡不踏实总在研究问题出在哪里!

翌日再战!对比一下发现用UltraEdit复制出来的64K文件竟然和从FLASH里面读出来的文件有出入!这UltraEdit复制粘贴怎么这么逊啊!还是Linux好,用dd很方便就把2M文件的前64K搞了出来。后悔自己为何用Ultraedit干这傻事,以后坚决用Linux思维方式解决问题!再次麻烦朋友帮忙焊接FLASH, 我烧录好自己重新整合的Loader+Image文件. 哈哈!系统OK了!可以轻松进去Shell Hack, 不错不错!终于有一块开发板可以Hacking了!

[后记]

烙铁要学习, 总麻烦朋友过意不去啊 =.=

2009年1月18日星期日

Unix shell 家谱

Thompson shell
The Thompson shell was the first Unix shell, introduced in the first version of Unix in 1971, and was written by Ken Thompson.

Bourne shell
The Bourne shell, or sh, was the default Unix shell of Unix Version 7, and replaced the Thompson shell, whose executable file had the same name, sh.

Korn shell
The Korn shell (ksh) is a Unix shell which was developed by David Korn (AT&T Bell Laboratories) in the early 1980s. It is backwards-compatible with the Bourne shell and includes many features of the C shell as well, such as a command history, which was inspired by the requests of Bell Labs users.

Bash(derive for Bourne shell)
Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell.[1] The name is a pun on the name of the Bourne shell (sh), an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978,[2] and the concept of being "born again". Bash was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer.[3]

Almquist shell(derive for Bourne shell)
The Almquist shell (also known as A Shell, ash and sh) was originally Kenneth Almquist's clone of the SVR4-variant of the Bourne shell; it is a fast, small, POSIX-compatible Unix shell designed to replace the Bourne shell in later BSD distributions. By intention it did not feature line editing or command history mechanisms originally, because Almquist felt that such should be moved into the terminal driver. Current variants have emacs and vi modes.

Debian Almquist shell(derive for Almquist shell)
Debian Almquist shell (dash) is a Unix shell, much smaller than bash but still aiming at POSIX-compliancy. It requires less disk space but is also less feature-rich. Some missing features, such as the $LINENO variable, are required by POSIX.

/bin/sh != /bin/bash

继续研究bash,惊奇发现自己是个白痴.原来以为/bin/sh和/bin/bash是一个东西,可是发现绝对不是那么回事.我还没搞懂这个dash是什么东西.晕!

2009年1月17日星期六

一天

编译好带Telnet程序的Image,折腾整整6个小时烧进去了,然后设备就安详的睡着了!看来非要把FLASH吹下来用烧录器烧了.不过也不错,中间学要了很多东西,比如用alien转换rpm到deb.比如sourceforge的项目奇遇.

2009年1月4日星期日

Story Board

<2009_0223>