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"

2009年3月24日星期二

近况

  1. 先是帮东子装上了 Slackware,装完了之后发现 slack 确实有点不适合新手,一开始不进图形界面就是一个比较大的台阶,系统的配置都只能通过文本来解决就会让很多从 win 下转来的孩子们不知所措…… 不过还好,折腾了一下午终于大概配置好了。

    不过在配置鼠标滚轮的时候发现一个问题,安装网上说的在 InputDevice 里加入:

     Option      "ZAxisMapping" "4 5"
    还是不够,还需要把 Option "Protocol" 改成 "explorerps/2" 才行…… 不知大家有没有遇到相同的问题……

    Update: 看了 vvoody 的回复,发现改成 "IMPS/2" 也是可以的,后来自己好奇,改成了"auto",结果 xorg 自己探测的结果还是 "explorerps/2",好吧,还是信任 xorg 吧~

  2. 最近开始看 Babiloo的源码了~主要是因为1)觉得不看代码还是不行2)那个东西是用 PyQt4 写的而且是个字典程序,还可以就着学点英语。不过看的时候就觉得不爽,首先是代码是用 bzr 托管在 launchpad.com,用惯了 git 感觉 bzr 作为一个 “分布式”版本控制工具怎么就不支持本地的分支和合并……(至少是迄今为止我还不知道怎么办,特性里面也没有说……)而且 bzr 和 launchpad 绑定的太紧了……代码缩进风格和自己的也不一样…… 不过能和作者直接联系这个优势是怎么样也替代不了的~ 当找到一个 bug 的时候可以和作者直接联系,他会给你讲一些全局上的事情,能让人受益匪浅。不管怎样,先坚持下去吧~

2009年3月2日星期一

大刀向Google Reader的头上砍去

今天在 Reader 里看到这样一篇文章:《大刀向Google Reader的头上砍去》文章幽默诙谐,读后深有感触。于是反观自己的 Reader,嗯,是该整理了。

整理的时候忽然发现 GReader 有一个十分好的功能:Trends(不清楚中文是怎么翻译的)。打开他就可以看到每个订阅的阅读率。我把低于 30% 的原则上全部退订了~一下子清闲了很多。估计以后又会有一段清闲的生活了,不过节省下来的时间去干嘛呢?……

忽然记起来以前看到过一个“定律”的,就是一个人开始的时候总是会被垃圾信息包围着,但是他又不愿意去屏蔽,因为“可能”会损失有价值的信息。但是事实是从一堆垃圾信息里能提取出有价值信息的概率很小,人们总是会得到有价值信息的,但是不是通过这种“鸟枪法”。但是现在我就感觉自己的信息“确实”太闭塞了,整天两眼一摸黑,啥新闻都不知道…… 大家都是怎么样收集信息的呢?

2009年2月5日星期四

感动中国 2008 之感动我

其实一开始就觉得自己没心没肺,如果不是我妈看那个节目我也就不会搬电脑过去看了。但是既然看了,而且略微有点小感动了,那就墨迹两句吧。

看完之后我妈问我,哪个给你最大的感动?我问,你呢?她说,是那个彝族教师,因为其他人其实只是做好他们的本职工作。我觉得也是。尤其是当他说自己每月的工资只有两百块钱的时候,快不成了……其实我当时很想看看主持人是什么表情,估计她的工资是这个的百倍,身上的一件衣服就顶的上人家几个月的工资…… 能够经常上网的同学们也可以想想两百块对你来说算什么?对人家来说算什么?由此,其实中国的国情也就可见一斑了。(想说当地消费水平低的滚蛋~ 每月给你两百块钱把你扔山里19年你试试?)

其实还有一个感动的,就是神州七号的乘员组。可能是自己从小关心航空航天的事件,略微知道点其中的辛劳、危险的缘故。尤其是当舱内有火警时改变工作程序的那一段。虽然理智上感觉那样做不对,觉得要是真有火,还是先灭火为好,但是那种大无畏的勇气,祖国至上的精神,是最感动我而且我所应该学习的。

没错,本质上说他们只是完成了自己的本职工作。但是这年头,能干好自己的本职工作就比较不错了。要是还有能力,还有意志,做到像那两个彝族教师一样更好。貌似《肖申克的救赎》里有句经典台词叫“要么好好活着,要么就去死”说的就是这个事?说了半天,其实我还是属于那种“就去死”的类型,为了以后能“好好活 ”今天就先不死了,呵呵~

2009年1月14日星期三

sep.py v0.1.1 发布

咳咳~ sep.py 是我自己写的一个 python 小脚本。用来从当前目录下提取指定扩展名的文件,并且保留其目录结构~~ 我经常是先用 vvoodycueconv.sh 转换下载下来的 flac啊,cue+ape啊什么的,然后在用这个脚本把转出来的东西一并提取出来,而且不会乱~;)

源代码在这里:http://github.com/grissiom/etc/raw/59d2482073b174530c27a58c8c28c8852e11d579/sep/sep.py。GPLv3 的许可证吧。代码是用 github 托管的~ 感兴趣的同学可以跟踪。非常欢迎提意见或者是 bug report。要是 bug fix 更好~ ;D

早晨发布的那个 v0.1 有问题,这个 v0.1.1 就好了~ 如果带来不便请见谅~;)

Qt4.5 will release under LGPL

消息来源这里还有~~

2009年1月13日星期二

Burning 4GB+ file(a singal large file) into a disk

详细的讨论在这:http://www.linuxquestions.org/questions/slackware-14/k3b-says-your-mkisofs-doesnt-support-large-filesetc-696073/

症状是K3b说“Used version of mkisofs does not have large file support.Files bigger than 2GB cannot be handled. ”于是,大文件都被丢掉了……

一开始还以为是 mkisofs 的问题,后来经人指点才知道应该选中 ISO9660 的 Level 3。查了维基百科才知道原来通过 Level 3 可以把大于4GB(或2GB)的文件分割,这样就可以刻录了。经验不敢独吞,拿出来分享~;)