2008-05-03

GTA IV

Shot of trailer

GTA IV has been put on shelves in market. I've just watched the 4 trailer videos, and I think the graphics sucks in comparison to Assassins Creed, the animation sucks in comparison to Prince of Persia 3, and the modeling sucks in comparison to Doom 3. But, guys, BUT: it has got "Grand Theft Auto" in its name. What else can a man want from a video game?

2008-04-24

EMI Sued MP3tunes

April 22th, CEO of MP3tunes sent all users an email, saying that MP3tunes was sued by EMI because of that copywrong thing.

As you may be aware, the major record label EMI has sued MP3tunes, claiming our service is illegal. You can read about the case here. Much is at stake -- if you don't have the right to store your own music online then you won't have the right to store ebooks, videos and other digital products as well. The notion of ownership in the 21st century will evaporate. The idea of ownership is important to me and I want to make sure I have that right and my kids do too.

I don't think MP3tunes did wrong and we all know what rights we have. So I just want to say, EMI, you suck!

2008-03-20

I Need an Apple Cinema Display

Apple Cinema Display

Yes, I do. Because when I'm working on my paper, my desktop becomes this:
sorry-looking desktop
The apps are Emacs, xpdf x 3, rox file manager and terminal.

And I can optimize it a little, which results in this:
sorry-looking desktop 2
I can make use of one xpdf now, while lose the usability of the terminal...

2008-02-16

Report IP and More via e-mail

Want to SSH to you machine at home but don't know the DSL IP address? Why not make your home Linux mail it to you? I wrote some tiny programs that would keep an eye on you mail spool and do stuff according to some specific mail subject. For example, I can send an e-mail to myself which has a subject [CMD] ip_wan and sometime later I will receive an e-mail containing the WAN IP of my router, so that I can easily make a SSH/ftp/telnet session between where I currently am and my box at home.

The first program check my e-mail spool and tell if doing some tasks is needed.

#!/usr/bin/env python

import sys
import mailbox
import StringIO
import rfc822

SPOOL="/var/mail/corsair"

def lookUp(mbox):
    MBox = mailbox.mbox(mbox)
    Deletes = []
    CMDs = []
    for Mail in MBox.items():
        Msg = StringIO.StringIO()
        Msg.write(str(Mail[1]))
        Msg.seek(0)
        MsgParsed = rfc822.Message(Msg)
        if MsgParsed["Subject"].startswith("[CMD]"):
            CMD = MsgParsed["Subject"][6:]
            MBox.remove(Mail[0])
            CMDs.append(CMD)
        Msg.close()
    MBox.close()
    return CMDs

def main():
    for CMD in lookUp(SPOOL):
        print CMD

if __name__ == "__main__":
    main()
    sys.exit(0)

And the second is a shell script that does specific task according to standard input.

#!/bin/zsh

MailAddr="My Email Address"

mailsend()
{
    print -l "Subject: CMD reply\n" $1 $2 | msmtp $MailAddr
}

for CMD in $(cat); do
    case $CMD in
        ip_wan)
            echo "Sending wan IP..."
            mailsend "Wan IP is" \
                $(wget -O - -q http://myip.dk/ | sed -nr 's|^<title>Your IP: ([^<]+)</title>$|\1|p')
            ;;
        ip_lan)
            echo "Sending lan IP..."
            mailsend "Lan IP is" "$(ifconfig)"
            ;;
        *)
            ;;
    esac
done

You can tell that this script currently only support sending LAN and WAN IP.

A possible usage of these two programs is to run the following every some minutes:

mailcmd.py | mailcmdexec.sh

2007-11-07

Terminal Broadcasting

Some days ago I registered an Aardwolf MUD account, and want to show to my girlfriend about MUD and how to play it. So I needed a method to copy the content of my terminal to hers, which I called terminal broadcasting. I got help from the official BBS of my college, that I could redirect the output of the script program to the target pt. The shell command ran thus:

$ script /dev/null 2>&1 | tee /dev/pts/2

Where I assumed that the target pt was /dev/pts/2.

Why was script functional? What I wanted was to duplicate the content of my terminal to hers, both of which, in fact, were file under /dev. So what I've got to do was to write the content of /dev/pts/1 (I assume it's my pt) to /dev/pts/2. Generally, for regular files, one can just do a redirected cat like this

$ cat /dev/pts/1 > /dev/pts/2

But since /dev/pts/1 changes continuously, the command above does not suit our needs. Furthermore, if we just redirect the output, we ourselves are not able to see the content of /dev/pts/1, which will make us unable to do any thing in it. So quite natually, tee will be used. And for the real-time-update stuff, we need a tool that gives us a subshell, and "watch" all the input and output and err. It very seems that a shell itself will do; however, unfortunately, a shell is too low-leveled for this task, and script is the very program (just see what script does: it write the content of current pt to a file). But the question is that why redirect? It seem a simple script /dev/pts/2 will do it perfectly. Yes it seems; however the answer is concerning the "update continuously" thing: by default, script only updates the file when encounter a line break (return), so we have to use a pipe. If you really hate pipes and redirection, you can pass a -f as an option like this:

$ script -f /dev/pts/2

It works similarly as using a pipe.

