星期日, 十一月 30, 2008

tips

1:安装完Ubuntu之后,要能通过putty即ssh访问的话,需要额外安装ssh。
sudu apt-get install openssh-server
2:熟悉的/etc/inittab文件在Ubuntu中,默认不存在,使用基于事件的启动进程upstart代替原来的传统的System V 的 init daemon (Sysvinit),原因在于Sysvinit无法很好地处理现代硬件,如热插拔设备、USB硬盘或山村、网络文件系统等。
cd /usr/share/doc/upstart/
gunzip -c README.Debian.gz
但是Ubuntu仍兼容Sysvinit。
vi /etc/event.d/rc-default 
3:如果想启动直接进入字符界面的话:
sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf
sudo update-rc.d -n -f gdm remove
sudo update-rc.d -n gdm start 2 3 4 5 . stop 0 1 6 .
注意:sysv-rc-conf运行后在选项中寻找到2列 对于的gdm项,去掉选择gdm即可。
当你重新启动ubuntu之后进入了字符界面之后,又想回到图形环境不是用startx命令,而是
telinit 3

星期五, 十月 24, 2008

MYSQL --Repair Tables

http://dev.mysql.com/doc/refman/5.0/en/repair.html

Symptoms of corrupted tables include queries that abort unexpectedly and observable errors such as these:

  • tbl_name.frm is locked against change

  • Can't find file tbl_name.MYI (Errcode: nnn)

  • Unexpected end of file

  • Record file is crashed

  • Got error nnn from table handler

To get more information about the error, run perror nnn, where nnn is the error number.


perror - describes a system or MySQL error code. 

Can  be  used  to  display a description for a system error code, or an MyISAM/ISAM table handler error code. The  error  messages  are  mostly system dependent

星期三, 十月 01, 2008

linux下 ls -l返回结果的处理正规表达式

sub print_file {

    my($ftp, $dir) = @_;

    my @files = $ftp->dir()

        or warn "Can't LIST: ", $ftp->message;

    return unless @files;

 

    print "into $dir¥n";

 

    for (@files) {

        s/¥r//g;

        s/¥n//g;

        if (/

            ^

            (.|-)                   # (1) type

            (.{9})                  # (2) permittion

            ¥s+

            (¥d+)                   # (3) links

            ¥s+

            (¥w+)                   # (4) owner

            ¥s+

            (¥w+)                   # (5) group

            ¥s+

            (¥d+)                   # (6) size           

            ¥s+

            (¥w{3}¥s+¥d+¥s+¥d+:¥d+) # (7) date

            ¥s+

            (.*?)                   # (8) filename

            (?:¥s+->¥s+(.*))?       # (9) link

            $

            /x)

        {

            print "$dir/$8  $6  $7";

            if ($1 eq 'd') {

                my $next_dir = File::Spec->catfile($dir, $8);

                $ftp->cwd($8);

                &print_file($tree, $ftp, $next_dir);

                $ftp->cdup();

            }

        }

    }

}

Perl FTP 相关module


Net::FTP::File - Perl extension for simplifying FTP file operations


Net::xFTP - Common wrapper functions for use with either Net::FTP or Net::xFTP


星期四, 九月 25, 2008

Linux下编译带CJK文字的Java文件

直接编译很可能出错,指定encoding也有出错的可能性。
去掉LANG环境变量,却又意外惊喜,虽然不知道具体原因。

export LANG=
javac -classpath=A:B xxxx.java

iText

keywords:

Document is the object to which you’ll add content: the document data and meta-data.
Upon creating the Document object, you can define the page size, the page color, and the margins of the first page of your PDF document.

By default, a user unit corresponds with the typographic unit of measurement known as the point.
1 in = 2.54 cm = 72 points

When a document object is opened,  a lot of initializations take place in iText.
If you use the parameterless Document constructor and you want to change page size and margins with the corresponding setter methods, it’s important to do this before opening the document. Otherwise the default page size and margins will be used for the first page, and your page settings will only be taken into account starting from the second page.
That’s why you should always set the PDF version and add the metadata before opening the document.

