Monday, December 14, 2009

Idea for a simple bib tool

I was using Zotero for my research readings, however, it is a bit too heavy for me, and I want a tool that can be portable across machines. So I am planning to write a bib tool for myself when I am a bit free sometime next spring.

The most important concept in this tool:

  • Keep it Simple: there will NOT be fancy setup interface, but a config XML; there will not be many export styles for that is latex’s business.
  • Depend less: there is already many advanced tools for bib organization, but they depend on this and that. I plan to implement all this tool with Python and sqlite3, so it can be put into U-key/Dropbox, and used anywhere.

The basci senarios is:

  1. User start the tool, which set up a local web sever at a high port (eg: 8080), and open any browser to land on the interface.
  2. To add a new paper, user have to
    1. upload a pdf file
    2. add bibtex info by
      1. upload a crospending a bibtex file
      2. fill a form to generate bibtex info
    3. add optional tags
    4. add optional note
  3. To view paper:
    1. start a search (empty field means any)
    2. a list of reference is returned
    3. (optional) open pdf file
  4. To export
    1. start a search
    2. select paper and add to “basket”
    3. go to export folder and get a sorted bib for all and BIB’s for each files and copies of PDF’s

Suggestions are always welcomed :)

Wednesday, December 9, 2009

SumatraPDF is really FAST

I have reading a lot of pdf files recently, and I often open a file, read a handful paragraphs and close the file. While Adobe Reader provides great render quality, it is a bit slow.

So I turned to SumatraPDF, which is an open source pdf reader based on MuPDF and brings several useful functionalities, such as searching and copy.

Thursday, December 3, 2009

What in_lto_p has _p suffix in GCC 4.5

Abstract: Curiosity killed the cat XD

Usually we use _p suffix to pointers in C language, but it is not the case for in_lto_p in GCC 4.5, so I searched for the reason, and according to <http://www.stanford.edu/~blp/writings/blp-stds/blp-stds_4.html> :

p-convention
A _p suffix indicates a boolean test for the condition described by the rest of the name. (This comes from Lisp.)

And it can be supported by this wiki page<http://en.wikipedia.org/wiki/P_convention> :

This practice originated among users of the Lisp programming language, in which there is the convention of appending the letter “P” on elements to denote a predicate (a yes or no question). It is most commonly used at MIT and the University of California, Berkeley, or among computer scientists working in Artificial intelligence (which frequently uses Lisp).

So _p for predicate not pointer here :)

Wednesday, December 2, 2009

Bash environment memo: profile, bash_profile & bashrc

Abstract: I'm trying to explain the process of bash setup in this article.

Keywords:bash, shell, environment

It is usually hard to answer the question where this variable is set, because there is SO many different files involved. So let's start with some concepts:

interactive login shell
The shell started after a successful login, using /bin/login, by reading the /etc/passwd file.
interactive non-login shell
It is normally started at the command-line using a shell program (eg.$/bin/bash) or by the /bin/su command. It is also started with a terminal program within a graphical environment.
non-interactive shell
It's usually used to execute a shell script

An interactive login shell generally initializes with the following configuration files:

/etc/profile -> [~/.bash_profile] -> [~/.bash_login] -> [~/.profile]

In some systems, the /etc/profile script will look for additional settings in /etc/profile.d/*.sh, and the ~/.bash_profile usually sources ~/.bashrc.

When an interactive non-login shell starts, it first copies the environment of its parent shell and then reads its settings in the following order:

/etc/bash.bashrc -> [~/.bashrc]

Remember that only exported variables of its parent shell is copied, functions and aliases of its parent are NOT inherited.

A non-interactive shell simply copies environment from its parent, and does not read any configuration files.

Thursday, November 5, 2009

Mount internal filesystem without passwd with udisk (formerly devicekit-disk)

Abstract: Use policykit to avoid root password for mount an internal filesystem.

Last week, I updated my Arch Linux laptop, and got the new deviekit-disk. Then I found that the authorizations set with gnome interface, which actually sets theorg.freedesktop.hal.storage..., stops work. I have to give the root passwd when I try to mount an internal filesystem, which is really bothering:(

Luckly it is not hard to solve this problem with Policykit, though there dosen't seem to be a sweet GUI to help. All you have to do is simply create a text file named anything with suffix .pkla in /etc/polkit-1/localauthority/50-local.d/ and fill it with the content below:

[filesystems mount internal privs]
Identity=unix-group:disk
Action=org.freedesktop.devicekit.disks.filesystem-mount-system-internal
ResultAny=no
ResultInactive=no
ResultActive=yes

In case you have udisks2 instead of udisks, the action should written like this:

Action=org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.filesystem-mount

Here I allow all users in group disk to mount internal filesystem without root password. disk is the default group of storage devices, you should add yourself to this group. Otherwise you can specify your login name:

Identity=unix-user:yourname

To see all possible actions, check /usr/share/polkit-1/actions directory.
You can always man pklocalauthority for more info:)


Update (May 22nd 2012)

Udisks2 uses different action name.


Update (Oct 25th, 2011)

Latest udev will set storage devices of group disk. So I specify group disk instead of storage now.

PS: I moved to a new blog.


Update (April 3rd 2010)

People from freedesktop.org are making a great progress - by renaming devicekit-disk as udisk (Sounds talking about flash disk, isn't it?)... So you got to change Action=org.freedesktop.devicekit.disks.filesystem-mount-system-internal to Action=org.freedesktop.udisks.filesystem-mount-system-internal.

Dear sirs/madams from freedesktop.org, will you please stop renaming things? It's not fun, at all :(


Update (April 16th, 2010)

It seems /etc/polkit-1/localauthority/50-local.d/ is a better place to apply your own settings.


Update (Nov 2nd, 2010)

The configuration file has to be named with suffix .pkla to be recognized, for more details you can man pklocalauthority. And lots of thanks goes to Awebb who kindly points this out :)

Sunday, September 27, 2009

looking for a web software for knowlege sharing

I am currently looking for a web-based software for knowledge sharing in our lab, I've investigated some blog, cms and also wiki softwares, but none seems to fit :(

We just want something which is easy to setup and maintain, and can organize different kind of materials. CMS's are powerful, but relatively hard to used...Wiki seems to lack some kind of structure. Blogs are easy to use, but does not organize resources well.

So what do you use in your lab, my dear readers?

Wednesday, September 16, 2009

QEMU "host only network"

Abstract: Setup an LAN network of only the host and guest.

Recently I'm trying something on qemu and want to access the guest from the host more freely than user mod port redirect, but I do not want to expose my guest to the host network. All I did is to wrap everything into a script:

#!/bin/sh

HOSTIP="192.168.1.250"
GUESTIP="192.168.2.10"
NETMASK="255.255.255.0"
USERID=`whoami`
IFNAME=`sudo tunctl -b -u $USERID`

sudo ifconfig $IFNAME $HOSTIP netmask $NETMASK up

echo ":: Host IP is $HOSTIP"
echo ":: Run the follwing command in guest to set IP and gateway:"
echo " # ifconfig eth0 $GUESTIP"
echo " # route add default gw $HOSTIP"
echo ":: Starting QEMU with TUN/TAP network..."

qemu -hda webdev.qcow \
-boot c -m 256 \
-k en-us -localtime\
-net nic,vlan=0,model=rtl8139 \
-net tap,vlan=0,ifname=$IFNAME,script=no,downscript=no

sudo tunctl -d $IFNAME
HOSTIP="19

Btw, I find sticky note gadget on iGoogle a great tool to share a couple of lines between machines - I'm writing on my Windows laptop and the script is in my Linix desktop, just a few paste and copy brings the script here :)

Monday, September 7, 2009

VIM Modeline is your friend

Abstract: Add modeline to a file can help VIM remember file-specific options.

I've got to port some application to another arch these days, so I have to deal with a lot of files that does not follow my usual coding standards, and I don't want to edit my VIM settings now and then, so I turned to modeline for help.

To add modeline to all the files, I simply did a find & echo like this:

for f in `find . -name '*.cpp' -o -name '*.h' -print0| xargs -0i echo {}`;do echo -e "\n/* vim: set ts=2: */" >> $f;done

