Monday, 1 December 2008

Review: pointer, reference in c++

A Reference Guide
Last updated Jan 1, 2004.from: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=166

Unlike most other programming languages, C++ offers an unusual diversity of argument passing mechanisms: pass by value, pass by address, and pass by reference. Additional non-standard argument-passing mechanisms are also supported by certain compilers, such as passing arguments on a register. Today I will explain the semantics of the three standard argument passing mechanisms, and focus on reference variables.

A bit of History
Most high level programming languages offer only a single argument passing mechanism. In Pascal and Ada, for example, arguments are passed by reference and that's it. In Java, objects are passed by reference, whereas fundamental types such as int and boolean are passed by value.

The crucial point, however, is that programmers cannot intervene or control the actual argument passing mechanism that the language applies. C is different in this regard. Built on the foundations of BCPL and B, which were really nothing more than high-level assembly languages, it offered two argument passing mechanisms: pass-by-value and pass by address. Oddly enough, it didn't offer the more common notion of pass by reference.

Pass by Value
Pass by Value is the default argument passing mechanism of both C and C++. When a caller passes by value an argument to a function (known as the callee), the latter gets a copy of the original argument. This copy remains in scope until the function returns and is destroyed immediately afterwards. Consequently, a function that takes value-arguments cannot change them, because the changes will apply only to local copies, not the actual caller's variables. For example:

void negate(int n) //buggy version
{
n=-n;//affects a local copy of n
}
void func()
{
int m=10;
negate(m);//doesn't change the value of m
std::cout<<m<<std::endl; //diplay: 10
}
When negate() is called, C++ creates a fresh copy of m on its stack. negate() then modifies this private copy, which is destroyed immediately when it returns. The original variable m remains intact, though. Consequently, the cout expression displays 10 rather than -10. If you want the callee to modify its arguments, you must override the default passing mechanism.

Pass by Address
In C, the only way to achieve this is by passing the argument's address to the callee. This passing mechanism is traditionally called pass by address.

In the literature, this often called pass by reference too, although it's is a misnomer -- C++ uses this term to denote a radically different passing mechanism. For example,

void negate(int * pn)
{
*n=-*n;
Similarly, the caller must also be adjusted:

void func()
{
int m=10;
negate(&m);//pass m's address<
std::cout<<m<<std::endl; //display: -10
}
Pass by Reference
This is all well and good. The problem with this technique is that it's tedious and error-prone. My impression is statistically, most C/C++ function calls don't use pass by value so forcing programmers to override the default passing mechanism using the &, * and -> operators is an example of a bad language design choice. C++ creators were aware of this. They introduced a new type of argument passing, namely pass by reference. The addition of reference variables and arguments to C++ was only a means of fixing an historical accident made in C about a decade earlier rather than a genuine innovation. However, the introduction of references did affect fundamental programming idioms in C++.

Most textbooks will tell you that a reference is "an alias for an existing object." For example,

int m=0;
int &ref=m;
The reference ref serves as an alias for the variable m. Thus, any change applied to m is reflected in ref and vice versa:

++m;
std::cout<<ref<<std::endl;// output 1
++ref; //increment m
std::cout<<m<<std::endl;// output 2
In other words, ref and m behave as distinct names of the same object. In fact, you may define an infinite number of references to the same object:

int & ref2=ref;
int & ref3=m;
//..and so on
Here ref2 and ref3 are aliases of m, too. Notice that there's no such thing as a "reference to a reference;" the variable ref2 is an alias of m, not ref.

Usage
In most cases, references are used as a means of passing arguments to a function by reference. The nice thing about references is that they function as pointers from a compiler's point of view, although syntactically they behave like ordinary variables. They enable a callee to alter its arguments without forcing programmers to use the unwieldy *, & and -> notation:

void negate(int & n)
{
>n=-n;//modifies caller's argument
}
void func()
{
int m=10;
negate(m);//pass by reference
std::cout<<m<<std::endl; //diplay: -10
}
Advantages of Pass by Reference
Passing by reference combines the benefits of passing by address and passing by value. It's efficient, just like passing by address because the callee doesn't get a copy of the original value but rather an alias thereof (under the hood, all compilers substitute reference arguments with ordinary pointers). In addition, it offers a more intuitive syntax and requires less keystrokes from the programmer. Finally, references are usually safer than ordinary pointers because they are always bound to a valid object -- C++ doesn't have null references so you don't need to check whether a reference argument is null before examining its value or assigning to it.

Passing objects by reference is usually more efficient than passing them by value because no large chunks of memory are being copied and constructor and destructor calls are performed in this case. However, this argument passing mechanism enables a function to modify its argument even if it's not supposed to. To avert this, declare all read-only parameters as const and pass them by reference. This way, the callee will not be able to modify them:

void display(const Shape & s)
{
s.draw();
}
Summary
The introduction of references to C++ initially caused a bit of confusion, especially among ex-C programmers who weren't sure which passing mechanism to use when (and in those days, virtually all C++ programmers were former C programmers). Even illustrious gurus offered to use the following dichotomy: when a function modifies its arguments, pass them by address and when it doesn't, pass them as references to const.

Today, using bare pointers is a thing of the past. In most cases, C++ offers superior alternatives that are both safer and cleaner. Similarly, when you decide how to pass arguments to a function, use references by default (except when you truly need to pass them by value) and avoid passing by address, unless there's a compelling reason to do so. If the function in question shouldn't modify its arguments, they should be declared const and passed by reference; the lack of the const qualifier indicates that the function is allowed to modify an argument. When should you pass arguments by address? Only when the function deals with real pointers. For instance, a function that allocates raw storage, or when a null pointer is a valid option. Otherwise, use references.

Saturday, 29 November 2008

HOWTO: stop imsetting-daemon im-info-daemon

I really don't know how many people will switch between more than 2 input methods, while imsettings, as a project, just provide such a function.
This is useless to me, and costing almost 7m memory when booting up fedora.

This is the solution to stop it, and still keeping scim in your system.

Put 'DISABLE_IMSETTINGS=true' in the first line of '/etc/X11/xinit/xinitrc.d/50-xinput.sh'.


###############################################################################

IMSettings
==============
IMSettings is a framework that delivers Input Method
settings and applies the changes immediately. so it will
takes an effect without restarting applications and the
desktop.

Background
==============
Input Method is used to input some dozens of characters that
can't be represented with ASCII characters, with some
framework such as XIM and SCIM via GTK+/Qt
immodule. particularly which to handle languages that is a
bit complex to do the same thing with the keyboard layout
such as XKB. In the past, those frameworks has been applied
through the environment variables, such as XMODIFIERS and
GTK_IM_MODULE. and can't be influenced immediately and can't
be without restarting the desktop because of its nature -
it's being inherited from the parent process unless it's
being brought up with the obvious thing from the terminal
say. Also, there are no such framework to bring up the
necessary process at the run time - of course anyone could
runs it manually though, it's totally out of focus on this
project.

Features
============
* Provide the information of Input Method through IMSettings
* Provide the DBus service to start/stop process of Input
Method
* Provide the way to apply Input Method to applications
immediately

Scope
=========
IMSettings may helps when:

* you may want to disable Input Method entirely to use
features on any applications, which actually can't use
with Input Method because of the key conflicting.
* you may try another Input Method without closing current
desktop session.
* someone may wants to borrow your desktop temporarily,
which uses different Input Method.
* the appropriate Input Methods needs to be installed by
default regardless of you use, such as Live image.

Supported Toolkits
======================
* GTK+ (with GConf backend)
* Xfce (with GConf backend and a plugin for xfce-mcs-manager)
* X (with IMSettings XIM server; require libgxim)

Information files for Input Method
======================================
To make Input Methods available from IMSettings, every Input
Methods that hopes so has to have the information file to
let IMSettings know. those files is usually put under a
directory where you can change the default value with
--with-xinputdir. the filename has to contain .conf or
something that you can also change the default value with
--with-xinput-suffix to avoid listing every Input Methods
that might not work for some languages. Input Methods
doesn't support multiple languages such as XIM doesn't have
to have .conf suffix or so. xim.conf can deals with such
configuration files properly for appropriate languages
according to current locale.

Available parameters
=======================

The following parameters can be described as the shell
environment variables like FOO=BAR in the information file.

* AUXILIARY_PROGRAM=

An optional program that may want to bring up for Input
Method, such as the panel and the toolbar and so on.

* AUXILIARY_ARGS=

A list of command line options for AUXILIARY_PROGRAM.

* GTK_IM_MODULE=

GTK+ immodule name that want to use.

* ICON=

An icon file to use in GUI.

* IMSETTINGS_IGNORE_ME=

A parameter to hide Input Method from the inventory. you
however can still take an action against such Input Method
via IMSettings.

* LONG_DESC=

An optional long description to explain what this Input
Method is.

* PREFERENCE_PROGRAM=

An optional program that set up Input Method. IMSettings
itself do nothing on this parameter. but other tools, such
as im-chooser will take an action for that.

* PREFERENCE_ARGS=

A list of command line options for PREFERENCE_PROGRAM.

* QT_IM_MODULE=

Qt immodule name that want to use.

* SHORT_DESC=

An optional short description to explain what this Input
Method is. this variable is also sued for the key to do
something on IMSettings. e.g. to start/stop Input Method
and get the information and so on. so this parameter has
to be unique.

* XIM=

This variable is used for XIM. actually it looks like
XMODIFIERS=@im=$XIM.

* XIM_PROGRAM=

A XIM server be brought up to communicate through XIM
protocol.

* XIM_ARGS=

A list of command line options for XIM_PROGRAM.

Other variables used in xinput.sh
====================================

* DISABLE_IMSETTINGS=

If you want to disable imsettings feature entirely, set true. you'll
miss the feature able to change IM on demand but just need to reboot
or restart the desktop after changing something.

* IMSETTINGS_DISABLE_DESKTOP_CHECK=

If your desktop has XSETTINGS manager support and you're sure it also
supports imsettings, please file a bug to imsettings. and set true
temporarily to ignore checking the desktop.

Processes
============

* im-settings-daemon

A DBus service that provide a facility to start/stop IM processes.

* im-info-daemon

A DBus service that provide Input Method information.

* gconf-im-settings-daemon

A DBus service that provide a bridge to communicate GTK+ through GConf.

* imsettings-xim

A XIM bridge between client applications and real XIM server.

* imsettings-applet

An applet that provides a facility of changing IM temporarily. this also
supports XIM bridge. if imsettings-xim is running, this applet will sends
a signal to be terminated.

Friday, 28 November 2008

跳得太高了

BUGS: Samba shares

there are two type of share,
1) traditional way, GUI: system-config-samba.
2) nautilus-share, right click the folder you want to share, which is default in ubuntu. this need a line 'usershare owner only = False' to put into the global section in smb.conf, sometimes, 'usershare allow guests = yes' is also needed. This is working on the command of 'net usershare'.

