Archive for November, 2007

Sách nói.Tình yêu.Nguyễn Nhật Ánh

Chia sẻ với mọi người 2 truyện ngắn với giọng văn tự nhiên, nhẹ nhàng & lôi cuốn của Nguyễn Nhật Ánh. Mình nghe xong rất thích & thấy lãng mạng hơn.

"Cô gái đến từ hôm qua", Nguyễn Nhật Ánh .:TTO MediaOnline:.
Tâm lý biết yêu của thời niên thiếu.
URL để tải về :
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd11.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd12.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd13.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd21.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd22.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd31.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd32.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn03-cogaicd41.wma

"Còn chút gì để nhớ", Nguyễn Nhật Ánh .:TTO MediaOnline:.
Tâm lý khi yêu của thanh niên.
URL để tải về :
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd33.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd11.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd12.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd13.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd21.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd23.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd22.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd31.wma
http://media.tuoitre.com.vn/Stream/AudioBooks/tvsn04-conchutgicd32.wma

Advertisements

Some of my tips working with Perl

How to run Linux-shell-command in Perl & get the result ?

Run shell command:
Source: Perl run shell command -> Run Shell COmmand in Perl SCript
From above URL, the answer for running shell command is the system function of Perl.

Get the shell-command result:
Source: Perl run shell command -> Live Search: perl shell command get output
There, they said, there are three basic ways of running external commands:

  • system $cmd;		# using system()
  • $output = `$cmd`;	# using backticks (``)
  • open (PIPE, "$cmd |");	# using open()

I myself prefer the backsticks syntax to get the command’s output most, so convenient! Specifically, I wrote the following to get RAM’s free size :

my $cmd="cat /proc/meminfo | grep MemFree" ;
my $memFree = `$cmd` ;#note the backsticks ` not the ‘ !
$memFree =~ s/
        ^\D+ (\d+) \D+$
    /$1/x ;

What a found!

Notes about arguments when using sub in Perl!

Source: I try it myself!

Assumed we have the code :

#this is where mySub called
my $outside=123 ;
sub mySub {
#here don’t see $outside varible !
}

So note that in sub, we can’t use outside-declared variables declared after the call command. Be caution !

How to get Perl ‘s array size ?

Source: google:perl array size-> Array Manipulation in Perl

Assumed having array @arr, to get its size, call either :

  • directly using $# :
    $#arr+1
  • from a indirect-converved varible :
    $size=@arr

Enjoy!

Some of my tips working on Unix OS

How to call explorer GUI in Linux?

Run a console a call the command nautilus.


How to remote copy files/folder between Linux computers?

google: linux + remote copy -> http://linux.about.com/b/2007/10/08/rcp-scp-ftp-commands-for-copying-files-between-computers.htm

Use scp: (more simple)
scp file2Copy username@hostIP:targetPath
after calling the above command, u’ll be asked for username/password.
scp -r folder2Copy username@hostIP:targetPath

Use rcp:
There it said u need to have .rhosts file in home folder that have lines where each line is :
<the host ip/computer name> <username>

Then, call rcp to copy files as sample :
rcp myLocalFile hostname:targetFile


How to change shell-prompt ‘s color?

google: lprocess + view memory used + linux ->   Process memory usage – LinuxQuestions.org

ps -AH v


How to change shell-prompt ‘s color?

google: linux + command line -> some begginer site to input keyword-space to my knowledge -> shell prompt
google: linux + shell prompt + color -> Tip: Prompt magic

Prompt basics

Under bash, you can set your prompt by changing the value of the PS1
environment variable, as follows:

$ export PS1="> "
>

Changes take effect immediately, and can be made permanent by placing
the "export" definition in your ~/.bashrc file. PS1 can contain any
amount of plain text that you’d like:

$ export PS1="This is my super prompt > "
This is my super prompt >