Saturday, September 5, 2009

How to insert formatted date in VIM

Abstract: Remember to escape the percent sign

I find that I cannot simply prefix a r! before plain date command to insert a date in VIM today, When I tried to insert date with

:r !date +%u

I got an error, the reason lies in the percent sign, which stands for the current file in VIM ex-mode. For example, you can count the current file like this:

:! wc %

Thus to insert a formatted date, you have to run:

:r !date +\%u

Thursday, August 13, 2009

Good Book: CERT C Secure Coding Standard

Abstract: a good reference book on coding in C

It's a good reference book on coding nicely in C, which is the most dangerous programming language I know except for brain-f*ck...

Another good point is that you can read it free online: https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Secure+Coding+Standard.

Thursday, July 30, 2009

Backup with Acronis and without CD

Abstract: Boot Acronis True Image from grub.

Acronis True Image features online backup, however sometimes you may still want to do a off-line one, then normally you have to either install Acronis to hard disk or use a rescue media CD. Since I have both Arch Linux and Windows installed, I do not want to install Acronis to hard disk because I want to have grub in MBR. But I cannot use rescue cd either, because my cd has already been dead for years.

I've tried to make a usb disk rescue media, but it simply does not boot :(

So here's what I did:

  • Generate a rescue ISO with Acronis;
  • Expand ISO file and copy all in Recovery Manager to a directory on hard disk;
  • Write in Grub's menu.lst:
    title Acronis
    root (hdX,Y)
    kernel /acronis/kernel.dat quiet vga=0x317
    initrd /acronis/ramdisk.dat

  • Reboot and select Acronis from grub

Now you see, Acronis Rescue CD is actually Linux :)

Tuesday, July 28, 2009

bool & GCC

Abstract: I'll try to clear up confusion about bool for non-compiler people;)

Even some of my teammate on compiler would misunderstand bool with GCC some times. So I'm trying to make it a bit clear:

bool is not an valid type in C89, which is referred as ANSI C sometimes. Therefore, if you are working on a project that is supposed to be compiled with an ANSI C compiler, do not use bool type. However, bool is valid in C99 as _Bool, so you can use it safely if your code is not expected to be compiled with an ancient compiler;)

In GCC code, you can see 'bool' here and there, but bear in mind that it's fake - it's actually unsigned char, defined in gcc/system.h. This is because GCC is expected to bootstrap with an ANSI C compiler.

In C++, bool is always valid, you don't have to worry about bool.

SnipMate is fabulous

Abstract: A textmate-like snippet script for VIM.

I've been using snippetemu for about one year and happen to find another snippet script for vim - snipMate. After a try, I do think snipMate is much better than snippetemu, for tow reasons:

  • Its snippet format is simple and clear.
  • No placeholder.

I do suggest give it a try even if you're not a fan of TextMate, because it really makes coding easier.

You can find snipMate's VIM page here.

Tuesday, July 21, 2009

Firefox 3.5.1 (Shiretoko) fails to launch in Arch Linux

Abstract: Firefox 3.5.1 needs libjpeg.

After updating my Firefox (Shiretoki) to version 3.5.1 in Arch Linux, I cannot launch it. When I tried to start it from command line, it says:

$ firefox
Coundn't load XPCOM
$

Then I tried to run xulrunner directly, I got a Error message saying that libjpeg cannot be found. So I installed libjpeg-7-1, and Firefox is back again. Hopefully the Arch people can add libjpeg to Firefox's dependency.

Monday, July 20, 2009

Pm-hibernate with MX440

Abstract: Some tweaks to avoid black screen after resume from hibernation with old nVidia MX440 graphic card and Intel motherboard.

First edit the setting for pm-utils in /etc/pm/config.d/config(you can name this file whatever you like).

HIBERNATE_MODE="shutdown"
S2RAM_OPTS="-f"
DISPLAY_QUIRK_VBE_POST=false

Then I edit /etc/modprobe.d/modprobe.conf(the modprobe.conf is here for Arch Linux, but may lies in different place in other distros):

blacklist intel_agp

Then reboot the computer, and try hibernate again, everything goes well :)

Monday, July 13, 2009

How to Compact Virtualbox vdi

