Monday, September 11, 2006

Poor MD, poor me

Yestoday, I was exhausted by the MiniDisk. I think I have never confronted such machines which try to protect audio copyrights so sucked as the MiniDisk. Some days ago, someone told me to export some audio tracks from several MDs, because another classmate recorded one teacher's lessons of a whole term into this disk, and she wanna share them. At beginning, I thought it was a much simple job.

I immediately borrowed a MD machine, an USB cable and installed the software sonicstage in my notebook, which is used to manage and transfer audio between computers and CD/MD machines manufactured by sony company. After completed these, I began to copy audio lessons from the machine, and I thought everything would finish soon.

However, to my surprise, I haven't found a nightmare just began. I got such a prompt when I wanted to transfer lessons to my notebook:

Unable to transfer the following tracks to My Library because they are recorded by Net MD or another computer.

I was totally astonished. The such fact as above means that, it's hardly to exchange music or other audio with each other, who uses MiniDisk to store his audio tracks, because you can only use the machine to manage the audio which it orginally recorded. You cannot upload or download tracks from your own MD, if you are using two different computers. You cannot acquire lossless musics you like from your friends, unless both of you transfer them by both sony MD machines. You can only import something into the MD from CD or your computers, but you will occours serial fantasic difficulties when hoping to share yours.

These tools, such as MD used for playing and amusement, in order to protect copyrights and sony company's rights, are designed so annoying and inconvenient, even weird. These technologies which are not open, not free and even not compatible with other audio formats, are totally out of date, and due to disappear earlier. No one should use it and no model would be seld in stores in this age, when everythig will be open, connected compactly and conveniently, because now it is the time of network and we need share, participate and communicate with each other.

In the end, I have to use audio cable to connect the MD machine and my computer, because I have to only use such original analog RCA style, to transform digital signal in the MD to analog signal by line-in, then again to digital signal in the computer, which process took me more than 10 hours for these lessons also spended so much time. So poor.

Friday, September 08, 2006

Print UTF8 CJK charactors by texLive

Firstly, let's install texlive2005 on the computer. It is very simple.

  1. Download texlive2005-inst-20051102.iso from ctan.org.
  2. Install texlive2005, mount it and run install-tl.sh.
    # su -
    # mount -o loop path-to-iso-file/texlive2005-inst-20051102.iso /media/cdrom
    # cd /media/cdrom
    # ./install-tl.sh
  3. Set the enviroment variable, you'd better put the content below into the /etc/profile.d/texlive2005.sh if you use Gentoo Linux, where you run mktexlsr (texhash).
    export TEXDIR=/usr/local/texlive/2005
    export TEXMFMAIN=$TEXDIR/texmf
    export TEXMFDIST=$TEXDIR/texmf-dist
    export TEXMFLOCAL=/home/apps/texlive/texmf-local:$TEXDIR/texmf-local
    export VARTEXMF=$TEXDIR/texmf-var
    export PATH=$PATH:$TEXDIR/bin/i386-linux
  4. Initialize the texLive.
    $ su -
    # mktexlsr
    # updmap-sys --syncwithtrees
    # texexec --make
  5. Then, we configure UTF8 fonts, this step is even more simple.
    1. Download arphic fonts from ctan.org.http://www.ctan.org/tex-archive/fonts/arphic/ There are four kinds of chinese fonts:
      bkai00mp-20050720.tar.gz  2005-07-20  9841 Kbyte  BIG5   Kaiti
      bsmi00lp-20050720.tar.gz  2005-07-20  9852 Kbyte  BIG5   MingLiu
      gbsn00lp-20050720.tar.gz  2005-07-20  4583 Kbyte  GB2312 Songti
      gkai00mp-20050720.tar.gz  2005-07-20  4538 Kbyte  GB2312 Kaiti
    2. Uncompress them into the directory $texmf-local, probably /usr/local/texlive/texmf-local/, or the directory $HOME/texmf, or $HOME/.texlive2005/texmf-var/, just inheriting the directory fabic of "texmf". Then, find out all the ".map" files under the directory $texmf-local/fonts/map/, includes bkaiu.map,bsmiu.map, gbsnu.map and gkaiu.map. Then, run the command updmap-sys --edit as root, and add these maps information in the bottom:
      Map bkaiu.map
      Map bsmiu.map
      Map gbsnu.map
      Map gkaiu.map
      After updmap-sys re-generate all map settings, all is done.
    3. Ok, now, set latex enviorment {CJK}{UTF8}{gbsn} or {CJK}{UTF8}{gkai}, you can use pdflatex or dvipdfmx to generate your pdf files.
    4. Append some contents below into $texmf-var/dvips/config/config.ps, then you can use dvips to print out ps files.
      p +cm-dvipdfm-fix.map
      p +dvipdfm.map
      p +gkaiu.map
      p +gbsnu.map
PS: when texlive2007, just choose basic scheme to install for the general application. And there is only about less than 200M bytes.

Tuesday, September 05, 2006

Gnus works with fetchmail

In the past, I always use only gnus to receive and send mails. However, minor defect in an otherwise prefect thing is that, when it receives many, especially, more than tens of letters, whole of emacs will seem to be suspended and have no response, unless you press C-g to interrupt current gnus process. Gnus is totally written with elisp and elisp is parsed by emacs, whereby it is not a program with multi-process. Then, when gnus receives or sends mails, emacs will wait it util its job ends.