When document.open() is invoked, the iText DocWriter starts writing its first bytes to the OutputStream. In the case of PdfWriter, a PDF header is written, and by default it looks like this:

%PDF-1.4
%âãÏÓ


adding content to the PDF document . There are three ways to do this:
    a:The easy way—Using iText’s basic building blocks
                        document.add(new Paragraph("Hello World"));

    b:As a PDF expert—Using iText methods that correspond with PDF operators and operands
                        PdfContentByte cb = writer.getDirectContent();
                        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                        BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        cb.saveState(); // q
                        cb.beginText(); // BT
                        cb.moveText(36, 806); // 36 806 Td
                        cb.moveText(0, -18); // 0 -18 Td
                        cb.setFontAndSize(bf, 12); // /F1 12 Tf
                        cb.showText("Hello World"); // (Hello World)Tj
                        cb.endText(); // ET
                        cb.restoreState(); // Q
    c:As a Java expert—Using Graphics2D methods and the paint method in Swing components
                        PdfContentByte cb = writer.getDirectContent();
                  Graphics2D graphics2D = cb.createGraphics(PageSize.A4.getWidth(),
                                                             PageSize.A4.getHeight());
                  graphics2D.drawString("Hello World", 36, 54);
                  graphics2D.dispose();
      (attention:On UNIX systems, may encounter X11 problems that prompt this error message: Can’t connect to X11 window server using xyz as the value of the DISPLAY variable. You can work around this issue by running the AWT in headless mode by starting the Java Virtual Machine (JVM) with the parameter java.awt.headless=true. Another solution is to run an X server. If you don’t need to display anything, a virtual X11 server will do.)


星期一, 九月 08, 2008

Compiling Software

1: How to compile
Software that comes in source form is often made available as a tarball-that is, it is archived into a single large file and then compressed with tar and gzip or bzip2, which often end in .tar.gz or .tar.bz2 or .tgz(contraction of .tar and .gz)

tar -xvzf kdirstat-2.2.0.tgz
tar -xvjf kdirstat-2.2.0.tar.bz2

To get a quick list of all the directories in a source tree
ls -l | grep drwx

To see what configure options come with a package
./configure --help

./configure

make (echo $PATH)

make install


the KDirStat executable is installed by default in /usr/local/kde/bin



2:How to run
<1>Running with Path Information
/usr/local/kde/bin/kdirstat

<2>Adding the Executable Directory to the Path
To make change during the current login session
export PATH = $PATH:/usr/local/kde/bin

To make the path change persist
~/.bash_profile

To make the path alteration system-wide
/etc/profile

<3>Linking to the Executable
ln -s /usr/local/kde/bin/kdirstat /usr/local/bin



3:Cleaning Up
make clean
OR
rm -rf kdirstat-2.2.0

RPM

1: Installing a New Package
rpm -ivh --force --nodeps packagename.rpm


2: Querying a Package
rpm -qa | grep -i 'name'

To find out which package a particular file belongs to
rpm -qf /dir/file

To find out the purpose of a package that is already installed
rpm -qi packagename

To find out what files are contained in a package
rpm -ql packagename

To identify information about and a list of files included in an uninstalled package
rpm -qilp packagename


3:Uninstalling a Package
rpm -e packagename


在线资料



System Management Tool
1:Webmin
http://yourservername:10000
Set the yourservername to be the name of the server as described by the Webmin installation message


2:redhat-config-packages


3:APT  non-RPM package manager used in other  distribution like Debian and Ubuntu
    Please note that these apt pages are obsolete. They were written in the days when yum didn't yet exist, when apt was the only decent dependency tool for rpm around. This has changed, you should really prefer yum over apt for rpm which is now unmaintained.
     <1>:Go to the http://freshrpms.net/apt/ to download the rpm package
     <2>:rpm -ivh
     <3>:apt-get update
     <4>:apt-get -f install
     <5>:apt-get install synaptic(Download an apt GUI manager) 

星期四, 九月 04, 2008

PHP の mbstring に関するメモ

http://www.asahi-net.or.jp/~wv7y-kmr/memo/php_mbstring.html

