2010年2月10日星期三

开了一个技术博客

在这里: http://blog.csdn.net/grissiom (好不容易在今天完成了第一篇文章……)以后这里就放一些关于生活啊之类的碎碎念吧~那里会放一些编程啊,硬件啊之类的东西。我尽量会不转帖的。有了分享,还用转贴么?把类别分开也能方便大家看。(问题是,看的人有几个呢?嘿嘿……)

最后,无论在哪里,都欢迎大家拍砖,人气低的时候欢迎灌水~;)

2010年1月30日星期六

又是一年考期时

Creative Commons License
本作品采用知识共享署名-非商业性使用 2.5 中国大陆许可协议进行许可。

=========================================

其实这是很久以前写的东西。久到大三上的那个考期,觉得郁闷,于是就写了。但是以后的考期就还是那么过的,没有什么变化…… 以后大概也就不会有考期这个东西了,把它贴出来作为纪念吧……

=========================================


又是一年考期时


其实只是上了大学才知道“考期”这个名词,其实只是过完了大一上才知道大学里原来还有 一个“考期”的时间专门留给复习 —— 准备最后的期末考试。


或许考试这个“龙门”就是留给有准备的人跳的。不过大学以前,印象里没有留过时间专门 复习期末考试的 —— 高考除外,其性质与期末考试不同,暂不属于讨论范畴。基本上是讲 完考,考完撤,上午一门下午一门,连考三天还不费劲。


上了大学,风水变了。有孩子喊,14 天考 10 门,能熬出来都成神了。不禁莞儿。想想, 我也是这么一路抱怨过来的。当年也怨过也骂过也狠过。也曾经用一晚上两三个小时把一 学期要学的东西吞进去过。当年是这样,今年,恐怕还是这样。


“大学”这两个字或许真的有魔力。进来之前是向往,进来之后是体味。甚至有大学生们常 挂在嘴边的“大学生活”这个词来凸显生活与以前别处的不同。不过显然没有“大学学习”这 个词。不过学习确实也是不一样了。以前不用专门抽时间来复习的,现在需 要腾一个月时 间了。以前上午考一门下午考一门不皱眉头的,现在今天考一门明天考一门就要抱怨了。


我不是旁观者,我也抱怨,甚至愤恨。


可是还是要思考为什么,为什么考试密集了会抱怨,为什么要有考期。


可能是知识太多,太复杂。其实我觉得,刚来时的传言“讲一、练二、考三”,平心而论, 再夸张一点,其实是“讲三、练二、考一”。基本上老师都是“不为难”,考的肯定是讲的子 集。理论上说,上课听,记住了,考试过是没问题的。老师说“上课听讲,课下消化”,没 有听说过“上课听讲,考期消化”的。从这一点来说,考期并无必要。


没有了考期,也就无从抱怨考期安排不合理了,该抱怨没有考期了。以前还有机会过,甚 至可以拿高分,现在连机会都没有了,这怎么能行呢?


其实是抱怨错了地方。如前所述,如果功夫下在平时,期末想过很容易。可是“平时”是个 隐性的时间,“考期”是个显形的时间。人们容易注意显性而忽略隐性的东西。比如大地震 ,举国关注,可以国内关注吸烟导致死亡的人却很少。其实,每年吸烟至死 500 万人,比 大地震死亡人数要多得多。美国的伊战在 08 年的时候已经死掉 4000 多人了。不过大部 分人不是在进攻的时候死掉的,而是在漫长的占领期内一点一点被各种事件杀掉的。如果 在第一波进攻内就死掉 4000人,估计它也就顶不住国内的压力要撤军了。可是现在,有谁 在关注么?同样是死人,“大家一起死”和“一个一个慢慢死”效果就很不同。同样是学习,“ 一个学期里 学习”和“一个考期里学习”所引起的关注也就不一样 —— 更何况考期还挂一个“ 考”字呢?