Recently, this situation took places so frequently that I can not suffer from it. Thus, I plan to distinguish my MDA and MTA. Gnus is a nice tool as MUA, such as mutt, but more powerful than mutt, which can orgnize mails and newsgroups easily and conveniently. Besides, gnus can also play a role of MTA like sendmail, which can send mails by smtpmail.el. Gnus can also take the place of MDA like fetchmail, while orgnizing newsgroup is its outstanding job, which has several style to store messages. The two most frequent styles are nnfolder and nnml, the former of which is to store messages into a whole file as the format mbox, the latter into several files for each in a directory. The nnml format is the fastest format to read and search, so as that I prefer the latter one. The more details exists in gnus manuals.

Now, Gnus will act as MUA and MTA, to orgnize mails and send mails. Correspondingly, fetchmail will play as MDA, instead of some functions of gnus before. Here is the method to configure fetchmail:

Firestly, touch a file named ~/.fetchmailrc, whose content is so simple:

poll MAIL_SERVER_IP protocol POP3 uidl
     username MAIL_USERNAME password MAIL_PASSWORD keep
mda "procmail -d %T"

Here is some selective explanation:

  • uidl: Only fetch newer messages.
  • keep: Leave messages on the pop3 server.
  • mda "procmail -d %T": This statement can bo omitted, which means to use procmail as the mail filter.

Important: When using fetchmail in Gentoo Linux and I omitted the statement which contains procmail, some similar errors occur:

1 message for  at  (923 octets).
reading message 1 of 1 (923 octets) fetchmail: SMTP connect to localhost failed
fetchmail: SMTP transaction error while fetching from 
fetchmail: Query status=10 (SMTP)

If you use procmail to categorze and filter mails rather than gnus, you need set rules in ~/.procmailrc:

MAILDIR=$HOME/Mail
DEFAULT=$MAILDIR/mbox
LOGFILE=$MAILDIR/from-log
LOCKFILE=$MAILDIR/.lock

:0
! FORWARD-NAME@FORWARD-SERVER.COM

After :0, you can create your filter rules, even with regular expressions, in which the symbol "!" above means to forward all mails received into the mailbox FORWARD-NAME@FORWARD-SERVER.COM, whereby procmail is enough powerful.

Important: In Gentoo Linux, I have to add "DEFAULT=$MAILDIR/mbox" into ~/.procmailrc, otherwise, procmail will automatically deliver messages into ~/.maildir as format maildir, which is used with nnmldir. When I do this, the messages will not be stored at default directory /var/mail/USERNAME. Then, we also should change nnml-spool-directory and others to ~/Mail/mbox accordingly.

Now, run fetchmail by command:

fetchmail -d 300
which means run fetchmail as a daemon, and receive mails from remote server every 5 minutes. If everything is ok, you can write it into cron or into startup scripts. All mails will be stored into the local mail spools, usually which exists in /var/mail/USERNAME, when it run at Gentoo Linux or FreeBSD.

Then, configure the ~/.gnus, to which we write some simple lisp code:

(setq
 user-full-name "Myfirstname Mylastname"
 user-mail-address "mymail@mycompany.com"
 nnmail-spool-file "/var/mail/USERNAME"
 display-time-mail-file "/var/mail/USERNAME"
 message-default-charset `utf-8
 nnml-directory "~/Mail/"
 gnus-select-method '(nnml ""))

Start emacs and open gnus. Gnus will automaticly move and orgnize messages from /var/mail/USERNAME into the nnml-directory with the program "movemail". If there is no rules to say how to orgnize mails in the ~/.gnus, all mails will be moved to the default directory ~/Mail/mail/misc.

Then, step into the Group buffer in the gnus, if the group mail.misc is invisible, then press "L"(gnus-group-list-all-groups). If the group mail.misc does not exist, press "G m"(gnus-group-make-group) to create a new group named mail.misc with the method "nnml:", or press "^" (gnus-enter-server-mode), then enter "{nnml:}(open)" to check whether you have missed some groups.

If you wanna make the group mail.misc always visible, then press "G c"(gnus-group-customize) to complete more customed details.

When go here, gnus and fetchmail will work together, and you will not be boring of gnus receiving mails and fetchmail takes the place of it at background.

Generate a package with dependency in FreeBSD

After completion to compile a package, we usually want to backup its binary backage so as to avoid compile it again when installing it in the future.

Here is a small script to automaticlly generate a package and other packages which it depends on.

for i in `pkg_info -qr $PACKAGE_NAME | cut -d ' ' -f2 | sort | uniq`; do
    pkg_create -zb $i
done

If you wanna backup all packages you installed on the system, try to replace "pkg_info -qr" to "pkg_info -Qoa".

strace, an useful diagnostic toolstrace

You will always occours some boring situation when using Linux-like system. For example, when you are trying the new feature of emacs unicode branch, such as xft fonts supporting. You input the command "emacs --enable-font-backend -fn monospace", and wish to enjoy the rounded and smooth fonts. However, your Emacs could not start up, and throwed out a fault, like "Fatal error (11)Segmentation fault". If you are a newbie, You may be distracted and donnot how to resolve.

Now, there is a cute tool, strace, to help us diagnose where it crashes. strace can be binded on an existed PID, and trace its system calls. here are some useful arguments:

-f : trace current process and its sub-processes -o file : redirect the output into a file, but not stderr -p pid : bind on a process with pid, which is often used to debug on background.

Here is an example to trace the emacs process, the result will be written into the file emacs.strace.

strace -f -o emacs.strace emacs

Here is an advanced article to explain how strace to work: http://www.linuxforum.net/forum/showflat.php?Cat=&Board=security&Number=534712&page=0&view=collapsed&sb=5&o=31&fpart=