星期三, 四月 09, 2008

Perl で、BASIC 認証付きのサイトにアクセスするには?

#!/usr/bin/perl

use LWP::UserAgent;

our $HOME_URL = 'ユーザー名とパスワード付きの URL';
our $USERNAME = '上記 URL にアクセスするためのユーザー名';
our $PASSWORD = '上記 URL にアクセスするためのパスワード';

$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => $HOME_URL);
$req->authorization_basic($USERNAME, $PASSWORD);

print $ua->request($req)->as_string;

1;



星期二, 二月 26, 2008

MySQL的LOCAL DATA INFILE命令

用户需要纪录数据库中记录的变更历史,使用update-log的话,精度太大。使用触发器的话,现行的版本(MySQL 4.0.20)又不支持。只能手动来干。

1. 每天午夜从数据库中取快照
mysqldump -unobody -pnobody
--opt
--skip-add-drop-table --skip-extended-insert --skip-add-locks
--skip-disable-keys --skip-comments
--quote-names $dbname $table_name > $dumpfile_name

2. 取出来的快照和前一天的快照进行比较,产生变更日志文件。

3. 然后把变更插入变更日志表里面。
mysql $dbname -unobody -pnobody -e
"LOAD DATA LOCAL INFILE '$diff_file'
INTO TABLE update_log
FIELDS TERMINATED BY ',' ENCLOSED BY '\\\'' LINES TERMINATED BY '\n'
(database_name,table_name,column_name,before,after)"

幸运的是,需要纪录变更的表里面没有特别复杂的列,例如,备注栏之类。所以从dump文件中分析数据要简单的多。中间比较折腾的地方也少了,不过还是有两个地方折腾人。

1. 默认从数据库中dump出来的列的值是用单引号括起来了,但是倒入用的LOAD DATA LOCAL INFILE命令的默认格式却不是单引号。指定时需要注意(ENCLOSED BY '\\\'')转义符的使用。
虽然dump的时候,可以指定文件格式。但是都会碰到下面讲到的权限问题。

2."SELECT INTO OUTFILE"和"LOAD DATA INFILE"都涉及一个file权限的问题。
The FILE privilege gives you permission to read and write files on the server host using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements.

mysqldump:
--tab=path
, -T path This option should be used only when mysqldump is run on the same machine as the mysqld server. You must have the FILE privilege, and the server must have permission to write files in the directory that you specify.

LOAD DATA LOCAL INFILE:
If LOCAL is specified, the file is read by the client program on the client host and sent to the server.
For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege.
Using LOCAL is a bit slower than letting the server access the files directly, because the contents of the file must be sent over the connection by the client to the server. On the other hand, you do not need the FILE privilege to load local files.

Security Issues with LOAD DATA LOCAL

mysqldump から、綺麗なスキーマを得る方法

mysqldump -unobody -pnobody --opt --skip-add-drop-table --skip-quote-names -d |
perl -pe '
s!(.+ )(int\(|varchar\(|enum\(|datetime|timestamp)!sprintf("%-20s%s", $1, $2)!ge;
s!(.+)(NOT NULL)!sprintf "%-40s%s", $1, $2!eg;
s!(.+)( default )!sprintf("%-60s%s", $1, $2)!ge;
s!(.+)( auto_increment)!sprintf("%-60s%s", $1, $2)!ge
'

-d : --no-data

星期二, 一月 22, 2008

フィルターとしての Perl

フィルターとしての Perl


テキストの改行コード

perl tips

from Perl Online Document

split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split

Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. (If all fields are empty, they are considered to be trailing.)

If LIMIT is specified and positive, it represents the maximum number of fields the EXPR will be split into, though the actual number of fields returned depends on the number of times PATTERN matches within EXPR. If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of pop would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified. Note that splitting an EXPR that evaluates to the empty string always returns the empty list, regardless of the LIMIT specified.


my $hoge = 'a,b,c,,';
my @foo = split /,/, $hoge; # @foo = ('a', 'b', 'c')
my @bar = split /,/, $hoge, -1; # @bar = ('a', 'b', 'c', '', '')