这也是一种懒惰。“枪打出头鸟”,“抓典型”,有意而为之的时候是一种手段、策略;无意 而为之的时候是一种祸患:只抓住了部分而没有把握整体;只听到了聒噪的“一小撮”而没 有看到“沉默的大多数”。有人可能会拿 80/20 原则来反驳。那么我会说:“ 什么样的人能 用 20% 的时间学习 80% 的知识并且把它们掌握牢固?”


我不是,我还是要用剩下的 20% 时间吞 80% 的知识,只期望于考试考过,不奢望于牢固 掌握。悲哀啊!莫过于此。


恐惧源于不知,待到明了之后,也就无所谓惧怕了。


立此存照

2009年12月11日星期五

Some Twist on the Blog

Creative Commons License
本作品采用知识共享署名-非商业性使用 2.5 中国大陆许可协议进行许可。

I spent some time on twist my blog(grissiom.blogspot.com) today. The major changes are direct RSS feed to feedburner( http://feeds.feedburner.com/Grissiom ) and add a CC icon on the blog. I choose NOT allow commercial uses of your work and Allow modifications of your work(not require as long as others share alike). So the articles on this blog will be covered by that license. Take care of this.

Also, I found a script named rst2wp.py from Using ReStructured Text with WordPress which is wonderful work. I adapted it to meet my blogspot's need. The script can be found on my MLES repository along with my other Make Life Easier Scripts ;-)

Hope you could enjoy them :-)

2009年12月10日星期四

Extract Audio to Ogg with mencoder and oggenc

If you got a video of a though-provoking speech, you may want to convert it to a audio file which could copy into your mp3 player and be with you all the time. You can listen to it without boot up the computers. In some situations listen is much easier than seeing.

mp3 is one of the choice of the audio file formats. But for patent reason, my distribution doesn't ship lame. And I know there is ogg format [Ref1] which is more open and free. So I decided to encode all the audio into ogg format.

mencoder is part of mplayer which is very very powerful multi-media player. With mencoder/mplayer, you can play nearly all kind of video/audio files. We only care about the audio here. Let's start to work!

Basicly we need to extract the audio from the multi-media stream first:

mencoder video.mp4 -of rawaudio -ovc copy -oac pcm -o audio.pcm

-of rawaudio tells the mencoder to output audio stream only. Although the man page told me the -of option is still BETA but it works like a charm here. -ovc copy tells mencoder not to decode the video stream, which would consume less resources on your computer. -oac pcm tells mencoder to encode the audio to uncompressed PCM. Now, we can use ogg --raw audio.pcm to convert the raw pcm file to an ogg file.

But it's far from perfect. One big problem is this way of converting will last long time. When mencoder is extracting, oggenc doesn't convert simultaneously. So the time will be doubled. The other problem is you have to provide a relatively large temperary file to contain the pcm data. The method that could kill two birds with one stone is using a pipe. So the second version will be:

mencoder video.mp4 -of rawaudio -ovc copy -oac pcm -o - | \
    oggenc --raw - -o audio.ogg                            

But this version have bugs too. mencoder will print out something like:

MEncoder r29789-4.3.3 (C) 2000-2009 MPlayer Team
success: format: 0  data: 0x0 - 0x34468059      
libavformat file format detected.               
[lavf] Audio stream found,  -aid 0              
[lavf] Video stream found,  -vid 1              
VIDEO:  [H264]  1280x720  24bpp  29.970 fps    0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:44  fourcc:0x34363248  size:1280x720  fps:29.970  ftime:=0.0334
========================================================================== 
Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)          
FAAD: compressed input bitrate missing,  assuming 128kbit/s!               
AUDIO: 44100 Hz,  2 ch,  s16le,  128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio))    
========================================================================== 
Ignoring video stream!                                                     
videocodec: framecopy (1280x720 24bpp fourcc=34363248)                     
Pos:   0.7s     22f ( 0%)  0.00fps Trem:   0min 141mb  A-V:0.068 [0:1411]  
Skipping frame!                                                            

which will corrupt the pcm stream to stdout and cause a corrupted ogg file eventually. In man page, it said -quiet will Make console output less verbose and -really-quiet will Display even less output and status messages than with -quiet but there is no guarantee that There won't be any message to stdout. That's unbearable for our condition.