Abstract: a memo on how to compact virtualbox vdi files.

VirtualBox comes with a utility to compact vdi files which drops zero block. So the problem is how to write zero to unused blocks. If you have a windows guest, run the following command in cmd:

sdelete -c

If you have a linux guest, run this:

cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

And in the host run:

VBoxManage modifyvdi harddisk.vdi compact

These may reduce the size of vdi files considerably if it has been used for a long time.

Tuesday, July 7, 2009

"The greeter application appears to be crashing"

Abstract: Resolved "The greeter application appears to be crashing" problem after updating Linux system.

I don't know whether this could be called a solution... actually just a tip if you happened to come across a same problem. I updated my Arch Linux, and after reboot this dialog box jumps up and gdm could not start normally. I checked the system and found the problem was caused by a full filesystem. I cleaned up some old files and then everything goes right.

So I guess I should give more disk space to / in the future.

Wednesday, June 24, 2009

Google Service Blocked by Chinese Gov

It seems the Chinese government is now crazy about blocking foreign websites, now www.google.com, and all services of Google except www.google.cn are now blocked by the Great FireWall.

Web censorship ans secrete police are now bringing the country back to the bad old days :(

Tuesday, June 9, 2009

Sigh...blocked again :(

As everybody knows, there is a Great Firewall(usually called GFW for short) between we Chinese internet users and the 'out side world'. Unluckily for some unknown reason, blogger and blogspot is blocked by GFW recently which does cause me a lot of trouble to keep blogging here... Anyway, I will try hard to keep this site updated.

Get Chrome Work in Arch Linux

Abstract: several steps to get chrome working on Arch linux


  • Google only provides deb pkg officially, damn...

  • download the deb pkg from:
    http://www.google.com/chrome/intl/en/eula_dev.html?dl=unstable_i386_deb

  • unpack, copy everything in opt to /opt

  • mkdir lib32 in /opt/google/chrome, and make symbol links as:
    http://code.google.com/p/chromium/issues/detail?id=13425

  • enjoy chrome...though I can't input Chinese in its linux version...wtf...

Update Jun 13, 2010: Now chromium is in the official repo, and if you'd like to use Google Chrome(beta), it's in the AUR.

Tuesday, May 19, 2009

The problem of pm-hibernate solved

Abstract: Solve the problem of pm-hibernate restarts computer.

When I try to hibernate my laptop running Arch Linux with pm-hibernate which is also used by GNOME behind the scene, it restarts immediately after hibernate to disk. I checked Arch wiki and find a link to opensuse wiki Pm-Utils. After add a s2ram force option as instructed, the problem is solved. I added the following lins to /etc/pm/config.d/config

HIBERNATE_MODE="shutdown"
S2RAM_OPTS="-f -p -m"

The "-p" parameter was the key to a successful hibernate for me.

Sunday, May 17, 2009

Script to synchronize VIM settings

Abstract: My scripts to backup vim setting and synchonize between Windows and Linux.


Finally I cannot bare the boring work of copying my vim settings around my labtop(with both windows and linux installed), lab pc and working server. So I write a few scripts to automatic this work for me:)


The first script is used to copy the scirpts to a certain dir on my laptop that can be share accross Windows and Linux systems. tr and sed are used to convert file format and handle some syntax difference.

#!/bin/bash
CURDIR=`pwd`
BACKDIR="/cygdrive/e/vim-setting"
if [ -d $BACKDIR ] ; then
echo "Backup to $BACKDIR"
else
mkdir "$BACKDIR"
echo "Make backup dir $BACKDIR"
fi
cd "$BACKDIR"
rm .vimrc
rm .gvimrc
rm -rf .vim
cp '/cygdrive/c/Documents and Settings/Yuanjie/_vimrc' .vimrc
tr -d '\15\32' < '/cygdrive/c/Documents and Settings/Yuanjie/_gvimrc' | sed 's/set guifont=\([^:]*\):h\([0-9]*\)/set guifont=\1\\ \2/' >.gvimrc
cp -r '/cygdrive/c/Documents and Settings/Yuanjie/vimfiles' .vim
cd $CURDIR

After files are moved to the synchronize folder, I init a git repo and push it to a host. The synchronize script on the Linux side goes like this:

#!/bin/bash
CURDIR=`pwd`
EMOUNT=0
BACKDIR="/media/e/vim-setting"
if [ ! -d "$BACKDIR" ] ; then
echo "trying to mount drive e ..."
pmount /dev/sda9
if [ "$?"=0 ] ; then
echo "drive e mounted"
EMOUNT=1
else
echo "drive e cannot be mounted"
exit
fi
fi
cd $HOME
tar cjf .vim-setting.$(date +%F).tar.bz2 .vim/ .vimrc .gvimrc
rm -rf .vim/ .vimrc .gvimrc
cp -r $BACKDIR/.vim $HOME
cp $BACKDIR/.vimrc $HOME
cp $BACKDIR/.gvimrc $HOME
if [ "$EMOUNT"=1 ] ; then
pumount /dev/sda9
if [ "$?"=0 ] ; then
echo "drive e unmounted"
else
echo "drive e cannot be unmounted"
exit
fi
fi
cd $CURDIR

The scirpt above tar the original setting files and copy the new settings from the synchronize dir. Since the drive is not always mount, a dir test is used and drive will be mounted with pmount. The synchonize scirpt on Windows is similar but simpler than this, but guifont setting in gvimrc will have to be changed back like this:

sed 's/set guifont=\([A-Za-z\\ ]*\)\\ \([0-9]*\)/set guifont=\1:h\2/'

Notice that you may have to modify this in case there's number in your font name...

Thursday, May 14, 2009

EE in side?

Well I promised that I will blog about technique-related stuffs in English, but that is NOT always easy, especially when I want to talk about something not exactly technical… So let me try ;)

Today I helped Emma understand the confusing chip manual from TI, which is actually quite ordinary for a guy who was majored in EE – like me ;) Computers, cellphones, PDA’s and all lovely electronic gadgets are just chips connected on PCB in my eyes, and all programs to me are just bit streams flowing on the binary circuit… Parallelism has never be something hard for me since all the parts on a circuit should be working simultaneously (though some of the chips can be disabled to save energy or for some other reason…)