While this is, um, interesting, it’s not exactly useful to have a
prompt that contains lots of static text. Most custom prompts
contain information like the current username, working directory, or
hostname. These tidbits of information can help you to navigate in
your shell universe. For example, the following prompt will display
your username and hostname:

$ export PS1="\u@\H > "
drobbins@freebox >


Sequence

 Description

\u

 Your username

\w

 Current working directory (such as "/home/drobbins")

Colorization

Colors are selected by adding special sequences to PS1 — basically
sandwiching numeric values between a "\e[" (escape open-bracket) and
an "m". If we specify more than one numeric code, we separate each
code with a semicolon. Here’s an example color code:

"\e[0m"

When we specify a zero as a numeric code, it tells the terminal to reset
foreground, background, and boldness settings to their default values.
You’ll want to use this code at the end of your prompt, so that the text
that you type in is not colorized. Now, let’s take a look at
the color codes. Check out this screenshoot:

Color chart
Color chartaa


export PS1="\w> "

becomes:

export PS1="\e[32;40m\w> "

So far, so good, but it’s not perfect yet. After bash prints the working
directory, we need to set the color back to normal with a "\e[0m" sequence:

export PS1="\e[32;40m\w> \e[0m"

This
definition will give you a nice, green prompt, but we still need to add
a few finishing touches. We don’t need to include the background color
setting
of 40, since that sets the background to black which is the default
color
anyway. Also, the green color is quite dim; we can fix this by adding a
"1" color code, which enables brighter, bold text. In addition to this
change, we need to surround all non-printing
characters with special bash escape sequences, "\[" and "\]".
These
sequences will tell bash that the enclosed characters don’t take up any
space on the line, which will allow word-wrapping to continue to work
properly. Without them, you’ll end up with a nice-looking prompt that
will
mess up the screen if you happen to type in a command that approaches
the
extreme right of the terminal. Here’s our final prompt:

export PS1="\[\e[32;1m\]\w> \[\e[0m\]"

Don’t be afraid to use several colors in the same prompt, like so:

export PS1="\[\e[36;1m\]\u@\[\e[32;1m\]\H> \[\e[0m\]"