So I come up with the idea that shell can redirect file-descriptor 3-10 to stdout, stdin or stderr. So we can write the pcm stream to file descriptor 3, and redirect the fd 3 to stdout. Then, redirect the origin stdout where the messages going to /dev/null. But how to tell mencoder write the pcm stream to fd 3? The trick is simple. Actually, fd n is /proc/self/fd/n for the process. What a great design of Linux system! Now, the pipe should be clean. Here is the final version:

mencoder video.mp4 -of rawaudio -ovc copy -oac pcm \
    -o /proc/self/fd/3 3>&1 1>/dev/null | \
    oggenc --raw - -o audio.ogg

There are two things you should care:

  1. You must redirect fd 3 when dumping things into it, otherwise it will break.
  2. The order in redirection is important. 3>&1 means redirect 3 to what 1 currently is. If you 1>/dev/null and then 3>&1, fd 3 will be redirected to /dev/null as well.

Now, you can extract the audio to ogg file flawlessly. Big thanks to http://www.commandlinefu.com where tell me the usage of mencoder.

[Ref1]http://www.vorbis.com/

2009年12月8日星期二

Gappproxy plus pac is your friend to break the wall

Nearly everyone on the earth know that China has a Great Fire Wall to monitor and control connections abroad. It block some web pages that should not be seen by teenagers or have politic issues. But it blocks some useful webs too. For example, *.blogspot.com where holds many technical blogs, http://chrome.google.com/extensions where you can extent you Chromium... It's unbearable for someone(like me, although I tolerated it for quite a long time) got "Connection Reset" now and then. So I decided and managed to get through it with Gappproxy.

Why Gappproxy?

It based on GAE(Google App Engine), which is free(within quotas) and powerful and 7x24 on line. Someone may found GAE has been blocked too. I will talk on it later. There are many ways to break walls such as buy a VPS abroad and use ssh tunnel through it or use VPN. But neither I don't have the money and time to buy a VPS nor many free VPN sites are not accessible, I choose Gappproxy as my way to embrace the free world.

There are some tutorials that could teach you how to setup a Gappproxy for yourself, search it on baidu.com will give you many results. (I nearly never search sensitive topic on Google because it would bring it into trouble) So I won't reinvent the wheel. One thing I want to mention is the Gappproxy main site was blocked too(not surprisingly). So you could not retrieve the source files unless you pass the wall... Here is a link for the tarballs and you may find it accessible behind the wall:

http://gappproxy.googlecode.com/files/gappproxy-1.0.0beta.tar.gz

In this tarball, fetchserver folder have the files that should be deployed to GAE, which is equivalent to the fetchserver tarball in most tutorials; in localproxy folder there is the client need to be run on your box. Don't forget to adjust them before you deploy/run :-)

After it was fully setup, set your browser's proxy to localhost:8000. I prefer to use a pac file to do the trick.(See below) After got it run successfully, you may need to update your Gappproxy to the latest version.

Access to GAE

Actually it's quite easy to do the trick. Following this link http://ftofficer.spaces.live.com/blog/cns!423B72634E2F6B7E!1073.entry (which is also blocked, but you can search "appspot www.google.cn" in baidu.com. It will be the third entry. Take snapshot with baidu you can know what he/she is saying about, in Chinese), you can edit your /etc/hosts to let your appspot point to a www.google.cn's IP. Now your GAE will be accessible. I hope GFW won't block www.google.cn ;-)

Use a pac file to setup proxy for your web browser

The last blog I mentioned above have taught me how to use a pac file to set up proxy for web browser. Why use pac file?

  1. It's plain text file with JavaScript syntax. So it will be editable with any of your favorite text editor. I know nothing about JavaScript but a pac file is rather easy to write and understand and thus, easy to extend.
  2. It's flexible and powerful. You can set different proxies for different urls or hosts. You can even tell the browser to connect to the web directly for some urls.
  3. It's browser-independent. It's not a fancy Firefox plugin which could not run on Chromium. It's a standard which is supported by most of the browsers, Firefox, Chromium, Opera... Maybe if you find a browser which does not support it, you should not use that browser ;-) (I haven't tested it in IE though.. ;)