1) system-config-samba will modify smb.conf; while 2) nautilus-share, using 'net usershare' will not change smb.conf. So these are different ways for sharing.

In Ubuntu, no matter what method you use, both works fine. But fedora, so far, only 1) works, while 2) always saying "'net usershare' returned error 255: net usershare: usershares are currently disabled".

Thursday, 27 November 2008

HOWTO: jython(java) calling c program in console

import java.lang

proc=java.lang.Runtime.getRuntime().exec("c:\\app.exe") // this app.exe is compiled from c
br=java.io.BufferedReader(java.io.InputStreamReader(proc.getInputStream()))
print br.readLine()
java.lang.System.out.println("last line")

=========================
Why not using os.popen() from python, is because there is a bug about calling popen. :)

happy thanksgiving

HOWTO: codecs from myplayer_win32

if the downloaded codecs file, all-20071007.tar.bz2, is extracted in /usr/lib/codecs

Then, to make these codecs visible to mplayer, do:

su

ln -sf /usr/local/lib/codecs /usr/lib/codecs && ln -sf
/usr/local/lib/codecs /usr/local/lib/win32 && ln -sf
/usr/local/lib/codecs /usr/lib/win32

Wednesday, 26 November 2008

efficiency of python calling c exetuable

python 可以用popen调用一个c语言的可执行程序。但是效率如何呢?

1)一个c程序: 调用一个循环求和从1到1000的function 10000次。
之所以要调用循环求和从1到1000,是因为这个function要声称另外的一个可执行文件供python调用,所以外部框架c和python都差不多,就是要往复调用这个function,以得出python与c的沟通效率。
#######################
/*
* File: newmain.c
* Author: cross
*
* Created on 26 November 2008, 16:08
*/

#include <stdio.h>
#include <stdlib.h>

struct timeb {
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
//ftime returns a struct with above structure.

int internal_loop(){
int ii=0,ss=0;
while (ii<1000)
{
ss+=ii;
ii++;
}
printf("%i\n",ss);
return ss;
}

int main(int argc, char** argv) {

struct timeb t1,t2;
double i=0,s=0;

ftime(&t1);

int repeat = 10000;
while(i<repeat){
s+=internal_loop();
i++;
}

ftime(&t2);
printf("%.1f\n",s);

printf("time = %ld.%d\n",t1.time,t1.millitm);
printf("time = %ld.%d\n",t2.time,t2.millitm);


return (EXIT_SUCCESS);
}


##################

2)以上的internal_loop function被单独生成一个c的可执行文件b.o,供python调用。以下是python代码。
##################

import datetime
import os

t1= datetime.datetime.now()

j=0
k=1000
for i in range(1,k):
printed=os.popen('/home/cross/NetBeansProjects/Application_2/b.o')
printed.readlines()
printed.close()

print # to print a new line

t2= datetime.datetime.now()

tstr=[(t2-t1).seconds,(t2-t1).microseconds] # the attributes of timedelta class: senconds and microseconds, from http://docs.python.org/lib/datetime-timedelta.html#l2h-602
print 'Repeated sum of 1-1000 ',k,' times : '
print tstr

###############

3) 只用python单独完成和1)一样的过程,python代码如下:
########################
import datetime

t1= datetime.datetime.now()

k=10000
for i in range(1,k):
    j=0
    for ii in range(1,1000):
        j=j+ii
    print j

print # to print a new line

t2= datetime.datetime.now()

tstr=[(t2-t1).seconds,(t2-t1).microseconds] # the attributes of timedelta class: senconds and microseconds, from http://docs.python.org/lib/datetime-timedelta.html#l2h-602
print 'Repeated sum of 1-1000 ',k,' times : '
print tstr

#####################


总结
如果成功运行以上两个程序,同样是运行10000次,1)耗时274毫秒;2)20秒。
可见python与其他程序通过popen这种字符沟通的效率是比较低的。以上,1)是同一个程序调用一个子函数,速度当然是最理想的。而2)是通过console的字符交换得以沟通,这种效率当然低,甚至这还远不如主程序和子程序的沟通效率。

通过1)和3)的比较,可以很容易看出来python的语法简单,但是python比c慢也是事实,3)用时3.8秒。

HOWTO: Calling c (or other programs) from python

Calling c (or other programs) from python

1. swig (to generate a python extention from c)
2. dl, python object (to call c shared library)
3. os.popen() (to call other exetuable programs)

In this example, I will use the 3rd method.

1) c program.
This is an example from netbeans, it can print all the arguments, argv[0] is the program name.
# args.c ###################################
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char**argv) {
int i;
// Prints arguments
printf("Arguments:\n");
for (i = 0; i < argc; i++) {
printf("%i: %s\n", i, argv[i]);
}

return 0;
}
#############################
compile it:
####
gcc args.c -o a.out
####

2) python script

# in python script ################
import os
printed = os.popen('./a.o hello world')
>>> printed.readline()
'Arguments:\n'
>>> printed.readline()
'0: ./a.o\n'
>>> printed.readline()
'1: hello\n'
>>> printed.readline()
'2: world\n'
>>> printed.readline()
''
##################################
Here printed is an python array object, all the methods for array are available.

Friday, 21 November 2008

C语言-指针; 2008温习

指针变量在定义中允许带初始化项。如:
int i, *ip=&i;
注意, 这里是用&i 对ip初始化, 而不是对*ip初始化。和一般变量一样,对于外部或静态指针变量在定义中若不带初始化项, 指针变量被初始化为NULL, 它的值为0。 Turbo C中规定, 当指针值为零时, 指针不指向任何有效数据, 有时也称指针为空指针。
int i=200, x;
int *ip;
我们定义了两个整型变量i,x,还定义了一个指向整型数的指针变量ip。i,x中可存放整数,而ip中只能存放整型变量的地址。我们可以把i的地址赋给ip:
ip=&i;
此时指针变量ip指向整型变量i.

字符指针
char *cp;
于是可用:
cp=a string;
使cp指向字符串常量中的第0号字符a, 如图所示。
CP----- | a | | s | t | r | i | n | g | \0|

以后我们可通过cp来访问这一存贮区域, 如*cp或cp[0]就是字符a,而cp[i]或*(cp+i)就相当于字符串的第i号字符,但企图通过指针来修改字符串常量的行为是没有意义的。
而char *Names[]表示指向字符的指针数组。


Turbo C中,数组名是数组的第0号元素的地址,因此下面两个语句是等价的
p=&a[0];
p=a;
根据地址运算规则,a+1为a[1]的地址,a+i就为a[i]的地址。
下面我们用指针给出数组元素的地址和内容的几种表示形式:
(1). p+i和a+i均表示a[i]的地址, 或者讲,它们均指向数组第i号元素, 即指向a[i]。
(2). *(p+i)和*(a+i)都表示p+i和a+i所指对象的内容,即为a[i]。
(3). 指向数组元素的指针, 也可以表示成数组的形式,也就是说,它允许指针变量带下标, 如p[i]与*(p+i)等价。
对于二维数组:
我们把a[0],a[1],a[2]看成是一维数组名,可以认为它们分别代表它们所对应的数组的首地址,也就是讲,a[0]代表第 0 行中第 0 列元素的地址,即&a[0][0], a[1]是第1行中第0列元素的地址,即&a[1][0],根据地址运算规则,a[0]+1即代表第0 行第1列元素的地址,即&a[0][1],一般而言,a[i]+j即代表第i行第j列元素的地址, 即&a[i][j]。
另外,在二维数组中,我们还可用指针的形式来表示各元素的地址。如前所述,a[0]与*(a+0)等价,a[1]与*(a+1)等价,因此a[i]+j就与*(a+i)+j等价,它表示数组元素a[i][j]的地址。
因此,二维数组元素a[i][j]可表示成*(a[i]+j)或*(*(a+i)+j),它们都与a[i][j]等价,或者还可写成(*(a+i))[j]。

在Turbo C中, 可定义如下的指针变量:
int (*p)[3];
指针p为指向一个由3个元素所组成的整型数组指针。在定义中,圆括号是不能少的, 否则它是指针数组, 这将在后面介绍。

指针数组
int *a[10];
定义了一个指针数组,数组中的每个元素都是指向整型量的指针,该数组由10个元素组成,即 a[0],a[1],a[2], ..., a[9],它们均为指针变量。a为该指针数组名,和数组一样,a是常量,不能对它进行增量运算。a为指针数组元素a[0]的地址,a+i为a[i]的地址,*a就是a[0],*(a+i)就是a[i]。


指针函数
当一个函数声明其返回值为一个指针时,实际上就是返回一个地址给调用函数,以用于需要指针或地址的表达式中。
格式:
类型说明符 * 函数名(参数)
当然了,由于返回的是一个地址,所以类型说明符一般都是int。
例如:int *GetDate();

函数指针
指向函数的指针包含了函数的地址,可以通过它来调用函数。声明格式如下:
类型说明符 (*函数名)(参数)
其实这里不能称为函数名,应该叫做指针的变量名。这个特殊的指针指向一个返回整型值的函数。指针的声明笔削和它指向函数的声明保持一致。
指针名和指针运算符外面的括号改变了默认的运算符优先级。如果没有圆括号,就变成了一个返回整型指针的函数的原型声明。
例如:
void (*fptr)();
把函数的地址赋值给函数指针,可以采用下面两种形式:
fptr=&Function;
fptr=Function;
取地址运算符&不是必需的,因为单单一个函数标识符就标号表示了它的地址,如果是函数调用,还必须包含一个圆括号括起来的参数表。
可以采用如下两种方式来通过指针调用函数:
x=(*fptr)();
x=fptr();
第二种格式看上去和函数调用无异。但是有些程序员倾向于使用第一种格式,因为它明确指出是通过指针而非函数名来调用函数的。

指针的指针
指针的指针看上去有些令人费解。它们的声明有两个星号。例如:
char ** cp;
如果有三个星号,那就是指针的指针的指针,四个星号就是指针的指针的指针的指针,依次类推。当你熟悉了简单的例子以后,就可以应付复杂的情况了。当然,实际程序中,一般也只用到二级指针,三个星号不常见,更别说四个星号了。
指针的指针需要用到指针的地址。
char c='A';
char *p=&c;
char **cp=&p;
利用指针的指针可以允许被调用函数修改局部指针变量和处理指针数组。

void FindCredit(int **);