I do find some differences between me and those ‘genuine CS’ guys XD – What occurs to me when I meet difficulty in my experiments is to build a ‘lab-made’ hardware environments of my own instead of buying from some vendor; CS people say that this CPU features loading 8 instructions a time, while I say this CPU could work better with block-reading storage devices since reading multiple continuously stored instructions at a time is more efficient...

Currently I’m working on GCC and studying machine learning and data mining techniques, which are all interesting, but sometimes I do miss those days with FPGA and various chips and I’m still dreaming of building my CPU (perhaps with FPGA) which implements my instruction set, designing a circuit to support it, and finally writing a kernel, a compiler and several applications to form a minimal environment in my programming language for it. I don't believe this will be of any academic significance... but it really sounds INTERESTING~

Sunday, May 10, 2009

Converting between WAV and MP3 with simple open source tools

Abstract

A short memo on converting between mp3 and wav files

Today I find some conf call audio records are so big for my little hard disk so I decided to convert them from WAV to MP3 format. I make use of a simple (more precisely, simple to use) tools to do the job -- lame.

Since all my wav files to convert sit in the same folder, I make use of a little bash:

$ for f in `ls -1 *.wav | sed s/\.wav$//` ; do lame $f.wav $f.mp3 ; rm -v $f.wav ; done

Easy, isn't it?

Converting mp3 files back is just as easy, though there should be some quarlity loss which I don't believe can be noticed for a conf call record;) The mpg123 is as simple as its name 123, you just have to give it the name of the file to convert

$ for f in `ls -1 *.mp3 | sed s/\.mp3$//` ; do mpg123 -w $f.wav $f.mp3 ; done

Tux Drawing

I'm not sure whether is a good idea to put it here, anyway, I think Tux is technique-related...

Done in OpenCavas(Maybe I should use Linux and GIMP to do this, but I really don't like GIMP)... This took me several minutes after a pencil sketch on real paper.

Saturday, May 9, 2009

How to use git-http-fetch with a proxy

Abstract

This post offers a tip on how to use git with a http proxy

I noticed a mail in the Chinese Google Summer of Code mail list today, which askes how to use git-http-fetch when a http proxy have to be used to access the git host. I don't believe there is any way to do so with GIT, but I don't think this should be a tough problem either. Remember git is only a common program, though it does many magic>. So it should work with http proxy just as other programs do.

Remember how we access the internet with a proxy in bash? All we have to do is to set the http_proxy environment variable.In bash we simply do:

export http_proxy=”http://<proxy-server-ip>:<port>”

Or you may:

http_proxy=”http://<proxy-server-ip>:<port>” git http-fetch <your-params>

And be aware that the name of the environment variable is in lower case.

Wednesday, May 6, 2009

How to process large text file efficiently in Python

Abstract

Three different ways of processing text file line by line are given in the order of increasing efficiency.

I have to handle a large text file of space-separated data in python, and the data goes like this:

tag1 tag2 tag3
12 34 12
123 345 12

the first line is tags for each column, and the rest lines hold data. Since the tags are fixed, I can code it directly in to my script, that is to say the first line should be skipped. My first script goes like this:

file = open('foo.txt', 'r')
for line in file.readlines()[1:]:
#do something

This script requires a vast amount of RAM, since it has to store a list of all lines! So it is wise to use iterator:

file = open('foo.txt', 'r')
first = True
for line in file:
if first:
first = False
else:
#do something

The second script works much better than the first one, because the lines are read one by one from the file by using a iterator. However, the first flag is not a neat way to skip the first line for we have to test the flag many times, which makes no sense. And the problem is solved in the third script:

file = open('foo.txt', 'r')
file.readline()
for line in file:
#do something

the 'fileread.line()' command will perfectly move the file position one line forward, and the iter will then start from the second line:)

Monday, May 4, 2009

How many lines does it take to learn a new language?

It seems to be impossible for me to learn a new programing language by reading books without practice, so the question in the title occurs to me – how many lines does it take to learn a language?

The number obviously depends on many factors: whether it is the first programming language to me, if I have learned a language with similar grammar/design before, the size of the standard library… and a lot!