So for now we have two methods, and there is one more: using a named pipe.

$ mkfifo temp.fifo
$ nc -l -p 1234 -c "cat temp.fifo" &
$ script -f temp.fifo

When others want to see your terminal, they can telnet you via port 1234. This is a more robotic way.

2007-10-18

Youtube Blocked by Chinese Internet Nanny

Yes. Youtube has been blocked by GFW. And meanwhile, blogspot is unblocked. Don't know what's in their brains...

在十七大召开,举国欢庆的日子里,打开 tor 以庆祝。

2007-10-13

Wiki is GFWed

My wiki (and webng.com) was GFWed. If you are not a chinese, and want to know about GFW (aka. Chinese Internet Nanny), I recommand you Chinese internet censorship machine revealed.

At first when I found my wiki could not be browsed, I thought that webng.com was down. But GaloisAbel told me today that she can read it, and I realized that webng.com might be blocked. So I inserted webng.com into my .pac (which Firefox will parse automatically) and started tor and type the URI. After a while, that familiar blue webpage appeared~~ Ha!!~~

2007-09-23

Mac OS X on IBM T40

Installed Mac OSX on my IBM T40 laptop, and Windows was totally wiped out from my box.

The installation was quite easy, and it reminded me of installing Ubuntu. What troubled me was the hard drive partitioning process. Before, The MBR on my hard disk was definitely a mess, for that since I was about to install Ubuntu, I used to dynamically part it using Powerquest Magic, and it must produce some junk in the MBR. So when I formated the used-to-be windows partition to HFS+ with Disk Utility, it refused to do that, and said that it couldn't write into MBR. I had to back up all my important data with size of 30GB onto a mobile disk, and repartition the whole drive. Finally, I could format a primary partition into HFS+ and installed Mac OSX.

This OS is amazing, and of fantastic convenience. And everything in it goes smooth and shiny. What shock me most are the dock and the structure of applications. The dock can communicate with other running applications, and it do it a lot, so I have a funny duck with its wings spread and the number of new messages when Adium got some, as well as a fat rocket on which text is shown indicating the download speed when BitRocket is flying. And for the structure of applications, each one of them is a folder whose name is ended with .app, and the stuff this program needs is in this folder, including icons, xml-s, logic, etc.. So Installing an application is all about drag the folder to somewhere local.

There are also some troubles. The first one is that I cannot get video card driver installed, so QE and hardware acceleration cannot be enabled. Another one concerning the stability of OSX x86. Some of the applications can be easily stuck or exit abnormally such as Grapher and Safari. I am planning to replace Grapher with GNUPlot.

At last, a screenshot.

Mac OSX
                                                screenshot

2007-08-17

Program To Generate Random Sentences and Emacs's Popularity

Just wrote a program to randomly generate sentences, which is somewhat more advanced than a similar program I wrote some mouth ago. The former one just randomly chose a pre-defined pattern and fill it with randomly chosen words, while this one, using recursive transition networks to indicate some basic rules of English grammar, can produce quite nice sentences with subject and object clauses, such as

  • The fool which reluctantly rocks unwillingly eats a book.
  • The silly man that is silly unwillingly kicks a book which finally pisses.
  • A book reluctantly eats a bug that is red.
  • A man unwillingly sucks.
  • The piece of shit that happily runs reluctantly kicks a bug.

Another thing, popularity of Emacs has descended during these years. And now it is less popular than even GEdit and Kite. See Vincent's post.

2007-07-28

Youtube Video URL Extractor in Python

This is a little programme I've just written, youtube-url.py. It finds the URLs of youtube videos according to video IDs. Thus we can download the video file whose ID is, for example, qNKtKm3SXvs with this command line:

wget -O video.flv `youtube-url.py qNKtKm3SXvs`

The code runs thus:

#!/usr/bin/env python
# Time-stamp: <corsair 2007-07-28 16:16:38>

# Corsair <chris.corsair@gmail.com>
# Usage: youtube-url video-id

import sys
import urllib2
import getopt

def main():
    # Options parsing, fake for now.
    try:
        Options, Args = getopt.gnu_getopt(sys.argv[1:], "", [])
    except getopt.GetoptError:
        # print help information and exit:
        pass

    if len(sys.argv) == 1:
        print "Pleas specify a video-id."
        sys.exit(1)

    VideoID = sys.argv[1]
    WatchPage = urllib2.urlopen(
        "".join(["http://youtube.com/watch?v=", VideoID]))

    HtmlLine = ""
    while HtmlLine.find("SWFObject") == -1:
        HtmlLine = WatchPage.readline()
    UrlOriginal = HtmlLine[HtmlLine.find("BASE_YT_URL")+12:]
    UrlOriginal = '?'.join(["http://www.youtube.com/get_video", 
                            UrlOriginal[:UrlOriginal.find('\"')].
                            partition('&')[2]])
    
    # Redirect
    RedirectOpener = urllib2.build_opener(
        urllib2.HTTPRedirectHandler)
    Request = urllib2.Request(UrlOriginal)
    UrlReal = RedirectOpener.open(Request).url
    print UrlReal

if __name__ == "__main__":
    main()

Also, there is a Ruby version by Cheng Meng