There are tutorials teaching you what a pac file is and how to write a pac file [Ref1], [Ref2] , so I won't reinvent the wheel again ;)

Let me use one sentence to finish this article:

Standing on the Cloud, where is the Wall?
[Ref1]http://en.wikipedia.org/wiki/Proxy_auto-config
[Ref2]http://code.google.com/p/gappproxy/wiki/UsingProxy_StepByStep# _2._使用_PAC_文件,强大、智能

2009年4月16日星期四

Suspend slackware in DELL1501

This is not true! It seems this is a kernel regression. I will post more info after the problem is identified!

Many users say that a Linux box should be shutdown as less time as possible. Because system will buffer the disk for you so the second-start-up time of an app will be much shorter. The longer time you run, the more quantity and more accurate buffer system will allocate, the faster your app will launch. If you shutdown you computer, all the buffer will gone. But I have to pay for my electricity charge! I want save power when I do not use my box. Unfortunately, Hibernate won't help because system will free "useless" pages to optimize load time.(I think) But Suspend is will keep the buffers and consume less energy. This is tested by other people.

But I suffered a disaster after resume from suspend. System goes totally unstable after resuming. I got something like this in dmesg:

[ 7962.125970] BUG: unable to handle kernel paging request at f76f5004
[ 7962.125984] IP: [] ext3_check_dir_entry+0x19/0x140
[ 7962.126000] *pde = 00007067 *pte = 77520002 
[ 7962.126010] Oops: 0000 [#1] SMP 
[ 7962.126017] last sysfs file: /sys/power/state
[ 7962.126024] Modules linked in: radeon drm vboxnetflt vboxdrv snd_seq_dummy snd_seq_oss snd_seq_midi_event snd_seq snd_seq_device snd_pcm_oss snd_mixer_oss ipv6 nls_cp936 vfat fat ext4 jbd2 crc16 fuse dell_laptop dcdbas b43 mac80211 joydev ricoh_mmc sdhci_pci cfg80211 led_class shpchp ohci_hcd sg input_polldev ati_agp agpgart video output
[ 7962.126075] 
[ 7962.126082] Pid: 6509, comm: pm-powersave Not tainted (2.6.29.1-slk-based-2 #4) Inspiron 1501 
[ 7962.126089] EIP: 0060:[] EFLAGS: 00010292 CPU: 1
[ 7962.126097] EIP is at ext3_check_dir_entry+0x19/0x140
[ 7962.126102] EAX: c0463684 EBX: f76f5000 ECX: f76f5000 EDX: f6c5a478
[ 7962.126108] ESI: f6846a00 EDI: 00002000 EBP: f6c5a478 ESP: f6785cec
[ 7962.126113]  DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
[ 7962.126120] Process pm-powersave (pid: 6509, ti=f6784000 task=f7031090 task.ti=f6784000)
[ 7962.126126] Stack:
[ 7962.126129]  f7781000 d9e5ad68 f6c35040 c01e6c4d 00000000 00000000 f6785dec f6785dec
[ 7962.126141]  f6785e80 c0463684 00000000 f76f5000 f6846a00 00002000 f6e246c0 c01e86f3
[ 7962.126153]  f6e246c0 00002000 f66c2cc0 f6ba1400 00000000 c01e5a07 0000000b d9c5fbb8
[ 7962.126166] Call Trace:
[ 7962.126171]  [] dx_probe+0x8d/0x350
[ 7962.126180]  [] ext3_find_entry+0x403/0x650
[ 7962.126189]  [] ext3_truncate+0x317/0x8e0
[ 7962.126197]  [] __ext3_get_inode_loc+0xda/0x2f0
[ 7962.126205]  [] __wake_up+0x3e/0x60
[ 7962.126215]  [] ext3_lookup+0x46/0xf0
[ 7962.126222]  [] d_alloc+0xf7/0x170
[ 7962.126233]  [] do_lookup+0x1ba/0x1e0
[ 7962.126240]  [] __link_path_walk+0x675/0xd90
[ 7962.126247]  [] generic_file_aio_read+0x2fa/0x6d0
[ 7962.126257]  [] do_page_fault+0x28c/0x6a0
[ 7962.126266]  [] path_walk+0x54/0xb0
[ 7962.126273]  [] do_path_lookup+0xb0/0x160
[ 7962.126280]  [] getname+0x96/0xd0
[ 7962.126287]  [] user_path_at+0x5a/0x90
[ 7962.126295]  [] vfs_stat_fd+0x22/0x60
[ 7962.126305]  [] sys_stat64+0xf/0x30
[ 7962.126313]  [] syscall_call+0x7/0xb
[ 7962.126321] Code: ff ff 83 c4 0c 5b c3 90 90 90 90 90 90 90 90 90 90 90 83 ec 3c 89 6c 24 38 89 5c 24 2c 89 d5 89 74 24 30 89 7c 24 34 89 44 24 24 <0f> b7 41 04 3d ff ff 00 00 74 74 83 f8 0b 89 c6 0f 8f c1 00 00 
[ 7962.126379] EIP: [] ext3_check_dir_entry+0x19/0x140 SS:ESP 0068:f6785cec
[ 7962.126390] ---[ end trace a30eca9c02841218 ]---
Some process has been terminated for some reason that I don't know. Even syslogd at worst case! Firefox won't launch, su don't work, if you click icons on panel, plasma will freeze...

After some exploring, I see these lines lay in /usr/doc/pm-utils-1.2.5/README.SLACKWARE

==============================================================================

KNOWN ISSUES

****  If you encounter either of these, mail rworkman@slackware.com ****

If your alsa drivers don't correctly save and restore state across a sleep /
resume cycle (due to a buggy driver), then you will need to add the drivers
to a custom file named /etc/pm/config.d/defaults (create the file if it does
not exist already) in a variable named "SUSPEND_MODULES" - see the file at
/usr/lib/pm-utils/defaults for proper format.

The /usr/lib/pm-utils/sleep.d/90clock does not run by default.  It added
over a second to suspend, and the vast majority of hardware does not need it
to keep the clocks in sync.  If you need this hook, you can set the
NEED_CLOCK_SYNC environment variable in a custom /etc/pm/config.d/defaults
file.

==============================================================================
So I tried to set NEED_CLOCK_SYNC=1 in /etc/pm/config.d/defaults . Suspend, go to a sleep, Resume. And everything works well! Angles sing, light suddenly fills the dorm ;)

What /usr/lib/pm-utils/sleep.d/90clock actually done is here:

#!/bin/sh
# Synchronize system time with hardware time.
# TODO: Do modern kernels handle this correctly?  If so, we should detect that
#       and skip this hook.

. "${PM_FUNCTIONS}"

suspend_clock()
{
        /sbin/hwclock --systohc >/dev/null 2>&1 0<&1
}

resume_clock()
{
        /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1
}

[ "$NEED_CLOCK_SYNC" ] || exit $NA

case "$1" in
        hibernate|suspend) suspend_clock ;;
        thaw|resume) resume_clock ;;
        *) exit $NA ;;
esac


A LQ post that I created to discuss this issue is here

2009年3月31日星期二

终于搞定 bzr 的 launchpad 帐户了……

纵使有一千个理由骂 bzr(而且确实有一千个理由),可还是要用它,入乡随俗么……

终于把 bzr 上的 launchpad 帐户搞定了。方法是在 ~/.bash_profile 里加一句

 export CURL_CA_BUNDLE=/usr/share/apps/kssl/ca-bundle.crt
,那个 ca-bundle.crt 是 "grep ca-bundle.crt /var/log/packages*" 找到的,竟然是 kde 包里面的一个东西 Qrz... 而且要重新 clone 上游才能有 commit 权限……

干嘛不用 git 呢?忽然想起前段时间看到的一句话:"yet another f*cking wheel -- but a better one",但是我觉得 bzr 就是"yet another f*cking wheel -- but a worse one"