main()
{
int vals[]={7,6,5,-4,3,2,1,0};
int *fp=vals;
FindCredit(&fp);
printf(%d\n,*fp);
}

void FindCredit(int ** fpp)
{
while(**fpp!=0)
if(**fpp<0)>
=====================
char *Names[]=
{
"Bill",
"Sam",
"Jim",
"Paul",
"Charles",
0
};

main()
{
char **nm=Names; /* nm是一个2维字符数组 */
while(*nm!=0) printf("%s\n",*nm++); /* *nm是指针,以确定指针指向非null */
/* 对于字符数组,数组名虽然是指针,但是也可以表示整个数组指向的字符串。反而“*数组名“却返回错误Segmentation fault。*/
}

先用字符型指针数组Names的地址来初始化指针nm。每次printf()的调用都首先传递指针nm指向的字符型指针,然后对nm进行自增运算使其指向数组的下一个元素(还是指针)。注意完成上述认为的语法为*nm++,它首先取得指针指向的内容,然后使指针自增。
注意数组中的最后一个元素被初始化为0,while循环以次来判断是否到了数组末尾。具有零值的指针常常被用做循环数组的终止符。程序员称零值指针为空指针(NULL)。

Wednesday, 19 November 2008

Terminology: West and East

Also, is it just me, or do Japan and New Zealand look suspiciously similar?  Has anyone seen them at a party together?

Assigning in C

int main ( int argc, char **argv ){}
int main ( int argc, char *argv ) {}

Quote:
An array of char pointers can be represented as a function parameter one of two ways: char *name[] or char **name. I have chosen to use the latter, you can use either one, it is a matter of style, which I refuse to dictate
#####################
In the code you quoted, the former is correct, the latter is wrong. (But since this is C, both main functions should return 0.)

Under certain circumstances, an array decays to a pointer to its first element. In that way, char **argv and char *argv[] are equivalent.
#####################
char *argv .. u r sending a pointer to a char as an argument..this can be a normal pointer or point to a array of chars...

char **argv .. u r sending a pointer to an array of pointers as an argument . which means, each element of this array can itself point to a char array..

Tuesday, 18 November 2008

HOWTO: free up memory

Free Memory by dropping caches | Timesys Embedded Linux

From: http://linux-mm.org/Drop_Caches
To use /proc/sys/vm/drop_caches, just echo a number to it.

To free pagecache:

# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

# echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, run sync first!

Here are the before and after results from my desktop:

# free
total used free shared buffers cached
Mem: 2074840 1656052 418788 0 140108 907920
-/+ buffers/cache: 608024 1466816
Swap: 3911816 76436 3835380

# sync ; echo 3 > /proc/sys/vm/drop_caches ; free
total used free shared buffers cached
Mem: 2074840 698472 1376368 0 268 126488
-/+ buffers/cache: 571716 1503124
Swap: 3911816 76436 3835380

HOWTO: Mysql JOIN

MySQL LEFT JOIN Explanation

(blogged from: http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php )

How is a LEFT JOIN different from a normal join? First of all, the syntax is quite different and somewhat more complex. Besides looking different, the LEFT JOIN gives extra consideration to the table that is on the left.

Being "on the left" simply refers to the table that appears before the LEFT JOIN in our SQL statement. Nothing tricky about that.

This extra consideration to the left table can be thought of as special kind of preservation. Each item in the left table will show up in a MySQL result, even if there isn't a match with the other table that it is being joined to.

MySQL Join and LEFT JOIN Differences

Here are the tables we used in the previous Mysql Joins lesson.

MySQL family and food Tables:

PositionAge
Dad41
Mom45
Daughter17
Dog
MealPosition
SteakDad
SaladMom
Spinach Soup
TacosDad

We executed a simple query that selected all meals that were liked by a family member with this simple join query:

Simplified MySQL Query:

SELECT food.Meal, family.Position
FROM family, food
WHERE food.Position = family.Position

Result:

Dad - Steak
Mom - Salad
Dad - Tacos

When we decide to use a LEFT JOIN in the query instead, all the family members be listed, even if they do not have a favorite dish in our food table.

This is because a left join will preserve the records of the "left" table.

MySQL LEFT JOIN Example

The code below is the exact same as the code in the previous lesson, except the LEFT JOIN has now been added to the query. Let's see if the results are what we expected.

PHP and MySQL Code:

// Make a MySQL Connection
// Construct our join query
$query = "SELECT family.Position, food.Meal ".
"FROM family LEFT JOIN food ".
"ON family.Position = food.Position";


$result = mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['Position']. " - ". $row['Meal'];
echo "
";

}
?>

Display:

Dad - Steak
Dad - Tacos
Mom - Salad
Daughter -
Dog -

Success! The LEFT JOIN preserved every family member, including those who don't yet have a favorite meal in the food table! Please feel free to play around with LEFT JOIN until you feel like you have a solid grasp of it. This stuff isn't easy!


Another example for 'JOIN', 'LEFT JOIN' and 'RIGHT JOIN' is here:

http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN.html

mysql, simple commands 2008

Selecting a database:

mysql> USE database;

Listing databases:

mysql> SHOW DATABASES;

Listing tables in a db:

mysql> SHOW TABLES;

Describing the format of a table:

mysql> DESCRIBE table;

Creating a database:

mysql> CREATE DATABASE db_name;

Creating a table:

mysql> CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE));
Ex: mysql> CREATE TABLE pet (name VARCHAR(20), sex CHAR(1), birth DATE);

Load tab-delimited data into a table:

mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table_name;
(Use \n for NULL)

Inserting one row at a time:

mysql> INSERT INTO table_name VALUES ('MyName', 'MyOwner', '2002-08-31');
(Use NULL for NULL)

Retrieving information (general):

mysql> SELECT from_columns FROM table WHERE conditions;
All values: SELECT * FROM table;
Some values: SELECT * FROM table WHERE rec_name = "value";
Multiple critera: SELECT * FROM TABLE WHERE rec1 = "value1" AND rec2 = "value2";

Reloading a new data set into existing table:

mysql> SET AUTOCOMMIT=1; # used for quick recreation of table
mysql> DELETE FROM pet;
mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table;

Fixing all records with a certain value:

mysql> UPDATE table SET column_name = "new_value" WHERE record_name = "value";

Selecting specific columns:

mysql> SELECT column_name FROM table;

Retrieving unique output records:

mysql> SELECT DISTINCT column_name FROM table;

Sorting:

mysql> SELECT col1, col2 FROM table ORDER BY col2;
Backwards: SELECT col1, col2 FROM table ORDER BY col2 DESC;

Date calculations:

mysql> SELECT CURRENT_DATE, (YEAR(CURRENT_DATE)-YEAR(date_col)) AS time_diff [FROM table];
MONTH(some_date) extracts the month value and DAYOFMONTH() extracts day.

Pattern Matching:

mysql> SELECT * FROM table WHERE rec LIKE "blah%";
(% is wildcard - arbitrary # of chars)
Find 5-char values: SELECT * FROM table WHERE rec like "_____";
(_ is any single character)

Extended Regular Expression Matching:

mysql> SELECT * FROM table WHERE rec RLIKE "^b$";
(. for char, [...] for char class, * for 0 or more instances
^ for beginning, {n} for repeat n times, and $ for end)
(RLIKE or REGEXP)
To force case-sensitivity, use "REGEXP BINARY"

Counting Rows:

mysql> SELECT COUNT(*) FROM table;

Grouping with Counting:

mysql> SELECT owner, COUNT(*) FROM table GROUP BY owner;
(GROUP BY groups together all records for each 'owner')

Selecting from multiple tables:

(Example)
mysql> SELECT pet.name, comment FROM pet, event WHERE pet.name = event.name;
(You can join a table to itself to compare by using 'AS')

Currently selected database:

mysql> SELECT DATABASE();

Maximum value:

mysql> SELECT MAX(col_name) AS label FROM table;

Auto-incrementing rows:

mysql> CREATE TABLE table (number INT NOT NULL AUTO_INCREMENT, name CHAR(10) NOT NULL);
mysql> INSERT INTO table (name) VALUES ("tom"),("dick"),("harry");

Adding a column to an already-created table:

mysql> ALTER TABLE tbl ADD COLUMN [column_create syntax] AFTER col_name;

Removing a column:

mysql> ALTER TABLE tbl DROP COLUMN col;
(Full ALTER TABLE syntax available at mysql.com.)

Batch mode (feeding in a script):

# mysql -u user -p <> source batch_file;

Backing up a database with mysqldump:

# mysqldump --opt -u username -p database > database_backup.sql
(Use 'mysqldump --opt --all-databases > all_backup.sql' to backup everything.)
(More info at MySQL's docs.)

Join tables:
# SELECT * FROM cars JOIN colors ON colors.car_ID=cars.id
# SELECT * FROM cars AS cr JOIN colors AS cl ON cl.car_ID=cr.id
After the ON, we state on wich columns the tables should join. Every color has a reference to a car by the "car_ID" column. Every car has an
ID, and these two columns are the link between the two tables.

Saturday, 15 November 2008

HOWTO: [Lyx] replace the name of bibliography with reference

in lyx, to replace the name of bibliography with reference, using report as document class

\renewcommand{\bibname}{References}
marked as TeX

==================================
\newcommand \renewcommand

\newcommand{cmd}[args][opt]{def}
\renewcommand{cmd}[args][opt]{def}
\providecommand{cmd}[args][opt]{def} -- LaTeX2e

These commands define (or redefine) a command.

* cmd The name of the new or redefined command. A \ followed by a string of lower and/or uppercase letters or a \ followed by a single nonletter. For \newcommand the name must not be already defined and must not begin with \end; for \renewcommand it must already be defined. The \providecommand command is identical to the \newcommand command if a command with this name does not exist; if it does already exist, the \providecommand does nothing and the old definition remains in effect.

* args An integer from 1 to 9 denoting the number of arguments of the command being defined. The default is for the command to have no arguments.

* opt (LaTeX2e only) If present, then the first of the number of arguments specified by args is optional with a default value of opt; if absent, then all of the arguments are required.

* def The text to be substituted for every occurrence of cmd; a parameter of the form #n in cmd is replaced by the text of the nth argument when this substitution takes place.

Examples
\newcommand{\water}{H$_2$O}

This would allow one to write, e.g.,

The formula for water is \water.

or

\water\ is the formula for water.

Note, in the second case, the trailing \ followed by a blank is required to ensure a blank space after the H2O; LaTeX ignores the blank following a command, so the space has to be specifically inserted with the \.

As a second example consider

\newcommand{\hypotenuse}{$a^{2}+b^{2}$}

Note that this will produce the desired formula in text (paragraph) mode because of the $...$ in the definition. In math mode, however, the first $ in the definition will cause LaTeX to leave math mode, causing problems.

In LaTeX 2.09 a standard trick for getting around this is to put the math-mode expression in an \mbox, viz.,

\newcommand{\hypotenuse}{\mbox{$a^{2}+b^{2}$}}

In LaTeX2e the \ensuremath command has been provided to alleviate this problem. The argument of the \ensuremath command is always processed in math mode, regardless of the current mode. Using this mechanism the above could be written as

\newcommand{\hypotenuse}{\ensuremath{a^{2}+y^{2}}}

Kobe dunk in the air

Thursday, 6 November 2008

HOWTO: find

From man:
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell. The command is executed in the starting directory.

find . -type f -exec file '{}' \; # '{}' or {}, and there is a space before '\';

Runs ‘file’ on every file in or below the current directory. Notice
that the braces are enclosed in single quote marks to protect them from
interpretation as shell script punctuation. The semicolon is similarly
protected by the use of a backslash, though single quotes could have
been used in that case also.

-----------------------------------------------------------------

`{}' is replaced by the current file name being processed;
\ is used for the iteration of found files.
; is to tell -exec that the job is done.

Example: find . -exec grep 'title="Phoca Gallery"' {} \; -ls
Normally above example suits our search jobs.

Monday, 3 November 2008

Confusing terminology in Fedora and Ubuntu

What is called 'orphan', and what is 'obsolete'? Fedora and Ubuntu give us contradictive and confusing definition.

Let's have a look here.

=========================================
Fedora:

"package-cleanup(1)"
--orphans
List installed packages which are not available from currenly configured repositories.
--leaves
List leaf nodes in the local RPM database. Leaf nodes are RPMs that are not relied upon by any other RPM.

=========================================
Ubuntu:

--'synaptic-status-installed(local or obsolete)'
Display only packages that are not (for longer) included in one of the specified repositories.

--"deborphan"
deborphan finds "orphaned" packages on your system. It determines which packages have no other packages depending on their installation and shows you a list of these packages.

=========================================

Accordingly, orphans(fedora)=obsolete(ubuntu), leaves(fedora)=orphan(ubuntu).

Thursday, 30 October 2008

Repositories for Ubuntu 9.04

# deb cdrom:[Ubuntu 9.04 _Jaunty Jackalope_ - Release i386 (20090420.1)]/ jaunty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://gb.archive.ubuntu.com/ubuntu/ jaunty main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty universe
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty universe
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates universe
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu jaunty partner
# deb-src http://archive.canonical.com/ubuntu jaunty partner

deb http://security.ubuntu.com/ubuntu jaunty-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jaunty-security main restricted
deb http://security.ubuntu.com/ubuntu jaunty-security universe
# deb-src http://security.ubuntu.com/ubuntu jaunty-security universe
deb http://security.ubuntu.com/ubuntu jaunty-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jaunty-security multiverse
# ============================================================================
# latest (beta versions) versions:
# deb http://ppa.launchpad.net/fta/ubuntu intrepid main

# http://medibuntu.org/
# sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list --output-document=/etc/apt/sources.list.d/medibuntu.list
# the public key:
# sudo apt-get update && sudo apt-get install medibuntu-keyring

# ==========================================
# Google
deb http://dl.google.com/linux/deb/ stable non-free
# wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
# Or goto http://www.google.com/linuxrepositories/apt.html to download the key, then install by using synaptic

# Wine
#sudo wget http://wine.budgetdedicated.com/apt/sources.list.d/hardy.list -O /etc/apt/sources.list.d/winehq.list
# wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -

# Miro
deb http://ftp.osuosl.org/pub/pculture.org/miro/linux/repositories/ubuntu jaunty/

# =========================
# PPA
# Firefox
deb http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu jaunty main
# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 247510BE

# Banshee
deb http://ppa.launchpad.net/banshee-team/ppa/ubuntu jaunty main
# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6E80C6B7

# Openoffice
deb http://ppa.launchpad.net/openoffice-pkgs/ppa/ubuntu jaunty main
# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 247D1CFF

# Ubuntu-netbook-remix
deb http://ppa.launchpad.net/ubuntu-mobile/ppa/ubuntu jaunty main
# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C6598A30

# Ubuntu-tweak
deb http://ppa.launchpad.net/tualatrix/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/tualatrix/ppa/ubuntu jaunty main
# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E260F5B0

# for Mac users
deb http://ppa.launchpad.net/mactel-support/ppa/ubuntu jaunty main# key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2B97B7B8

# chromium
deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main
#key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E5E17B5

Wednesday, 29 October 2008

[funny]Pres. Bush endorses McCain and Palin



说话的声音,形态和招牌动作都模仿的很象,搞笑。
并且谁得到布什的支持,估计谁就没戏了。哈

Friday, 24 October 2008

中文podcast(beta): 介绍podcast

首次试录,简要介绍podcast。
用手机录的,试试效果。哈

original audio


HOWTO: convert amr ringtones or voice recording to mp3/ogg/wav

First you should decode the file to the raw format:
$ amrnb-decoder Sound1.amr Sound2.raw
which should produce something like this:
================================================== =================
TS 26.104
REL-5 V5.4.0 2004-03
REL-6 V6.1.0 2004-03
3GPP AMR Floating-point Speech Decoder
================================================== =================

Secondly, you can convert the resulting .raw file to other preferred format in Audacity.
In Audacity, using 'File->Import->Raw Data' to open the raw file by selecting 8000 as the sample rate.

Thursday, 23 October 2008

The music players for Ipod in Linux

A little bit jealous of Mac users, because those stupid people have a smart itune.
Compared with clever us, linux users, we have to confront the bloody true world.

Here are my favorite music players. So far, none of them can be called perfect.

1. Rhythmbox 0.11.6
As a 'music' player supporting podcasting, for audio ones, it works very very well, just like itune, the episodes can be marked new or old. super!
And support Chinese characters.
But it can not do the right things of video podcast transferring to ipod, even though it can play video now using visualization.

2. Banshee 1.4
Almost can do everything, including video podcast transfering to ipod, and a sync button.
But 1) not support transferring music or videos with Chinese file name correctly. Yes, you can transfer them, but when you reconnect ipod, most of the songs in ipod can not be recognized. Maybe the database in ipod is destroyed by the Chinese characters; Except everytime you re-sync your music library in ipod.
And 2) Doesn't mark the item is new or listened. (compared with Rhythmbox and amarok)

3. Songbird 1.0
Great products and ideas from mozilla. In the current 0.70 version, the synchronaztion works. (add something to tell ipod the item is video, so ipod nano 3rd gen will not see and hear any video podcasts)
And support Chinese characters.
But it has same shortcoming with firefox 1) too much memory usage, because of internal web engine embeded. 2) Without new/old marks in Ipod. Also, 3) It can not watch folders, but this feature is coming in half of year, feb 2009. 4) Very weak functionality for podcasting.

4. Amarok
Mark new or old, video podcasting and transfering, supporint Chinese characters. Only missing the sync button, but it can add the new podcast episodes to a queue, which collects all the items are waiting for transferring to ipod.
But 1) No sync button, have to manually sync each playlist, transfer episode and delete old episodes. 2) Very odd KDE interface and menu, difficult to find the right place to show what's in ipod libary and how to transfer or sync.

Penguins can fly in Linux

中文podcast(beta): zero

先放上一段英语学习的mp3来调试。很快就会有这个podcast的介绍。


original audio



Bloody correct comments on Mac and Linux(current)

Paul Murphy, noted recently,

MacOS X is the no brainer option…[it] mostly just stays out of the way of knowledgeable users. In fact, for many it meets the IT ideal: it works so well, they don’t know it’s there or doing anything to help them - they just click and expect it to work; because, well, it just does.

When Linux can do that too (and Ubuntu brings us pretty close), it makes it ever harder to justify licensing Windows. Now if the educational software vendors can just become platform agnostic, I’ll be a happy camper.

HOWTO: 使用Mutagen来修改Mp3文件的标签信息

具体方法如下(只针对GBK/GB18030编码的情况):

安装Mutagen(ubuntu下终端运行 sudo apt-get install python-mutagen)后,在终端执行:


mid3iconv -e gbk *.mp3

如果想转换当前目录下的所有 mp3 (包括子目录):

find . -iname "*.mp3" -execdir mid3iconv -e gbk {} ;

这里只介绍最常见的情况,更多信息可以查看Nicky的文章,他分析得很详细。

Wednesday, 22 October 2008

Ubuntu AD Rocks, Come on baby

http://blog.omega-research.org/uploads/2007/09/ubuntu-linux-very-friendly-circle-of-friends.jpg

HOWTO: NFS server

Install NFS Server Support
at the terminal type
sudo apt-get install nfs-kernel-server nfs-common portmap
(Optional: sudo dpkg-reconfigure portmap)
sudo /etc/init.d/portmap restart

Editing /etc/exports
the /etc/exports file is used for creating a share on the NFS server

invoke your favorite text editor or
sudo vi /etc/exports

Here are some quick examples of what you could add to your /etc/exports

For Full Read Write Permissions allowing any computer from 192.168.1.1 through 192.168.1.255

  • /files 192.168.1.1/24(rw,no_root_squash,async)
    Here /24 is netmask, meaning the netmask is 24 bits. Therefore, above line can be equivalent to:
  • /files 192.168.1.1/255.255.255.0 (rw,no_root_squash,async)
    details can be found in the reference

Or for Read Only from a single machine
  • /files 192.168.1.2 (ro,async)
save this file and then in a terminal type
sudo /etc/init.d/nfs-kernel-server restart

Also aftter making changes to /etc/exports in a terminal you must type
sudo exportfs -a

Install NFS client support
sudo apt-get install portmap nfs-common

Mounting manually
Example to mount server.mydomain.com:/files to /files. In this example server.mydomain.com is the name of the server containing the nfs share, and files is the name of the share on the nfs server

The mount point /files must first exist on the client machine.
cd /
sudo mkdir files


to mount the share from a terminal type

sudo mount server.mydomain.com:/files /files

Note you may need to restart above services:
sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-common restart


Mounting at boot using /etc/fstab
Invoke the text editor using your favorite editor, or
gksudo gedit /etc/fstab

In this example my /etc/fstab was like this:
  • server.mydomain.com:/files /files nfs rsize=8192,wsize=8192,timeo=14,intr
You could copy and paste my line, and change “servername.mydomain.com:/files”, and “/files” to match your server name:share name, and the name of the mount point you created.
It is a good idea to test this before a reboot in case a mistake was made.
type
mount /files
in a terminal, and the mount point /files will be mounted from the server.

Reference:
==========
http://www.cyberciti.biz/tips/ubuntu...nfs-share.html (for client configuration)
http://www.redhat.com/docs/manuals/l...nfs-mount.html (for mounting using fstab)
http://czarism.com/easy-peasy-ubuntu...s-file-sharing (for server configuration)
http://www.freebsd.org/doc/en_US.ISO...twork-nfs.html (contains more info about NFS)
http://www.freebsd.org/cgi/man.cgi?query=exports&sektion=5 (man for exports)
http://www.computerhope.com/jargon/n/netmask.htm (netmask /24 things)

a nice try of ubuntu linux for education in China







Tuesday, 21 October 2008

We're winning!

Image


Blogged from: http://mwcnews.net/content/view/9256/166/

Disappointed Ubuntu upgrade to 8.10 compared with Fedora 10

New features in Ubuntu 8.10:

  • Linux kernel 2.6.27
  • GNOME 2.24
  • Encrypted private directory
  • X.Org 7.4 (offering better support for keyboards, mice, and tablets)
  • Network Manager 0.7 (improved network management)
  • Dell’s DKMS (Dynamic Kernel Module Support)
  • PAM authentication
  • BBC plugin for Totem (grab free shows from the BBC)
  • Guest session support.

New features in Fedora 10:
  • AMQP Infrastructure: A technology that makes it easy to build scalable, interoperable, high-performance enterprise application
  • Appliance Tools: Tools and meta-data that make it easier for anyone (ISVs, developers, OEMS, etc) to create and deploy virtual appliances
  • Artistic 1.0 License Removal: Remove all packages licensed under only the Artistic 1.0 license before Fedora 10
  • Better Printing
  • Better Remote Support
  • Better Start-up
  • Better Webcam Support
  • Connection Sharing: Enable adhoc network sharing
  • Echo Icon Theme
  • Eclipse 3.4: Rebase Eclipse to version 3.4
  • EFI
  • Evdev Input Driver
  • Faster Startup
  • First Aid Kit: First Aid Kit is an automated recovery tool that brings together common recovery processes and applies them to a system
  • Glitch Free Audio: Rewrite the PulseAudio sound server to use timer-based audio scheduling
  • Gnome 2.24: Re-base Fedora to Gnome 2.24
  • GStreamer RPM dependencies: dependencies Assist automated installation of GStreamer codecs provided by third-party repositories
  • Kernel Modes Setting for Graphics: Move graphic mode initialization from the X server's DDX drivers to the kernel
  • NetBeans IDE: Add the NetBeans IDE to Fedora
  • Online Accounts Service: Provides applications with credentials for user's online accounts listed on online.gnome.org or stored in GConf
  • Python NSS Bindings
  • Remote Virtual Install
  • RPM 4.6
  • Save to Bugzilla: Auto create bugzilla entry with anaconda tracebacks
  • Sbin Sanity: Add /usr/local/sbin:/usr/sbin:/sbin to the PATH
  • for normal users to simplify command-line administration tasks
  • Security Audit: A new security audit system and intrusion detection system
  • Sugar Desktop: Include the Sugar Desktop (used in OLPC) in Fedora
  • Virtual Storage: Make storage provisioning over libvirt connections (local and remote) virtual machines as simple as possible.

Compared with these two major distro of linux, ubuntu is more like a service pack to me than a new release (from:http://blogs.zdnet.com/hardware/?p=2788) . While Fedora pushes it's milestone release, which will be the shipped to next version of Red Hat Enterprise Linux 6, to a new level, even though some features have existed in ubuntu or other distros, fedora got a huge improvement.

Monday, 20 October 2008

HOWTO: 昂达989+ 白屏

经过一系列的刷机,烧录和几个论坛的折腾,终于找到一条融会贯通,于其他人不太一样的解决办法。

经验说明,一旦白屏,烧录很难解决。
综合其他人的经验加本人989+白屏解决办法,总结如下:

白屏的原因并非软件,而是‘接触不良’的问题。
1.在一个高级一点的单片机论坛里看到,是因为‘虚焊’,
2.在一昂达论坛看到说有人在一个黑色芯片下垫纸解决。
3.本人则是发现用力按下方向键,反而有开机成功的机会。

综上,应该是接触不良的问题。

当把最新的固件保存到根目录下,然后用力按下屏幕中央,再按住‘向下’方向键,再开机,于是发现,可以升级固件了。于是最新固件(此时是1.25)升级成功,白屏基本没有再出现。

HOWTO: Remove Input Method(SCIM) from Right Click Menu

Type "ALT+F2" and start the "gconf-editor". Then:

desktop --> gnome --> interface

and disable

show_input_method_menu
show_unicode_menu

Sunday, 19 October 2008

HOWTO: TAB TO AUTOCOMPLETE COMMAND OPTIONS

yum install bash-completion
Now you will get the ability to use TAB to autocomplete your command and COMMAND OPTIONS.

Friday, 17 October 2008

Queen on Google




女王第二次与google‘合作’,上次是在youtuble上开设皇家频道。这次是以女王的头像的google的logo。
http://www.timesonline.co.uk/multimedia/archive/00415/google1_415407a.jpg
这个Royal Channel on YouTube 公布了 54个皇室的视频,已经被浏览160万次,如果女王自己也做一个blog的话,这个浏览量应该能给皇室带了更多的广告效益。2006年女王的演讲还被受准作为podcast发行。可见女王作为一个internet的使用者,已经走在了我们绝大多数人的前面,google以之作为logo,不足为怪。

但是在这个视频中,个人发现一点比较有趣的现象,主要负责接待的google高官,无一带领带,都是敞开西服上衣,里面衬衫领子,随意凌乱的自由状态。相比其他员工在女王来临之前的毕恭毕敬的联系打招呼,可以形成一个较为鲜明的对比。也许,这就是google的dressing code,或许,google在释放什么信息。哈。纯属个人理解。但是我还是比较喜欢这种风格,即便是面女女王这样的人物。

Google, well done.

Thursday, 16 October 2008

HOWTO: equivalent yum option to apt-get autoremove

To remove packages that has been installed as dependencies for the package you are removing if they are only needed for that particular package.

a yum plugin must be installed. Otherwise, yum doesn't provide the capability.

yum install yum-remove-with-leaves
Now yum will automatically have the same function as apt-get autoremove.

================
more:
yum-changelog is a Yum plugin for viewing package changelogs before/after updating.

Install yum-changelog via:
# yum install yum-changelog

How to use yum-changelog:
# yum update ktechlab --changelog
Loading "changelog" plugin
Loading "installonlyn" plugin
Setting up Update Process
Setting up repositories
[..]
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package ktechlab.i386 0:0.3-6.fc6 set to be updated
--> Running transaction check

Changes in packages about to be updated:

ktechlab - 0.3-6.fc6.i386
* Wed Nov 22 23:00:00 2006 Chitlesh Goorah - 0.3-6
- Rebuilt due to new gpsim-devel release

By default, this plugin will show the changelogs before the updates. However if you want to make it echo those changelogs after the updates, replace when=pre by when=post in the file /etc/yum/pluginconf.d/changelog.conf

HOWTO: yum equivalent function with apt-get

1. Find and review "lost" packages

You can find orphaned packages (ie packages not in the repositories anymore) with the tool package-cleanup from the yum-utils package: yum install yum-utils; package-cleanup --orphans.
Old packages with a failing "%postun" script will remain partly
installed. Remove them with rpm -e package-name-and-version. It's often
helpful to run this command after the update, too.

But here what 'package-cleanup --orphans' found out is the 'obsolete' ones in ubuntu words. Namely installed not from repositories.

2. Find yum install or update history

/var/log/yum.log

3. Find orphan packages
sudo package-cleanup --orphans

Note: Here 'package-cleanup' must run with sudo or su, otherwise lots of packages will be considered as orphans because of normal users don't know the relationship between packages and repositories.

Monday, 13 October 2008

HOWTO: wine fonts

Wine中对话框默认的字体是Tahoma,在我们的LINUX上,Tahoma字体是无法正常显示中文的。比如Wine configuration中的"确定""取消"等就变成了"<<"">>"的字样。

解决方法很简单:

在wine的regedit中,找到:

\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes

方法1. 直接地将这个键设为空,问题就解决了。

方法2. 将MS Shell Dlg设置为一种自己字库中已有的中文字体即可,如果已经将windows中宋体取来使用了,字库中SimSun对应宋体(这是Windows的,LINUX下默认是没有的),在这里设置为 SimSun即可。

HOWTO: find WINE menu stored in Gnome

Everything about the wine menu is stored here in a text mode, while not separately for each item.

  • .config/menus
Especially the file, 'applications.menu', a xml file, which describes the Gnome menu structure.
Every menu-edit operation on wine menu will reflected in this file.

  • .config/menus/applications-merged
The 'wine-program-*' files, xml files, are the short-cuts appears in the 'application-wine-Programs'. The rest, not appear here, will listed in the other menu.

  • ~/.local/share/applications/wine/Programs

Where the 'application-other' menu retrieve short-cuts directly from
.

Sunday, 12 October 2008

HOWTO: codecs for fedora

http://www.mplayerhq.hu/MPlayer/releases/codecs/



download "all-20071007.tar.bz2" to your desktop, then right click and
extract it now rename the folder to codecs, then open a terminal and
type



cd ~/Desktop

su

mv codecs /opt/
ln -sf /opt/codecs /usr/lib/win32
ln -sf /opt/codecs /usr/lib/codecs
ln -sf /opt/codecs /usr/local/lib/win32
ln -sf /opt/codecs /usr/local/lib/codecs


For Totem (gstreamer)
gstreamer-ffmpeg and ffmpeg is essential.
other plugins for gstreamer will be helpful.

Friday, 10 October 2008

最需要的IT技能是什么

CIO被问道:在你的IT部门内哪些技术技能最需要?(所有的被提问者(CIO们)均工作在有100名以上员工的公司;可以选择不止一项技能;是在2008年9月做的这项调查)



•    网络管理员( Network administration (LAN, WAN)): 70%

•    Wiondows管理员(Windows administration): 69%

•    桌面支持(Desktop support): 69%

•    数据库管理( Database management): 58%

•    无线网络管理( Wireless network management): 47%

•    通讯支持(Telecommunications support): 44%

•    Web开发/网站设计(Web development/Website design): 42%

•    商业情报/报告服务(Business intelligence/reporting services): 33%

•    虚拟化(Virtualization): 32%

•    .NET开发(.NET development): 22%

•    CRM 实施(CRM implementation): 22%

•    ERP 实施(ERP implementation): 20%

•    Linux/Unix 管理员(Linux/Unix administration): 20%

•    Java开发(Java development): 17%

•    开源开发(Open source development): 17%

•    XML 开发(XML development): 17%

Bill Gates on The Daily Show With Jon Stewart



HOWTO: Gnome下节省系统资源的输入中文方式

最简单的方式输入中文就是在System-Administration-Language Support里选中'enable support to enter complex characters'.但是这样会使得scim的进程一直在后台占用一定的内存,不太‘干净’。

1。每次都是在gnome的popup menu里选择input methods-scim又太过麻烦

2。在~/.profile最后加上(出自man scim)
GTK_IM_MODULE="scim"
export GTK_IM_MODULE
这样开机会自动启动scim但是可以方便的通过右键点击图标去关闭;如果想在输入中文,只要随便打开gnome的程序,scim会自动跟着打开,关闭gnome程序,scim也会跟着自动关闭。如此可以在不需要输入中文的时候,节省些系统资源。

此种方式的输入法是全局的(global),在所有运行的程序中都可以直接输入中文。

3。在~/.bashrc最后加上(出自man scim)
GTK_IM_MODULE="scim"
export GTK_IM_MODULE
每次要输入中文,要通过terminal去启动相应gnome程序,否则通过点击快捷图标,不会启动scim。

但是如果要在fedora下,须在这两条命令前执行以下命令,否则输入法会随着login自动启动(ubuntu的.bashrc已经自带此命令)
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

此种方式的输入法只是针对相应的运行的程序(session),只有在这一个程序内可以直接输入中文。(recommended)

Wednesday, 8 October 2008

hp m2000 拆解图

2005年秋季,罗钧同学托人从苏州帮我带到新加坡,3年过去了,我还没毕业,(经抢救无效)它先挂了。









Monday, 6 October 2008

HOWTO: podcast a audio in blog

here we explore some new Flash MP3 players from Google and Yahoo!
that are again light-weight, easy to implement and extremely efficient.

1. Google Reader MP3 Player


Google Reader has an inbuilt MP3 player that is pretty much the same
as Gmail player but it also works on non-Google websites. This player
has volume controls, no Google branding and it auto-detects the
duration of the music file so your readers know how long the song will
last. Here’s a live example followed by the HTML embed code:



To use this MP3 player on your website or blog, copy-paste the
following code and replace the MP3_FILE_URL with the link to your MP3
file.


<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=MP3_FILE_URL"
width="400" height="27" allowscriptaccess="never" quality="best"
bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />


2. Yahoo! MP3 Player


If you think normal is boring, check this out. Yahoo! offer a code generator (Easy Listener) to help you create a Flash based MP3 player that matches your website color theme and layout. See example:




Though this Easy Listener MP3 player requires you to pass the
address of the web page that contains the MP3 file(s), you can directly
pass the MP3 link and it will work just fine. Supports auto play and
you can decide where the meta data associated with the MP3 file should
be displayed.


<embed src="http://webjay.org/flash/dark_player" width="400" height="40" wmode="transparent" flashVars="playlist_url=MP3_FILE_URL&skin_color_1=-145,-89,-4,5&skin_color_2=-141,20,0,0" type="application/x-shockwave-flash" />


3. Yahoo! Media Player


If you maintain an MP3 blog or run a podcast and regularly link to
MP3 files, it makes little sense to embed a separate Flash player with
every MP3 file. I would therefore recommend using the Yahoo! Media Player that auto-detects links to MP3 files in your web pages and creates an embedded player for each link.


All you have to do is insert the following link in your blog
template and all MP3 hyperlinks will be converted into inline MP3
players. This also has the shuffle feature and visitors can easily skip
to any song in the playlist. Excellent stuff.


<script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>


4. Odeo MP3 Player


Odeo offers a pretty impressive MP3 player (see example)
that works perfect in web pages as well as RSS readers but a small
issue is that Odeo Player requires you to type the exact duration of
the song in the embed code. You can skip this step but then the
progress bar won’t reflect the true status when you play the
song. And there are no volume controls.




To use Odeo MP3 player in your website, add the following code replacing MP3_FILE_URL and DURATION with relevant values.

<embed src= "http://www.odeo.com/flash/audio_player_standard_gray.swf" quality="high" width="300" height="52" allowScriptAccess="always" wmode="transparent"  type="application/x-shockwave-flash" flashvars= "valid_sample_rate=true&external_url=[MP3 file address]" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed>


Summary: With so many choices, how do you pick the right MP3 player for your website ?

Saturday, 4 October 2008

HOWTO: use the "label:" query word to search in Gmail

how to use the "label:" query word to search for Multi-Labeled messages
as well as Un-Labeled messages. Thanks to "rishid" on the GmailForums
for submitting this tip...



Say you want to find messages that have multiple Labels. For example,
you want to display all messages with label1, label2 and label3 that
you had previously defined and assigned. Into the basic search field at
the top of any Gmail page, you would enter label:label1 label:label2
label:label3



Note that this is searching for all messages that have label1 AND
label2 AND label3. If you want to include messages that have ANY of
those labels, you can use the "OR" command like this: label:label1 OR
label:label2 OR label:label3 (Note: "OR" must be in uppercase.)



You can optionally add a "-" to the query words to exclude search
criteria. For example, entering -label:label1 label:label2 label:label3
would return all messages that have label 2 AND label 3, but do not
have a label1 Label.



Taking this concept a step further, you can use this method to search
for all "Un-Labeled" messages. Unfortunatly, Gmail does not provide a
choice in the search dropdown that lets you search for unlabeled
messages. If you manage a large number of messages, it can be very
cumbersome to determine which messages are unlabeled. My personal
preference is to ensure that all messages have a Label making it easier
to manage and organize them.



So, if you want to list all unlabeled messages, just create a long
search string containing every label that you have defined. Be sure to
include the "-" character in front of every label. This ensures that
messages with these labels will be EXCLUDED (remember, you are looking
for all messages WITHOUT Labels.) You can also optionally include the
hidden "inbox" Label to exclude anything in your Inbox.



For example, if you have defined the Labels "Family", "Friends",
"Ebay", and "Support", you would enter the following string into the
search field (note that the labels are not case sensitive) to find all
Unlabeled messaegs:



-label:inbox -label:family -label:friends -label:ebay -label:support



If you have a large number of labels, obviously, this becomes harder
and harder to manage, so I recommend reating a "note" email to yourself
containing the search string for easy future reference.

Thursday, 2 October 2008

HOWTO: Find which Debian or ubuntu Linux Version you are running

Find or identify which version of Debian Linux you are running

This can be checked in

/etc/debian_version file


Find or identify which version of ubuntu Linux you are running

You can find in different ways in ubuntu

Solution 1

cat /etc/issue

The file /etc/issue holds the version of Ubuntu installed on your system

Solution 2

lsb_release -a

or

cat /etc/lsb-release


Where lsb for Linux Standard Base

鹤吃兔(regent park版)

周日,阳光明媚,万里无云,秋高气爽,自己的用词使我回想起国内这个时候该开中小学运动会了。

我和珊珊一起去了regent park,并拍了以下一些照片。





1.看到湖边居然有鹤。看惯了鸭子和鸽子,看到鹤觉得挺稀罕的,立刻合影留念。


http://blufiles.storage.live.com/y1phZeaaJYArJlgpGXhk7GJFJjO_OjyLX5xmsqlit2IhzeW60soXCarEDqvri6-7HXJ





2.虽说镜头28-105不济,但是也够安全的拍个特写了。


http://blufiles.storage.live.com/y1pxoO6NVqzsDZZBxgzhZmBHLsyIhKm08M3TPt7CcQs4ktA39tRDm86nZs-ge8vgBV9





3.不知道古人怎么会想到‘鹤立鸡群’,明明该是鸭群吗。


http://blufiles.storage.live.com/y1pCfB0qh_7aU4-CG_X59vKhYX2xMBFlMq95KxzM-gJYXVtygovBw0rQjQJSyt3G83e





4.飞了,仍旧是帅的一塌糊涂。


http://blufiles.storage.live.com/y1pPZ39H80z00pe-vH8ZGhXVgBYpOcjOGXpPs2jP9d6AImewnO08euoYnQLB2cOhSXq





5.后来被我发现,它跑到这来卖单来了,不知道它洒么啥呢。


http://blufiles.storage.live.com/y1p4cYJI_XvKMFdz4KNuYhmV7RMz9jhOMeiXZjSbafEai5wD0lqWXcMO-jeW7TAJqSz





6.原来,它要活捉个兔子。。。。


Heron eats rabbit





7.然后,可能是为了消毒,把兔子按到睡里致死


Heron eats rabbit





8.洗把干净


Heron eats rabbit





9.吞


Heron eats rabbit





10.撑的2眼发直,继续卖单。


Heron eats rabbit





我的故事讲完了。





看到这里,我得澄清一下,6-10并不是我拍的在regent park的鹤,不过也真是巧,周日公园里看到鹤,第二天早上看报纸,就看到这和鹤吃兔子的报道。于是乎,我就连在一起了,娱乐一下。哈。







Tuesday, 30 September 2008

Heron catches rabbit: Dramatic photos

Enjoying a leisurely wade in the waters of the Dutch
undergrowth this grey heron decided to go in search of lunch when he
came across this unsuspecting black rabbit.

Undeterred by its size, the grey heron, the
largest bird of its kind in Europe, swooped down and gobbled the rabbit
up in one mouthful, as these pictures show.

Heron eats rabbit

Wildlife
photographer Ad Sprang, has specialised in bird watching for 10 years,
made the trip to Vianen, Holland, last year to get pictures of the
bird.

"I was trying to make some nice shots of this grey heron," describes the 56-year-old Dutchman.

Heron eats rabbit

After having made several shots a little rabbit suddenly appeared out of a hole in the ground.

"The heron was interested in it and slowly approached the little rabbit.

"When the heron was quite close to the rabbit you could feel the tension.

Heron eats rabbit



"The head of the bird slowly moved from the left to the right; apparently to estimate the distance."

Obviously hungry, the adult grey heron, who
average at 90-100 cm in height, with a 175-195cm wingspan and a weight
of 1.2kg, made its move.

Heron eats rabbit

"Then all of a sudden in a split second the bird caught the rabbit," said Mr Sprang.

"The rabbit screamed loudly when it was hanging helplessly in the bill of the big heron.

I managed to make two photos of this and the bird flew away with the rabbit in its bill.

The bird landed in a water-place nearby. I could quickly turn the car and took several photos of the rest of the story.

Heron eats rabbit

"The
heron tried to kill the rabbit by putting it under water. After about
half a minute the rabbit was almost dead but as it moved it was put
under water by the heron again.

"When the poor
little rabbit had finally died the heron swallowed the rabbit
completely. It was not that easy because of the size but finally the
heron was successful.

Heron eats rabbit



"I have often seen herons catching preys like mice and fish. but catching a rabbit was a surprise."

Monday, 29 September 2008

普通linux的使用者也要为Ubuntu平反!

序(更正:文首的引用是linux内核的开发人员,文末的是来自国内某版霸,谢谢有些朋友指正)
===============================
日前,一来自Greg Kroah-Hartman的抨击ubuntu的猛文在国内火速流传。我身为一个ubuntu的支持者,我实在忍受不了这种无理的栽赃与指责;而且我不希望国内潜在的大量linux爱好者受此文影响,而对ubuntu产生错误的理解。原文附于最后,便于大家理解,我一一对比阐述我对ubuntu的认识与理解。

事情是这样的:
‘9月19日,Novell公司的Linux内核开发高手Greg Kroah-Hartman在《国际Linux内核维修者》大会上,率先对Ubuntu主要支持者Canonical公司发难,指责Canonical公司对Linux内核贡献“极少”,在过去3年中,Canonical总共才提交了100个补丁程序,占此期间Linux内核补丁程序总数的0.1%。由此,Greg的真正意思是说:Ubuntu对“Linux生态系统”的贡献“极小”。这一非常怪异的说法和看问题的立场和视角,立即遭到业界相关人士的猛烈反击。’
来源: CU的Linux论坛。


我一个ubuntu的使用者和支持者的切身体会
===============================
1。针对所谓‘贡献’
Linux是一个开放,开源的系统;如果大家有过sourceforge.net上的浏览或者参与经历,都会了解到,开源社区需要大家都出一分力,正所谓人人为我,我为人人,但是不是每个人都是有足够时间,精力和实力去做最最核心的开发代码的工作,还有很多工作,比如翻译,发现bug或者是传播开源文化(具体的理解清参看IBM的linux广告,唯一一个让我看了后会很感动的广告:http://www.youtube.com/watch?v=EwL0G9wK8j4)。
所以在这一点上,最大的两家linux开发公司red hat(redhat和fedora)和novell(suse和opensuse)他们确实为了linux的内核做出了卓越的工作,但是即便是ubuntu内核工作的做的少,但是ubuntu不遗余力的推广和普及工作,做这些工作的就要遭到抨击?那我们普通使用者要怎样参与这个开源的项目呢?!如果我们不做内核开发工作,就要挨骂,这将据所有人于千里之外,逼大家回到windows的世界里,难道这是这个novell的内核专家想看到的?这是他在为linux做贡献吗?其居心不可谓不叵测啊。

2。针对所谓‘胡乱篡改代码’
open source的初衷就是让大家学习其代码,并发布自己定制的系统和大家共同探讨学习以及享受到不同定制的便利,而摆脱microsoft提供的桎梏,发挥人类的想象力和创造力,而不是为几个公司,几个开发者所左右我们人类的思维;而且上百个linux的版本,都是基于那么3,4个版本修改并开发而来,从这一点上,ubuntu修改debian有什么错?!而且ubuntu里面最原始的安装,根本不带任何商业软件,完全的开源与免费,为何这要受到一些人的诟病?
这个novell的内核专家是为suse这个系统工作;但是不要忘记suese早年也是2个德国人现从翻译并传播redhat的rpm系统,而最终自立门户,后又卖身给美国的novell而发展起来的;现在你们羽翼丰满了,又龌龊的与微软签订了一些不伦不类的契约,受了大笔的钱后,反倒回过头来指责另外一个给他带来竞争力的公司。而且,要说修改的很夸张的,我觉得linux的所有软件里最特殊的并孤立其他版本的莫过于suse的yast,不能否认其功能之强大,但是完全是一个傻瓜系统,如果你用惯了这个系统,你就会变成一个linux的白痴,一旦没有了这个yast,所有设置你都不会做,估计连terminal是干嘛的可能都不知道(正像许多使用apple的mac的人)。从这一点上来说,真正改变linux的标准的是novell的suse系统,而他们有名的内核专家却开口以此为理由指责一个只是完善可用性的ubuntu,其居心不可谓不小人啊。

3。针对所谓‘制造麻烦,卖服务’
个人学习linux的经验,从早期的redhat,到fedora(1-9),再从suse到opensuse,一直是麻烦不断,硬件支持很差,效率很低。真正享受到了linux提供的便利,强大和高效的工作效率是从ubuntu开始的。Ubuntu也不指一次的被评为兼容性最好的linux发行版;是真正的为了初学者敞开了一扇通往学习linxu的大门;并且对linux社区有大概了解的人都知道,ubuntu的社区是规模最大的,并且ubuntu还提供相关的brainstorm(专门的一个网站,让大家提出尽可能多的想法和建议,这是一个普通用户和开发者联系的纽带)和launchpad(普通用户提交bug的非常强大的管理系统),看看这些,就会知道,ubuntu怎么会所谓的‘故意制造困难,然后让用户买服务’。相比之下看看这位指责者开发的suse系统吧,用户社区逐年缩水,并且由于历史原因,suse来源德国,有大量老牌开发者都是来自德国,suse维护了这样大量的德语社区,这就使得世界上其他语言的使用者很难找到最权威的帮助和开发文档。并且suse也宣称过,最近几年内不会进入桌面系统领域。这样一个只知道做商业用途的开发系统,有什么资格来说ubuntu是在故意给用户制造麻烦。

4。针对所谓‘商业利益‘
Redhat和novell为何拥有企业版的Red Hat enterprise linux和SUSE,免费的fedora和opensuse?其实显然,后者是给普通用户使用的,以普通用户为小白鼠来完善他们的企业版,这种不惜牺牲普通用户的做法正是他们能够提供高质量的企业版的原因;并且,针对linux的一些不完善,这两家公司也都先后宣布暂不大力度投入桌面用户领域,这实际也就是说,普通用户对于他们完全是无足轻重的,钱途才是最最重要的。而相比之下,ubuntu填补这个空缺,仅以130个员工的实力去完全为普通用户提供完善的桌面系统,并先后开发出针对mobile设备,超便携电脑(umpc)的不同版本系统,而且ubuntu的服务器版本完全就是整个ubuntu软件库里的一部分软件的组合,也就是说企业版和个人版都是一样的,只是选择的软件包不一样而已。从道义上讲,这为开发者服务的suse系统是无法和一个把普通用户和企业级用户视为同等地位的ubuntu相提并论的,真正为了‘商业利益’的,就是他们自己,结果倒反咬他人一口。

总之
ubuntu对开源社区,对linux所作的贡献不能只以对内核贡献来衡量;它对linux的代码的完善做了卓有成效的贡献,使得大家不再像以往fedora和opensuse提供给大家的垃圾系统,用户是在没完没了的找解决问题的方法,而无从谈及工作效率,ubuntu真正把linux变成了一个工具给人类使用;ubuntu提供了最广泛的社区支持,这也是它能鹤立鸡群的原因,他是真正为用户考虑,并创立了独有的商业模式,而不是像suse那样的牺牲普通用户利益而达成自己的商业利益的开发版本。

ubuntu是for human being的意思,ubuntu这个系统当之无愧,最早的支持者就是南非为了人类自由而致力的曼得拉。而suse呢?!

我个人不喜欢看到这种互相指桑骂槐的事情在linux和开源领域发生,这毕竟是一个崇高的项目,不该像apple那样萎缩的演出一幕幕'i'm mac, i'm pc'的无聊的互相挖苦无聊的掐架(在这一点上微软要比apple正人君子多了)。当时,red hat和novell都宣布暂不致力个人桌民系统领域,这真的让很多linux的用户感到痛心,毕竟如果失去这种竞争,很多优秀的创意的可能就不会出现了,同样很多人在争执kde和gnome哪个更好,相信,当有一天真的一方落败并消失的时候,遭受损失的是我们每一个人,而不是某一个单独的阵营。大家应该致力把整个社区,甚至是整个人类学习工作的平台做的更好,让不同的理念和想法自由发展;而非这位大名鼎鼎的内核开发者这般无理的指责。

希望更多潜在的或者是已经在使用ubuntu的用户不要因为这位开发者的言论蒙骗。

原文翻译如下:
===============================
Ubuntu根本就是个祸害开源社区发行版。资本家是“无利不起早”的。“新人用Ubuntu系列是最不明智的选择,因为很难利用到别人的经验。Ubuntu修改了太多东西造就了和其它发行版的不兼容。
“Ubuntu通过大量散发免费光盘圈走很大一部分初级用户,这部分用户自行解决问题能力相对较差,当遇到问题而又因为系统和别人不兼容而无法获得别人帮助时,最终将屈服于Ubuntu而购买Ubuntu的服务。

“ 这种称作糖衣炮弹的诈骗手段古往今来屡试不爽。实际上微软也这样,只不过微软是通过放纵盗版来圈客户,并且微软的Windows好歹还有很大一部分是它自己编的;Ubuntu则明着圈初学者,并且利用的工具也基本上不是它自己的,而是GNU/Linux。”(按:在以上大字报贴出一年后,Ubuntu果然提供了比买Windows Vista还贵的收费服务。)

由于Ubuntu直接抄袭Debian的特色内容,所以有的网友称Ubuntu为“番茄花园版的Debian”。这个系列的发行版以标新立异为荣,轻率修改关键代码,对用户极不负责。例如对随机数发生器的非官方修改导致openssl密钥容易重复,直到现在Ubuntu还在不断追加black list,让其用户苦受倒悬之危。

Ubuntu区别于其它大多数发行版的另一显著特征就是临近版本之间改动极大。经常有人抱怨:“我的Ubuntu升级后不能启动了。”(例如7.04版升级到7.10时,很多用户无法进入X Window.)

同时Ubuntu为了进一步增加用户的麻烦,用dash取代了bash,带来繁多的兼容问题。不幸的是,在其自身的论坛上,Ubuntu被证实在一些只兼容dash的脚本开头使用了#!/bin/sh而不是#!/bin/dash,从而自掘坟墓,损人害己。由此可见Ubuntu本身就不是一个严肃的产品,不适合作为操作系统使用。

只有让用户经常遇到麻烦,为Ubuntu提供服务的公司才能最大限度地赚钱。要多赚钱,不但要让每个用户多使用服务,还要扩大用户群。这就要从Windows世界不择手段地拉拢用户。

Ubuntu为了讨好Windows用户不惜东施效颦。作出了一些破坏*nix惯例的修改,例如学习Windows的Program Files目录,将不同软件装到各自的目录而不是分散在统一目录结构中,导致类似gtkConfig失效等Ubuntu特有问题。

综上所述,Ubuntu完全就是一个用砸钱的办法耧取商业利益同时祸害自由软件社区的发行版。一般人无论是从自身利益还是从社会责任考虑都不应该主动使用Ubuntu。

what our galaxy looks like

Interestingly, on a true vertical log plot, I think the Eiffel Tower's sides really would be straight lines.

Sunday, 21 September 2008

HOWTO: fstab backup

# /etc/fstab: static file system information.
#
#              
proc            /proc           proc    defaults        0       0
# /dev/sda5
UUID=ac407051-9b61-4cdf-8ee5-931ee60ca142 /               ext3    relatime,errors=remount-ro 0       1
# /dev/sda2
UUID=a1c7cec0-e0ce-428d-b358-9a28121c78ab /boot           ext3    relatime        0       2
# /dev/sda8
UUID=c2fdb6c9-c9c3-4f2c-8415-f0a447dcadd3 /home           ext3    relatime        0       2
# /dev/sda7
UUID=c6222043-d2dc-4c2c-9d28-7048164a3fbe /usr/local      ext3    relatime        0       2
# /dev/sda6
UUID=b377178f-e7b5-4c44-8f20-39befffb85a5 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0


# my ntfs partitions
/dev/sda4    /home/Personal    ntfs-3g    default    0    0
/dev/sda1    /home/Win_C    ntfs-3g    default    0    0

Thursday, 18 September 2008

HOWTO: find out 'orphaned' packages

1. Enable the Extra Repos (http://ubuntuguide.org/#extrarepositories)



2. Install deborphan

$ sudo apt-get install deborphan

3. Open Synaptic and click the 'Custom' button in the lower-left corner.

You should already see sections such as 'Broken' and 'Marked Changes'.



4. From Synaptic's main menu choose Settings > Filters

It should look similar to this:





http://img.photobucket.com/albums/v469/camplear/forums/synaptic70b.png





5. Click on the 'New' button.

In the Dialogue box type in 'Orphaned' in place of 'New Filter 1'

This will name the filter (choose any name you prefer).



6. Click the 'Deselect All' box then tick the 'Orphaned' box.

It should look similar to this:





http://img.photobucket.com/albums/v469/camplear/forums/synaptic71b.png





7. Click 'Okay'



8. Highlight the 'Orphaned' option and view the selected packages.

Choose any/all of them and 'Mark For Removal' with right-click.





It should look similar to this:





http://img.photobucket.com/albums/v469/camplear/forums/synaptic72b.png

这波经济危机让我赶上了,撤离Canary Wharf吧。

撤离Canary Wharf。

You’ve packed up your desk at Lehman Brothers, rolled up that AIG umbrella and headed to the pub. But wait, there is still hope!




一切都这么迅速。
  • 上周末放出消息lehman brothers要倒。
  • 周一证实。
  • 周二与其密切合作的,尤其是次贷(不太懂这个词,不过就像牙疼,平时看着小事,发威时能整死人那种)方面的Halifax一开盘股票狂跌1/3。
  • 周三继续跌,最大到达40%,这时Lloyds TSB(这个老气横秋的银行)出来趁火打劫,并双方进行高端收购会谈,这时Halifax股票小规模回升,而Lloyds TSB净增长2%。当然Halifax的颓势不如Lehman Brothers那么迅速和夸张:曾经在美国抵押贷款债券业务上连续40年独占鳌头的雷曼兄弟,过去一周内股价暴跌77%,公司市值从112亿美元大幅缩水至25亿美元。公司股价一年内已下跌了近95%。
  • 周四,收购达成,英国政府力挺。这时Lloyds TSB股票已涨了58%。

本来,最近半年Halifax成了我的新宠,Debit Card和Credit card都转了过去,高利息,还很多overdraft免费免息的政策,实在讨人喜欢;而Lloyds TSB对overdraft的收费那叫一恨,我就看不过这种斤斤计较的公司,才彻底放弃他们。结果这么快就成了这个下场。

看到正式收购消息,再打开一次halifax的网页吧,过不了多久就变样了。哎。


Tuesday, 16 September 2008

男士对付车上的泼妇的好方法

    一天在公交车上,由于拥挤一男一女发生了碰撞。
  时髦女郎回头飞眼道:“你有病啊?”
  男子觉得莫名其妙回道:“你有药吗?”
  车上人窃笑!
  女子觉得生气回道:“你有精神病啊?”
  男子冷面对道:“你能治啊?”
  全车人爆笑!
  公交司机停车,趴在方向盘上大笑!
 这是珠江路上上班的朋友遇见的
   公交车上超挤,有一女人站在门口,
  从车后面挤过来一个GG要下车,
  跟那女的说了一句“让一下,下车”,那个女滴木有动。
  GG挤过去时就踩到她了。
  结果那女人好厉害的,不停的骂“神经病啊你!神经病啊你!~~”,还超大声,搞得全车都看呀。
  GG一直木有说话,下车时忍不了了,回头对那女人说,“复读机呀你!”
  全车人暴笑~!
  后边有几个搞笑的小孩,不停的伴演刚才的一幕,
  甲说“你神经病呀你!。。。。。乙说“你复读机呀你”。。。。。。
  全车人暴笑~!
  后来,有个小MM也要下车,挤过去怯怯滴说“偶~偶~偶想下去,偶不是神经病~!”
  全车人再次暴笑~!
  那个女人木有说话,可是从边上飘来一句话“你是不是没电了”
  全车人暴笑不止~!

Monday, 8 September 2008

howto: format SD cards

To check the mounted usb device:

sudo fdisk -l

Umount it:
sudo umount /media/disk
Format it:
sudo mkfs.vfat /dev/sdc1

Friday, 5 September 2008

Telephone Alphabet

a for apple/alpha
B for (Bravo)
c for charlie
d for david/DELTA
E for Echo
F for (FOXTROT)
G for golf
h for hotel
I for India
J for Juliet
K for Kilo
L for (LIMA)
M for Mike
N for November
o for oscar
p for peter/pub/Papa
Q for (Quebec)
R for Romeo
S for (Sierra)
t for tom/Tango
U for uniform
V for Victor
W for Whiskey
X for x-ray
y for yankee
z for (Zulu)

Wednesday, 3 September 2008

Howto: conky

My content of .conkyrc:

=============================
background yes
font Zekton:size=7
xftfont Zekton:size=7
use_xft yes
xftalpha 0.1
update_interval 2.0
total_run_times 0
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
minimum_size 220 5
maximum_width 220
default_color d7d7d7
default_shade_color black
default_outline_color black
alignment bottom_right
gap_x 10
gap_y 10
no_buffers yes
cpu_avg_samples 2
override_utf8_locale no
uppercase no # set to yes if you want all text to be in uppercase
use_spacer no

TEXT
${font Zekton:style=Bold:pixelsize=42}${alignc}${time %H:%M:%S}${font Zekton:size=7}
SYSTEM ${hr 1 }

Hostname: $alignr$nodename
Kernel: $alignr$kernel
Uptime: $alignr$uptime
Processes: ${alignr}$processes ($running_processes running)
Load: ${alignr}$loadavg
Battery ${battery_time BAT0} ${alignr}(${battery BAT0})
${battery_bar 4 BAT0}

FILESYSTEM ${hr 1}${color}

Root: ${alignr}${fs_free /} / ${fs_size /}
${fs_bar 4 /}
Home: ${alignr}${fs_free /home} / ${fs_size /home}
${fs_bar 4 /}

NETWORK ${hr 1}${color}

Down ${downspeed eth1} k/s ${alignr}Up ${upspeed eth1} k/s
${downspeedgraph eth1 25,107} ${alignr}${upspeedgraph eth1 25,107}
Total ${totaldown eth1} ${alignr}Total ${totalup eth1}

SYSTEM RESOURCE ${hr 1}${color}

Highest CPU $alignr CPU% MEM%
${top name 1}$alignr${top cpu 1}${top mem 1}
${top name 2}$alignr${top cpu 2}${top mem 2}
${top name 3}$alignr${top cpu 3}${top mem 3}

Highest MEM $alignr CPU% MEM%
${top_mem name 1}$alignr${top_mem cpu 1} ${top_mem mem_res 1}
${top_mem name 2}$alignr${top_mem cpu 2} ${top_mem mem_res 2}
${top_mem name 3}$alignr${top_mem cpu 3} ${top_mem mem_res 3}

CPU ${alignc} ${freq}MHz / ${acpitemp}C ${alignr}(${cpu cpu1}%)
${cpubar 4 cpu1}
${cpugraph}
RAM ${alignr}$mem / $memmax ($memperc%)
${memgraph}

=============================
or: using 'mem_res' instead of 'mem', which is percentage
${top_mem name 1} ${top_mem cpu 1}$alignr${top_mem mem_res 1}

Monday, 1 September 2008

Hifi, too many stuff want to buy

《视听技术》2005年音响排名
进口音箱:
(1) 英国B&W:http://www.bowers-wilkins.co.uk/
(2) 丹麦Dynaudio:http://www.dynaudio.com/
(3) 丹麦Jamo:http://www.jamo.com/
(4) 德国ELAC:http://www.elac.com/en/index.html
(5) 英国KEF:http://www.kef.com/
(6) 英国AE:http://www.acoustic-energy.co.uk/
(7) 丹麦AVANCE(皇冠)
(8) 意大利世霸:http://www.sonusfaber.com/eng/home.html
(9) 美国JBL
(10) 英国tannoy:http://www.tannoy-speakers.com/

国产音箱:
(1) 惠威
(2) 惠普
(3) 金琅
(4) 博良
(5) 杰作
(6) 君悦
(7) 美之声
(8) 何氏
(9) 原音
(10) 唐颂。

进口功放:
(1) 日本马兰士
(2) 日本天龙
(3) 英国音乐传真
(4) 日本安桥
(5) 美国麦景图
(6) 英国美丽安
(7) 英国雅骏
(8) 挪威音乐之旅
(9) 日本雅马哈
(10) 日本金嗓子。

国产功放:
(1) 钟神
(2) 八达
(3) 斯巴克
(4) 山灵
(5) 风之声
(6) 新德克
(7) 声雅
(8) 天逸
(9) 柯颂
(10) 琴谱。

进口家庭影院:
(1) 日本天龙
(2) 丹麦尊宝
(3) 日本安桥
(4) 英国KEF
(5) 德国意力。

国产家庭影院:
(1) 惠威、
(2) 爱浪
(3) 惠普
(4) CAV
(5) 风之声。

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter