Monday, April 21, 2008

sed programming - commands combination

Sed is a programming language, to me it basically contains two things, one is regexp, the other is the control commands such as "g G H h" which manipulate the hold buffer and pattern buffer. Sed only contains these two buffers, so it is simple. No more.

Although Sed itself is simple, programming with Sed can be complicated. This is like playing chess, to know the rule of each play does not mean you know how to play. You need to know at least some combinations.

Combination of "G h d". Here is an example "1!G;h;$!d" which REVERSE a list of items, typically 3 states control, at start it is "h d", then the second state which can be looped, which is "G h d", and the third state is "G h". Explanation is quite not hard to understand, the hold buffer was used to save the result, so for the first item, it hold it and delete current pattern, for the second, add "\n' on current buffer and append current buffer with the content in hold buffer, save current buffer to hold buffer, so the second item will be ahead of the first item in the hold buffer. it do the same for third, fourth, etc. until the last item, is just "G h", with out "d" means it did not delete current buffer, so at last the current buffer contains the reverse list of items. (My opinion, the last 'h' is not necessary since hold buffer is only for assistant use)

"x;x" combination. A second example:

/^<\example>/ { h; }
x
/^< example>/ { x; p; d;}
x
/^< example>/ {h;}

The five line script find the content of a XML "example" tag. It need a little time to figure out how it works, this script is not using b and n command, remember it and use it in some cases. A altered way may be easy to understand, here the hold buffer contains the content of the example tag.

/^< example>/ {
h
: example-loop
n
/^<\/example>/! {
H
b example-loop
}
x
p
d
}


Here is some of my thought,
1. "n" is alway used "p", thus with "sed -n". And if you use "p", then "p" is always connect with with "d", you don't do "b end" since "d" itself restart a new cycle, -- read a next line to current buffer.
2. using branch is easy to understand the flow, but in some case, the "x;x" command combination can also be considered.

Other thoughts:
3. eol : Use "sed -e 's/\r//' your_file" to convert line ending "dos to unix".

Thursday, April 10, 2008

some newsgroup readers

1. Outlook Express. This is the traditional news reader, it works fine on Windows, you never have any problems with it.

2. Pan. This is based on gtk, it is almost as great as Outlook Express, but it need tough build on Mac OS X.

3. slrn. Should we read news on a terminal? maybe that's the one. Terminal can have a lot of brilliant applications, but not do a good job on web browsing, news reading.

4. MT-NewsWatcher. It is free, but it is NOT in a good shape with GUI.

5. Unison. Just download it and get it a try, which is brilliant! It tell me what news server from my ISP I can use, great work! And I have no trouble to startup, love it.

Ususally I would try Pan, because it is free and it can be used on all platforms, just like firefox. And I am not willing to pay a comercial newsreader, such basic tool should be free, but I am considering buy Unison.

Wednesday, March 19, 2008

Understanding Digital Signal Processing - by Richard Lyons

There are a lot of praise on this DSP book, the following is a typical one from Amazon.com:

"We need this Richard Lyons guy in other fields!!"

The last mathematics course I took was Calulus 3 during my senior year in high school... I graduated in 1991. That was my last exposure to mathematics. My undergrad was in biochemistry (no math) and after that I went to medical school (no math). I started my residency in neurology and I became interested in analyzing EEG brain waves. Unfortunately, most work in this field is done in collaboration with engineers, since us docs have minimal knowledge of mathematics and data analysis. I stumbled upon Lyons's book at Borders and decided to give it a shot. Voila!! No more engineers needed!! I now understand sufficiently the concepts of periodic sampling, the Fourier stuff, filters, signal averaging, etc. all the way down to the simple sums of products that they are. Lyons motivated me so much that I picked up Dietel and Dietel's C++ book and now... a month later... I develop my own software to anaylize these EEG signals.

This may not seem as a big deal to the mathematician or engineer... but you have to remember that I'm a neurologist with no math exposure since high school!! If I can learn digital signal processing through Lyons's book... anyone can.

Congratulations, Richard G. Lyons... I wish you would write something on time-series predictions.