Bash allows these prompt strings  to  be  customized by inserting a number of backslash-escaped special
characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format
(e.g., "Tue May 26")
\e an ASCII escape character (033)
\h the hostname up to the first `.'
\H the hostname
\j the number of jobs currently managed by the
shell
\l the basename of the shell's terminal device
name
\n newline
\r carriage return
\s the name of the shell, the basename of $0
(the portion following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel
(e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a
$
\nnn the character corresponding to the octal
number nnn
\\ a backslash
\[ begin a sequence of non-printing characters,
which could be used to embed a terminal control sequence into the prompt
\] end a sequence of non-printing characters

To have this prompt permanently, put the command : export PS1="blabla" in .bashrc file (located in your home folder)
My extracted script:

#The followings set the prompt to show username workingFolder with color
boldGreen="\e[32;1m"
green="\e[32m"
default="\e[0m"
export PS1="\[$boldGreen\]\u\[$default$green\] \w $ \[$default\]"

Enjoy!


How to search & replace on multiple files on Linux OS ?

google:Linux + search and replace multiple files -> Search and replace over file(s) with Perl [linux] [perl] [replace] [search]

They use sed command with inline option and using expression (regular expr.) as :
sed
i e s/source/destination/g *.html

More detail on sed?

google:Linux + sed command -> sed – Linux Command – Unix Command

How to rename multiple files on Linux OS ?

Source: google: linux rename multiple files -> Howto Linux rename multiple files at a shell prompt

Syntax :

rename oldText newText *.files

Eg:
For example rename all *.bak file as *.txt, enter:

$ rename .bak .txt *.bak

Remove all blank space with rename command:
$ rename "s/ *//g" *.mp3

To remove .jpg file extension, you write command as follows:

$ rename ‘s/\.jpg$//’ *.jpg

To convert all uppercase filenames to lowercase:
$ rename 'y/A-Z/a-z/' *


How to get numbers of lines of a huge file?

Source: google: linux shell command + "concatenate string" -> concatenate strings – Linux Forums
There, u can see that we can easily concatenate string by putting variables/strings next to each other.

How to get numbers of lines of a huge file?

Source: my professor Jean Pierre Chevallet -> wc -l <filename2CountLines>

Call the wc command with -l option : wc -l <filename>

How to get memory (RAM) size in Linux OS system by command line?

I need to know the memory size, RAM size, of the server which is a Linux OS. I look on the web and found this quite not easy since the input keyword must be precise.

cat /proc/meminfo
There u can see the line that says: MemFree : ### kB (or mB) is where the free memory is showed.

For a brief information output let’s used :

cat /proc/meminfo | grep MemFree
This will show only the MemFree line! What a command!

Next, we can output the result of free memory size :

  • to a file by cat /proc/meminfo | grep MemFree > outputFile
  • to output it into a Perl varible see it here.
Enjoy!


How to start a program, e.g Kate, in background ?

Source: google:unix + background + start -> Working With the Unix Shell

Just put an & after ur command will make the ‘kate’ run background.

What is the useful programs used on Linux ?

I myself use :

  • Kate as the code/text(e.g Perl) editor
  • and Krusader as the files browser.
  • More over, I used the SSH Secure Shell from www.ssh.com to transfer file between Windows XP and Linux and reversely.

Perl bug: Error when get size of big files?

In Perl, to get file size we use : $size = -s "filename".
I used this to compute size of 2Gb file but nothing happens when call print $size! Suggest this is a Perl’s bug.
-> should try sprintf command instead of print.

I did try again and it print fine using sprintf("%.0f bytes",$size) ;

Bản Tuyên ngôn Độc lập

Source : truyền tay bằng Yahoo Messenger nên ko rõ ai nữa… ^_^

BẢN TUYÊN NGÔN HỌC TẬP…
Hỡi toàn thể học sinh!! Chúng ta muốn an lành, chúng ta phải nhân nhượng. Nhưng chúng ta càng nhân nhượng, giáo viên càng lấn tới, vì họ quyết cho chúng ta lưu ban một lần nữa. Không! Chúng ta thà hi sinh tất cả chứ không để bị lưu ban, nhất định không để… thi lại! Chúng ta phải đứng lên. Bất kỳ học sinh nào, dù nam hay nữ, dù thằng thông minh hay thằng đần độn, không phân chia mập gầy hay cao thấp. Hễ là học sinh thì phải làm mọi cách để thi tốt, kiểm tra tốt. Ai có sách dùng sách, ai có fao thì dùng fao. Không có sách, có fao thì nhìn thằng kế bên mà chép.

(hết biết ^_^)

bebet.vn -> Việt Nam related links

Unix – How to search for a word in a big file ?

The probelm.

I have done a tag-name statistics on a huge wikipedia data files and figure out that some tags are extremely useful while others are useless.
My next step: Look at the text contents of those important tags to see what text lying there!
My objective of doing this: I need to find the places inside a huge files where the text there is the most meaningful, which is a prerequisite to calculate P(w2|w) = P(w,w2)/P(w).

So, the problem is : search a tag name in a very huge file to see its context(the surrounding text) by naked eye, which will help to define the importance tags(by urself sense).

The solution.

Source :

  1. my Prof.Chevallet did a demo 1, 2 weeks ago and I saw him using ‘grep’ to seek text in a file.
  2. google:unix grep command -> Linux and UNIX grep command help

So what u need to do to search for the text is :
grep <seeking text> <filepath> -n -m <# of lines u wanna see> -C 1 –color
where :

  • -n
    will show line number
  • -m #
    will stop showing after # lines
  • –color
    help highlight matched terms
  • -C #
    show # of nearby(above & below) near the matched terms.

One example :
grep mySeeking myFile -n -m 11 -C 1 –color

Enjoy!