And it’s even harder to define when I should say I have learned a programming language… Having been programming in C for years, I still check the standard library now and then :(

Maybe I should define a metric of the familiarity of a programming language, ask all my friends in this trade to help me collect data, and take some statistical approach to obtain a equation of lines needed to practice a language... Hmm, a lot work to answer this simple question, isn't it XD

a python script to generate cue file

Abstract

A python script to generate cue file from file names in a same folder is given.

Sometimes we have lessless music (ape, flac…) split in to different files, and a cue file may help orgnize them in some music jukebox application, i.e foobar2000. so I create a really silly script to help me…

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys
import glob
from string import Template
from optparse import OptionParser

cue_head='''REM GENRE $GENRE
REM DATE $DATE
REM DISCID $DISCID
PERFORMER "$PERFORMER"
TITLE "$ALBUMTITLE"'''

cue_file='''
FILE "$FILE" WAVE
TRACK $TRACK AUDIO
TITLE "$TRACKTITLE"
INDEX 01 00:00:00'''

def cue_gen():
"""
generate cue file
"""
parser = OptionParser()
parser.add_option('-d', dest='dir',
type='string')
parser.add_option('-s', dest='sfx',
type='string', default='ape')
options, args = parser.parse_args()

if options.dir is None:
directory = os.getcwd()
else:
directory = options.dir
suffix = options.sfx
print directory, suffix

files = glob.glob(os.path.join(directory, '*.'+suffix))
files = [ff[1] for ff in [os.path.split(f) for f in files]]
files.sort()
for file in files:
print file
begin = int(raw_input('Title offset? '))

genre = raw_input('Genre? ')
date = raw_input('Date? ')
discId = raw_input('DiscId? ')
performer = raw_input('Performer? ')
albumTitle = raw_input('Title? ')
d1 = dict(GENRE = genre,
DATE = date,
DISCID = discId,
PERFORMER = performer,
ALBUMTITLE = albumTitle)
head = Template(cue_head).substitute(d1)
cuepath = os.path.join(directory, (albumTitle+'.cue'))

f = open(cuepath, 'w')
f.write(head)

track = 0
for file in files:
trackTitle = file[begin:-(len(suffix)+1)]
track = track + 1
d2 = dict(FILE = file,
TRACK = track,
TRACKTITLE = trackTitle)
body = Template(cue_file).substitute(d2)
f.write(body)

f.close()

if __name__ == '__main__':
cue_gen()

I know it’s quite rough and a lot of enhancement can be made… maybe it should search for the right file extension automatically or even search the genre for the internet, and that’s just why I put it here, hopefully some of you would help to improve it XD

Sunday, May 3, 2009

Migrate to a blog is just like move to a new house...

It's tiring, but offers a great opportunity to review my stuffs - what I have been writing about, what kind of blog I hope to have, whether my posts are well tagged...

And when I was trying to make a list of all programing/makeup languages I've used, I found some of them get so rusty that I cannot even remember how to define a function in it...Hmm it doesn't sound good :(

Fresh New Blog for Tech blogging =)

Hi all,

Finally I've decided to write a new blog for my technological posts, and all posts related to technology (software, Linux system, web technology...) will be migrate here in a short period of time =)

Thursday, April 30, 2009

My Comments on Books about Shell Programming

Abastract
In this article I shall introduce several books about shell programming and hopefully it will help you to determine the right one for you.

I have to learn shell to carry out some of my experiments recently, and to be honest, I don’t feel like shell very much since there are so many modern script languages out there… Anyway, as shell is so widely used, it’s not too bad to spend some time on it.

  • A Practical Guide to Linux Commands, Editors, and Shell Programming is a nice book to start for newbies :)
  • Unix Shell Programming is the best book on shell programming I’ve found, which explains how shell works clearly
  • Classic Shell Scripting is not structured as well as the the previous one, but it has a chapter on security and explains some basic ideas in more details. If you get confused while reading the previous book, check this one.
  • Unix Shell by Example explains all popular shells, including sh, bash , csh and ksh, if you are going to script for different shells you may very likely find this book useful.

Monday, April 27, 2009

Google logo today is so~ COOL!

So impressive.

Finally get Xorg-1.6 work with nVidia MX440

Abstract

I describe a solution to the problem that Xorg 1.6 fails to work with Mx440 and kernel 2.6.29 in Arch Linux

I'm currently using an old PC in the lab, which features a MX440 video card, last week I updated my Arch Linux and got Xorg 1.6, and that was the start of a nightmare...

Xorg refuse to work with the legacy driver (nvidia-96xx), and won't start if the xorg.conf file exists, which is used to specify the screen resolution(though the pc is quite old, I got a big widescreen monitor…). I browsed the Arch user forum and tried all the solutions given, and finally get it work with add “nopat” option to the kernel in the grub munu.lst like this:

title Arch Linux
root (hd0,4)
kernel /vmlinuz26 root=/dev/disk/by-uuid/99b8f60e-c1eb-4482-a22f-6a49a5572401 ro vga=0x317 nopat
initrd /kernel26.img

Hopefully this can be useful ;)

Saturday, April 25, 2009

Linux is neither heaven nor hell (3)

前两天开始写这个系列,本来是打算先写天堂的,不过我刚刚写完天堂的信仰之后就发生了无法配置X的惨剧,所以我决定先写“地狱“……

在Linux下,一个十分重大的问题就是升级。因为我们总是希望Linux更加的好用,所以大家弄出了各种各样的新鲜东西,引诱你升级。而现实的另一面是可能过去遇到的一个一直没有解决的问题一直在折磨你,而据说新版本解决了这个问题,所以需要升级。

在Linux升级的时候,需要首先做好搞砸整个系统再也看不到可爱的GUI界面的心理准备,备份好自己的文件,向图灵、冯诺依曼等计算机史上的贤者祷告,祈求得到他们的祝福。然后毕恭毕敬小心翼翼的输入升级的命令,接着就是听天由命了……可惜这些神明并不好伺候,有的时候他们会莫名其妙的降罪于我。比如我今天在笔记本电脑和台式机上同时升级我的arch Linux,笔记本上的表现很好(尽管Root Terminal不能用了,我的触摸板却神奇的好了,经过我的配置还支持了连为windos都不曾支持过的双指触控-_-b),而台式机则直接出现了最恶心的xorg错误,目前连正确的分辨率都无法设置。

Linux像地狱,因为我总是生活在恐惧之中,常常因为一个小小的贪心,陷入系统无数细节的深深泥沼……如果幸运的话还可以抓住manual、wiki、google和bbs这些救命稻草,如果不幸的话常常会花去数个小时也没有挣脱出来。在Linux这个原始蛮荒的丛林里,只有熟悉环境经验丰富的家伙才能像山猫一样游刃有余的穿行,很可惜我至今还是一个时常掉进坑里头破血流还半天爬不出来的小白鼠……

在这片丛林中,你脚下的土地都不是坚实而值得信任的;很多问题和硬件有关的。我不知道这种现状应该归罪于什么人,毕竟对于硬件厂商来说,支持纷繁复杂变幻迅速的Linux比支持用一只手的指头都能数过来的微软Windows要困难多了。这个社区缺乏一个强大的力量,了解并统一大家的意见提出一个清晰的标准;而没有这样一个清晰的标准,社区和外界的交流就会有很多困难。自由和效率不仅仅是一个政治问题,在很多地方都能看到这种博弈的影子。

有人说没必要这么复杂,装一个Ubuntu就好了,可就像在树林边的草地上散步,终归会因为窥见的诱惑或是其他的原因走进这篇丛林……复杂的系统软件如参天巨树遮天蔽日让人难辨方向,依赖关系的藤蔓纵横交错将人包围,脚下的硬件支持如同泥沼不知道什么时候就会陷进去,这就是Linux的地狱印象。

不过着绝望的印象中还有一丝的希冀:当最终穿过这片林子时,当初因好奇而迷失其中的小白鼠应该已经变成主宰丛林的大象了吧。

[ to be continued... ]

Friday, April 24, 2009

Linux is neither heaven nor hell (2)

昨天说了我在Linux下混的短短历史,其实没什么值得参考的,今天说说我对于类Unix系统和GNU/Linux的感想。