I got this book 2 days ago, and just read a few chapters, it is really a wonderful study journey presented by Lyons. In my work, I was exposed to the audio processing area, and I feel I have trouble to understand dsp filters... The hard thing on DSP is the DFT or FFT which contains a lot of math, while I only study it at College that was 13 years ago, another difficulty is English is my second language, I have never use a English math book for study; Third, DSP area and math are different, for example "i" is used in math to express the root of -1, while in DSP it uses "j", (Thanks to Steve Smith's online dsp book tell me the difference)


I enjoy reading some classic books, Lyon's book should be one of them, what the book contains is like a great teacher, not feed you the knowledge, but guide you to understand it, this book acts like this!

Other books on DSP, one is jos, this book is quite fit to my area, but I would not choose it, because I am not in the college to spend that time. The other wonderful online book is by Steve Smith, this book is quite interesting, it choose not to expose the mathematics way, so you will not be overwelmed by the equation. But I still think Lyon's approach is the best, avoid math may be ok, but equation can also be a good role, be clean if you understand it.

Wednesday, February 27, 2008

Use markdown to build - foyep.org

After 15 days, it seems I build nothing on the website, but I have something to talk. My most concern is I have to use a powerful editor such as vim which will make changes on pages more easily and more controllable.

Markdown: Basically it is two things. One, a light-markup language, the syntax is similar to emacs-wiki I have used to write notes before, and I can use the language in vim to write pages. Second, a perl software tool to convert the written markdown to html.

Markup RW plugin: It is a Rapidweaver plugin, it support markdown language, thus I can use markdown in Rapidweaver, also the plugin contains a bash interface, which could be most meaningful to me -- a programmer.

Blocks: fromPaul,it seems that Blocks is a must have plugin with rapidweaver. The price is an issue, compared to RW (36CAD with coupon), it costs 26CAD, is it valuable to spent for just a plugin. Right now, I think it is worth after I bought it online, it provides me a simple way to design my website as I am not a designer, so I feel great although I need to figure out the usage such as use page blocks, html blocks or align images, etc. One good thing to me is Blocks works with the markup plugin. It is obviously that markdown can be used in blocks.

webyep: NOT choosed as a result.

PlusKit: it supports Markdown and bash, but I have difficulty to use it with blocks, don't know why.

accordion: Anthor beautiful plugin from yourhead, I see some nice samples but not got a chance to try, would like to investe the use with it.

Wednesday, February 20, 2008

setup a website - foyep.org

I spent a whole night to setup a new website, I feel I need to create a site on Buddhism (in Chinese). To register and setup my host account with Godaddy is so efficient, they are doing a great job.

RapidWeaver - I have fiddling it for a little while, liked or dis-liked, but it should be a top 10 Mac application. I used it to create and weave my pages and publish to my website, it also includes some nice and clean themes. The forum of RapidWeaver is quite good.

Ralf Simple Theme - A quite nice theme I choose when I don't want to use the default themes from RW.

webyep - I may feel sad with RW until I found the Webyep plugin, I have never imagen to use CMS but I like the idea, especially when I found it is developed by the guys who bring LaunchBar, while LaunchBar is so impressive to me and it is my #1 Mac Application.

Still need learning to fill the gap, but here is my website, still in construction.

Thursday, January 31, 2008

Install Gentoo VM on Macbook -1

I use Minimum CD, the installation is more hard than using a liveCD, so I failed a bunch of times. And as my learning, I started installation with stage3, so I don't need to catch stage1 and stage2, but even stage3, is a lot to me. Every time with Minimum CD, I have to get stage3 and portage, so at last I save them to another machine that I can easily get with ssh.

0 startup with Minimum CD
vmware: other linux 2.6.x
connected: NAT

1 check network
- ifconfig => eth0
- dhcpcd => some times need it if eth0 did not show ip address
- ssh => connect with my file server where I save stage3 and portage etc.
/etc/init.d/sshd start
ssh 192.168.0.104

2 prepare disks...
- fdisk /dev/sda
=> /dev/sda1 for boot
=> /dev/sda2 for swap
=> /dev/sda3 for / (the root)
mkfs.ext2 /dev/sda1
mkfs.ext3 /dev/sda3
mkswap /dev/sda2
swapon /dev/sda2
mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda1 /mnt/gentoo/boot

3 install stage3 and portage
scp -p -r 192.168.0.104:/root/gentoo .
cd /mnt/gentoo
tar xjpf stage3-<>.tar.bz2
tar xjf portage-<>.tar.bz2 -C /mnt/gentoo/usr

4. env setup
vi /mnt/gentoo/etc/make.conf
CFLAGS as "-O2 -march=prescott -fomit-frame-pointer -pipe"
mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
cp -L /etc/resolv.conf /mnt/gentoo/etc
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1="{chroot} $PS1"


5. emerge -sync --quiet
emerge vim lilo subversion

6. vi /etc/fstab
7. network
vi /etc/conf.d/hostname => "gentoovm"
vi /etc/conf.d/net => for dhcp: config_eth0="dhcp", but i did not set.
rc-update add net.eth0 default => boot eth0 as default
emerge dhcpcd => MUST
vi /etc/hosts
=> 127.0.0.1 gentoovm.homenetwork gentoovm localhost

8. System
passwd => MUST
useradd
emerge syslog-ng vixie-cron
rc-update add syslog-ng default
rc-update add vixie-cron default

9. lilo
vi /etc/lilo.conf
prepare the default kernel (from ssh) and save to /boot
/sbin/lilo

10 reboot

Friday, January 18, 2008

xwd : capture window on linux


xwd is the basic tool to do screen (or window) capture. I used it in my xw manager fvwm2. Here is a shot, but it seems not dump the title part of the window (gvim). Would like to find out the reason.