说到学习Linux,我觉得这个说法本身就有一点问题,尤其是对于绝大多数从Windows过去的童鞋(按理说从mac过去的同学应该问题小很多)不是学习一个操作系统如何使用,更主要的是在Linux背后的一些逻辑。没有这些逻辑,就会觉得始终不得要领,而这些逻辑不是Linus自创出来的,而是来源于光辉伟大千秋万岁的Unix系统。

Unix的逻辑是简单的逻辑。(尽管Linux有时候会让人觉得很复杂,这只是因为nix系的操作系统对于消费用户来说暴露了太多的细节,没有做到所谓的傻瓜化隔离)

Unix系统里很多东西都是保存在纯文本文件里的,软件的源代码,软件的设置,甚至软件的本身也很少包括不是从源代码来的东西。比如windows程序多数都会内置一个图标,而Unix程序一般会使用一个外部的单独的图片文件。这种看似原始的方式其实还是蛮有好处的,你可以方便的使用你喜欢的工具编辑你的软件的设置;而且即使你搞砸了,也只是破坏了一个软件的设置,试想如果你把Windows的注册表搞砸了是什么后果……(我记得某文科女生说过她的一个师兄告诉她改注册表就会死机,呵呵……)

Linux继承了这种简单,和所有类Unix系统一样,计算机的文件组织方式是一棵树,这棵树只有一个根,不论你有多少个硬盘,多少个设备,都是这个根上的分支而已。(而Windows呢?我的文件夹还有C盘都是什么关系?正是因为搞不清楚我的文件夹实际上是C盘上若干文件夹内容的映射,多少小白再重装电脑之后痛失桌面上刚刚写好的作业啊……)更好的是所有的类Unix系统的磁盘都是可以挂载在任一文件夹的。如果你希望在Windows上把某软件的缓存设置到内存上,那么你只能祈祷该软件可以设置缓存地址,否则没戏。而在Unix上你可以把内存变成ramdisk挂载在任何你觉得合适的地方。逻辑简单,用法灵活。

很多人提到Linux相到的就是free,可惜理解的意思往往是“不要钱”。卓越上一份Windows也就是几百块,我还真不相信那些叫嚣着微软黑我屏我就跟盖茨拼命的家伙们拿不出来这个钱;把盗版微软觉得理所应当的人,几乎一定认为Linux社区应该把什么都给他免费准备好,生怕他不用……GNU/Linux的free更多的含义应该是自由,作为万灵之长了解并操作一个机器的自由。

有些人会说了,我们不是学计算机的,我就是一个OL,我搞不定C语言,弄不明白算法啦,我只想知道如何写报表怎么办呢?——这些都对,可是这不是褫夺自由和权力的理由。我们的自由和权力与生俱来,我们使用软件是委托其他人帮助我们实现我们的权利,而不是放弃我们的自由和权力。假如因为你扭了脚,要求我代你去超市买只菠萝,我说从此你的钱包就归我,你一定不会答应。所以拥有操作你的电脑的权利的人永远是你而不是某软。所以用某软的东西不是大问题,觉得电脑只有靠某软才能转就不对了。

某软的系统的逻辑也是简单——用户的头脑应该是简单的。于是某软私自做了很多的决定,既不告诉你为什么这么决定,也不说好处是什么,甚至不告诉你它做了决定。客观地说我不认为某软那些家伙们没能力做一个更好的系统出来,不过他们都忙着防范假象中的傻瓜用户把事情搞砸了。(这就和“为了防止你们把不靠谱的人选为xx代表,我熬夜把你们的选票上的圈都画好了,你们到时候拿过来直接扔到投票箱里就好了”是一个逻辑)微软的消费市场操作系统通过图形界面能干很多事情,但是没了图形界面基本干不了啥事情。

我认为Linux的桌面应用永远也不会成为主流,甚至可能在这个脑残和娱乐化的时代用户越来越少;但愿若干年后,还有一种叫做自由的精神香火不灭吧。

【 to be continued… 】

Thursday, April 23, 2009

Linux in neither heaven nor hell (1)

今天Emma童鞋问我用Linux多久了,我说这要看从什么开始算起,是第一次虚拟机安装?第一次在电脑上安装?还是最近的一次开始使用。于是Emma童鞋创造性的提出了应该看总时间,那么把若干次尝试零零星星的合计起来大概应该是一年吧。

这“一年”里我用过很多发行版,最开始是Ubuntu,因为据说用户多资料多中文社区好,后来发现用户多和中文社区都是很不本质的问题,资料还不怎么好(当时ubuntu的wiki里面有很多陈旧的东西)。尽管当时我还是离开了Gnome或者KDE什么都干不了的超级小白,还是果决的走上了一条漫漫长路——换发行版。

在Ubuntu之后,我现跳到了openSUSE。我用SUSE的原因十分值得鄙视,就是当时的SUSE的grub界面和KDE界面比较好看——我后来才知道这些都是很不本质的问题,换起来很容易(现在偶尔还听到有人说Ubuntu/SUSE/Fedora好看或者不好看,就会想起当初白白的我呀……很傻很好奇,呵呵)。不过openSUSE的教育网源是不大容易找的,在T大那个上国外网无比困难的情况下(在国内网络噪音远远大于信息的条件下,还让学生只能上国内网,T校真的是太没眼界了;单单知道怕国外势力毒害大好青年,不知道有金盾护卫祖国未来么;百年名校落得如此畏畏缩缩,唉),我的“华丽革命”没多久就华丽丽的收场了T___T

SUSE之后换了据说用户也很多的Fedora Core(当时还是叫做Fedora Core的,后来才改名叫作Fedora),可是我很快就被rpm打败了,依赖关系这个概念对小白太复杂了……

在然后我又一次回到了apt的怀抱,不过不是ubuntu,也不是加强版ubuntu——Mint,而是ubuntu的嗲地——debian。有科大的教育网源,有舒适的apt,于是我安顿很长时间。不过呢,debian太有当爹的感觉了,等一个软件进testing都得半年,进stable就更漫长了……这对于服务器不是问题,但是对于桌面应用这个就是问题了,毕竟Linux桌面上很多东西就靠等新品了呢……

后来我搞了一次debian的dist update,把它搞死了……然后也懒得修理,就抛在那里去用cygwin了……

再后来就是今年开始的arch冲击了,呵呵。从只有bash, ssh, wget, ftp, make, gcc, tar, pacman, vim等几十个小工具开始的系统建造之旅。这是我第一次下了决心要把该知道的都知道了,告别没了X就完蛋的时代。一路走来,我认识了以前不认识的/etc里的大部分文件,我知道了HAL的设计思想,我知道了Gnome中挂载硬盘分区是通过pmount的……后来我发现原来系统是可以通过tar备份迁移的,再后来知道原来神奇的ZFS文件系统有snapshot功能……

不过在我的笔记本上我还是没搞明白如何启用我的触摸板……我不知道如何让系统支持我的笔记本的Fn组合键……我更不知道如何让openoffice.org在绘制三维图表的时候不卡……最主要的问题是我现在没有充裕的时间来研究这些奇怪的问题=(

【 to be continued… 】

Wednesday, April 15, 2009

面对网页的遐思

本来我认为技术应该是越来越方便的,可是忽然想到网页制作,发现不是那么回事。

当年dreamweaver横空出世,与frontpage争锋“用table布局的最强大工具”;而今虽然土坯还在孜孜不倦的出dw cs2, dw cs3, dw cs4 实际上严肃的实用网页基本上都变成用文本编辑器(比如记事本)写代码的了(不知道T大的计算机文化基础课程还要不要大家做网页了,当年会有dreamweaver可是个“先进”工具的说……如果还在教dreamweaver我就不的不鄙视一下母校何其土鳖……当然作为一个第三世界国家我没指望大学教学能引领研究和产业发展,至少也得跟上时代步伐)

的确上来就教如何手写代码看起来很是不人性化,大有要非ECS系童鞋小命的感觉,不过从只有head, title, body, p标签开始学习做其实还挺有趣的,比一个一对按钮面板不知道怎么用的dw强多了;当今网页创作工具再次倒退回到了文本编辑器时代。

想想技术变化真是无情,当年一统江湖的大杀气如今成了土老冒的象征……如今漫天的div盒子在html5的语义标签下是不是也很快就要黯然落幕了呢?这个产业真的够残忍,几年时间就把认识颠覆一遍,知识淘汰一遍,一不小心没跟上趋势就被拍死在沙滩上了……

退化进化终究都是变化啊

btw,忽然回想起大四上的一门完全没花心思的课——貌似叫做网络信息论——想起樊平毅老师,当时很不愿意去翻找论文和经典教材,现在才恍然发现追本溯源,看清时下纷繁技术的前世今生,判断它未来,是如此的重要。

Monday, March 30, 2009

Clone Arch Linux to another computer

I’ve just cloned my arch linux installation from my lab pc to my laptop, and it is much easier than I’ve expected. First I packed every thing up into a tar in a removable disk like this: (you need to change sdxx and sdyy below to your corresponding partition)

#mount the backup disk
mkdir /mnt/backup
mount /dev/sdxx /mnt/backup
cd /
tar -cvpzf /mnt/backup/BACKUP_FILE.tar.gz --exclude=/{dev,lost+found,mnt,proc,sys,tmp,}/* /

Then in my laptop:

# boot with arch iso
# mount the dest partition
mkdir /mnt/arch
mount –t ext3 /dev/sdyy /mnt/arch
# mount the backup disk
mkdir /mnt/backup
mount –t vfat /dev/sdxx /mnt/backup
# expand the installation tar
cd /mnt/arch
tar –xvpzf /mnt/backup/BACKUP_FILE.tar.gz
# something necessary to boot
chroot /mnt/arch
cd /dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
# modify the /etc/fstab
# make a new boot ramdisk
mkinitcpio -p kernel26
# install grub
# modify /boot/grub/menu.lst
exit
umount /dev/sdxx
umount /dev/sdyy
shutdown –r now
# have fun

Besides what are listed here, I also changed my video card driver and edited my /etc/xorg.conf file. The workflow works well for Arch Linux, but might not work exactly with other distro(e.g. mkinicpio seems to be Arch-only), in this case you may need to consult the all-mighty adviser – Google ;)

Monday, March 23, 2009

Cannot use visudo?

Su is not always the best tool to grand permission to users, so I installed sudo on my Arch Linux system. However when I tried to issue visudo, I got the following error:

bash-3.2# visudo
bash: visudo: command not found
The reason of this is quite simple - /usr/sbin is not in the PATH environment variable by default, and you can locate the visudo command by:
bash-3.2# whereis visudo
visudo: /usr/sbin/visudo /usr/share/man/man8/visudo.8.gz
so just use the full path to visudo:
bash-3.2# /usr/sbin/visudo
then everything goes right.

Sunday, March 22, 2009

Script to set all pdf bookmarks to zoom: inherit

When you create a bookmark in Acrobat, it automaticly sets the current zoom setting to te bookmark. This may be smart and sweet for someone, but to me it's stupid and annoying. Since when I read a file in a large screen, I want a greater zoom, while on a smaller screen, I wanna save space and see more content; setting a zoom for bookmarks screws things up. Finally I found {a great perl script} that can convert all pdf bookmark to zoom: inherit.

Use the bookmarks-fitpage.pl script from the zip, which set all bookmarks to zoom: inherit (the script is named as fitpage, which is a bit confusing...)

Notice that the script only works for PDF version 1.4 or earlier, if you're using Acrobat 9, you can convert the file to pdf-1.4 (Acrobat 5) by going to menu: advanced>print production>preflight, the wizard will do a nice convert job for you.

VIM in GNU coding style

I guess I'll start working on GCC recently, so I tried to prepare my VIM for GNU coding style. However, it's not as easy as I hoped, since VIM seems to favor BSD style more than GNU style which is a great waste of screen space in my view...Anyway, after a vast amount of Googling and attempts, it works now. Here's what I did to VIM: create a file named c.vim in my "~/.vim/after/ftplugin" directory, with the following content:
"GNU Coding Standards
setlocal cindent
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal expandtab
setlocal shiftwidth=2
setlocal tabstop=8
setlocal softtabstop=2
setlocal textwidth=80
setlocal fo-=ro fo+=cql
I have to put it here otherwise the settings might be overrode by VIM's default ftplugin settings.

Saturday, March 21, 2009

My Score Summary as a Nerd…

I came accross this quiz (nerd quiz) when I was browsing my RSS feeds -____-b

Overall, you scored as follows:




10% scored higher (more nerdy),
1% scored the same, and
89% scored lower (less nerdy).

What does this mean? Your nerdiness is:
High-Level Nerd. You are definitely MIT material, apply now!!!.

Wednesday, March 18, 2009

Vim春季新装面世


Vim是什么?Vim是一种异空间里的宗教……那就让我来展示一下我看到的Vim世界的样子吧=)
color scheme: molokai

Friday, February 27, 2009

Tip:如何让Acrobat不提示阅读未标记文档

今天发现用Acrobat打开某课件的时候总是提示如何阅读未标记文档的对话框,十分的恼人。再选项里面找了一圈都没有发现有能够关掉这个功能的方法。(看来因为关掉阅读功能作为给残障人士带来不便,所以“政治不正确”,所以没有这个选项)

于是我很愤愤,不过最后还是用一个十分山寨的办法解决了。到acrobat的目录里,把一个叫做的Accessibility.api东西重命名成了Accessibility.api.damn,于是这个烦人的提示终于不再出现了=)

Sunday, February 22, 2009

虚拟机学Linux的悲剧

今天从实验室回来忽然发现在虚拟机里的arch linux上不去网了,而我还没装上图形界面呢……于是翻了俩个小时的wiki也没查出个啥问题,一直"ping www.google.com”都是丢包100%

怀疑来怀疑去,终于想起来好像在实验室用ping命令也是不成功的,但是可以连接源,晚上折腾的时候手上连文本的浏览器lynx都没有,所以用ping来测试。查看了一下VirtualBox 2.1.4的help文件发现原来在vbox的NAT模式下ping不通才是常态-____-b

于是我晚上都是在瞎忙活了>_< 剩下的未解决的问题是在vbox里的arch不能访问ipv6的源,问题在哪里……

【更新
刚才装上了lynx浏览器,终于有了访问web的方式了,哈哈,连接www.kame.net,得到不动的海龟(图片名称,嗯)证明ipv6访问有问题而不是源的问题。

又在vbox里启动了windows xp,安装IPv6支持,还是不能看到会动的可爱小海龟:( 于是我暂时的结论就是vbox的NAT模式不能使用IPV6……

如果我是一个第一次接触linux的小朋友,一定被弄跑了,所以为了避免因为虚拟机带来的不确定性,除了实验分区等危险操作,还是老实的用真机器吧。

Friday, February 20, 2009

Arch貌似不错啊

今天开始在虚拟机里面折腾 Arch,发现Arch的wiki的质量很是不错(比某U的强多了),直追gentoo呀~默认安装的Arch是没有图形界面的(这么“反动”的发行版似乎已然不常见了),而阅读wiki中关于GNOME的安装的部分才发现该发行版的GNOME的安装被分解的如此详细,一大堆早就看不顺眼的组件都可以不装:) 对于GNOME的废物组件我是很有怨念的,当年俺还是特白的小白鼠的时候(现在是比较白的小白鼠-__-b),装了某U没事干就想在新立得里面把Gnome-games卸载掉,结果哗啦哗啦一大堆我不太明白的东西滚过后,重启后发现没图形界面了T__T 当时一点法子都没有呀,只好重装了一次某U ~>_<~ 往事不堪回首(尽管至今也没啥数据放在nix下,浪费点时间而已),我不禁想如果我当初早知道有种叫做Arch的发行版,那么有可能:
  1. 我现在对linux了如指掌,成为开源应用强人
  2. 我认为这个东西太可怕了,我不想RTFM,于是至今视linux为异端
第一种情况的可能性……呃,可以忽略了……所以尽管某U发行版对kernel等贡献比较少,还多少能拉点人来看看linux的:大部分对社区意义不大(如我),很少部分成了开源生力军;所以基数还是蛮有意义的。

但愿本周末能在虚拟机上把KDE 4.2完整的运行起来……

Thursday, February 19, 2009

damned linux distros:(

前两天在debian lenny下发现有个东西死活装不上(谁让debian的口号是稳定呢,某些发行版current里面到东西都要比debian experimental里面都要新……而我用debian是当桌面用的,偶尔一两个程序crash一下我是不在乎的,而现在linux桌面到发展速度还是很不容小视),于是就英勇到跳槽到了fedora 10(还好我的home是个单独到分区,跳槽方便快捷)。
可是开始看起来很美的(尤其是启动界面不错,视觉系一下,咔咔)fedora用着发现也不怎么样……比如说Yum装东西到速度实在是比aptitude慢多了,在漫长到安装程序过程中干别的事情还卡:( 我的fedora是用liveCD安装的,安装后发现有网络设置不长记性到毛病,每次开机后都会自动设置成DHCP……吐血ing
……
于是就有了更加bt的念头,我想尝试一下传说中的小众发行版了,比如说Arch Linux(本来也挺向往gentoo的,不过现在手里没有一台”现代“配置的机器,非要用legacy machine运行这个需要自己编译一大堆东西到系统实在是太sm向了=_=)虽然bsd风格的简洁优雅到启动脚本比起sysV风格的更加适合俺这种简洁直白控,可是我不能没事去对着启动脚本发呆吧-__-||
……
这两天实在是没有什么动力干正事,于是就拜读了Filesystem Hierarchy Standard,还是蛮有收获的,推荐茶余饭后阅读之(现在有些发行版装软件到时候乱塞,不过其实社区的维护者也不容易,那么多包能稳定运行就不错了,何况某些路径还是hard code在代码里)
……
话说回来fedora毕竟是大户人家的小姐,虽然难伺候了一点,还是很知道如何待人接物的——比如默认的中文字体蛮好看,而且把firefox的默认保存路径设为/home//Download,自动挂载非*nix分区做的也不错:)
……
等周末了在virtualbox里面装个arch linux试试,如果有人用过给点提示哈~