2007-12-06

SPARC: What to Do if You Forgot Root Password

SPARC: What to Do if You Forgot Root Password


(Use keyboard abort sequence--Press Stop A keys to stop the system)
ok boot net -s
# mount /dev/dsk/c0t3d0s0 /a
# cd /a/etc
# TERM=vt100
# export TERM
# vi shadow
(Remove root's encrypted password string)
# cd /
# umount /a
# init 6

2007-12-05

Quota setting of Linux & BSD

這四天連續看了 Linux 和 FreeBSD 的手冊,設定 quota,今晚的進度即將邁入 Solaris;都是為了推廣系上得 Unix-account Service,所以需要給每位使用者 quota limit。以下寫下個別的心得。

對於 Linux,是我最熟悉的系統,之前有設定過一次,可是出現錯誤,當下沒有立即排除,造成這次閱讀的時候釐清了一些原本誤解的觀念。例如,Quota 是 kernel mode 的功能,我有一種感覺一直以為要 dependence on HW;要怎樣的 quota limit 就得割一個 partition 給設定檔,一時腦筋轉不過來。既然都是軟體實做了,這些硬體的問題都會克服的。

接著,Venus 是跑 GNU/Debian Linux,大約花了三個小時設定,釐清觀念,事後很開心,翻起 FreeBSD Handbook 接著看。

FreeBSD 是 CoreDure Quad 的壯壯機,fBSD 對於我來說是個新系統,先前的成功經驗,加上對 fBSD 的新鮮感,所以猛看手冊。上次的進度停留在 Ch.4,今天大約花了五個小時,一直看到完。我沒那麼神,中間有些東西我不感興趣,例如 printer setting 還有 networking setting,所以就 skip into next lol。早上開始逐章讀,興致全開,竟然編起 FreeBSD Kernel,我真的很開心,因為學到不少新東西。之前見到 afoofa 說 Linux 的 make menuconfig is such friendy to her, but the interface FreeBSD is a little bit bored and monolithic. 但是我反而覺得 Handbook 教的很詳細,我很感謝 maintainer 把文件寫的那麼清楚,一一介紹,讓我觀念清楚明瞭,可以放心地跟著進度走。

今天編 kernel 都沒有 booting failure,真開心。不過還沒很確定是否要這麼做 make clean cleandepend depend buildkernel installkernel,前面三個步驟是我比較不清楚的。Durning making the source tree, I've found a interesting function, had before in Linux, that is -j, menas make "make" to does something in parallel. And my best argument is "16", not "32". It earns more and more time-saving and performance.

中午吃完飯,一度沉迷在 SMP 的 option。先說的,這篇 Installing the FreeBSD SMP Kernel 已經過期了,裡面的 APIC_IO, NCPU, NBUS, NAPIC 都已經在 6.2 kernel 失效了,只需要指定 SMP 就行了。

接著,我又病發了,開始找 SMP 的實做時比較早,心中一直有個感覺,逐漸推翻 FreeBSD 優於 Linux 的看法。Linux 很多人送 code & patch,FreeBSD 則是人數沒有那麼多,而且 Linux 有不少商業公司背書,燒錢改善 Linux。不過,現在下定論還太早,因為各有可取之處。謂之:「量才適性,學而不倦」。

我現在找到最早的 Linux SMP 是 2.0 加入的,1996。而 FreeBSD 是 5.0, in 2003 推出。不過,我也有看見 1986 就在寫的,不知道正確與否。

後來,有個疑問:如果 OS kernel has no SMP supports, can program run as parallel, as like MP? 後來想到,如果 OS 沒有 SMP,四隻 folding@home process 會平分一個 CPU 資源,而有 SMP 的話,每隻都是跑到 99.8% 左右。哈哈~ 可是這又不是純 MP,如果用 icc 編的話,應該也會得到同樣的結果。

好奇 kernel 怎麼知道是 SMP-type cpu,用 asm does detect?

另一支 BSD Family 就是 Solaris,我一直覺得上面的 utilities 功能都不健全,Linux 算是最健全的,fBSD 其次,Solaris 最少。我看,說不定 AIX, IRIX, HP-UP 更少呢~ 可是,也必須承認,因為硬體特性的關係,這些大廠都寫了很多東西支援,是一般 i386 OS (Linux, fBSD) 不會去實做的。

光是 Solaris 要設定 quota 的手冊就翻了兩本,因為要 refer,加上我也對它不熟,所以今天眼睛累,手指也酸了,就先暫擱吧。

2007-09-24

Ptt 的功能未來可能性

Why Use Parallel Computing?
*Other reasons might include:
**Overcoming memory constraints - single computers have very finite memory resources. For large problems, using the memories of multiple computers may overcome this obstacle.

用 MPI 實做應該可行,不用特地買一台 20,000 NT 的 quad cores 機器。

2007-09-16

MVC - Model-view-controller

Model-view-controller

Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.

Perl::Catalyst
Perl::Jifty
PHP::CakePHP
PHP::Zend Framework

The brief is a good brief of wikipedia, I love its style forever.

cd2iso

The magic of creating CD ISO files under Windows


/* This program has been compiled with VC6 and tested under Windows XP SP2 */
#include
#include

int main ( int argc, char ** argv )
{
FILE * f, * out;
char buf[512];
unsigned len;

if (argc != 2)
{
fprintf( stderr, "Syntax: rdiso filename\n" );
return 1;
}

if ( (f = _fsopen( "\\\\?\\CdRom0", "rb", _SH_DENYNO )) == NULL)
{
fprintf( stderr, "Can't open CdRom0\n" );
return 1;
}

if ( (out = fopen( argv[1], "wb" )) == NULL)
{
fprintf( stderr, "Can't open %s\n", argv[1] );
return 1;
}

do
{
len = fread( buf, 1, sizeof(buf), f );
if (len)
fwrite( buf, 1, len, out );
}
while (len == sizeof(buf));
fclose( f );
fclose( out );
return 0;
}

2007-09-14



In the book, "The Complete FreeBSD", wrote,

“Those Linux books hve over1000 pages! This looks like nothing. What can you do? We need something yesterday!

Haha~~

2007-09-06

ssh-copy-id


ssh-copy-id - install your identity.pub in a remote machine’s authorized_keys

ssh-copy-id [-i [identity_file]] [user@]machine

2007-09-05

Never have it again!!!


int** ptr = malloc( sizeof(int) * SIZE );
char** ptr = malloc( sizeof(char) * SIZE );

WRONG


int** ptr = malloc( sizeof(int**) * SIZE );
char** ptr = malloc( sizeof(char**) * SIZE );

RIGHT

2007-08-22

Linux Networking-HOWTO

5.7 Routing.

You cannot modify the Hosts file or the Lmhosts file in Windows Vista

You cannot modify the Hosts file or the Lmhosts file in Windows Vista

WORKAROUND
To work around this issue, follow these steps:
1. Click Start Start button , click All Programs, click Accessories, right-click Notepad, and then click Run as administrator.

User Account Control permission If you are prompted for an administrator password or for a confirmation, type the password, or click Allow.
2. Open the Hosts file or the Lmhosts file, make the necessary changes, and then click Save on the Edit menu.

Links in Today

kqemu, QEMU Accelerator modules

alias in dos, use the doskey.

2007-08-21

libmtsk.so

Forbestperformanceandfunctionality,makesurethatthelatestOpenMPruntimelibrary,
libmtsk.so,isinstalled on the running system.


How can I find out the libmtsk.so. :(

Haha~~ have the patch for old-school. :D

SunOS 5.9: Microtasking libraries (libmtsk) patch

2007-08-20

Algorithm for square matrix multiplication

The trivial: O(n^3)
The Strassen: O(n^2.807)
The fastest*: O(n^2.376)

As the Strassen algorithm [ http://0rz.tw/bf2Xo ] mentioned:

The reduction in the number of multiplications however comes at the price of a somewhat reduced numeric stability.


* Coppersmith–Winograd algorithm
Reference:

*The Simultaneous Triple Product Property and Group-theoretic Results for the Exponent of Matrix Multiplication, arXiv:cs.CS/0703145

2007-08-19

Links in Today

Improving Application Efficiency Through Chip Multi-Threading

2.1.1.8 Multi-Threaded malloc

malloc and free are single-threaded operations and are among the bottlenecks for multi-threaded applications. A multi-threaded malloc scales with multi-threaded requests and can improve multi-threaded application performance. The Solaris OS has two types of multi-threaded malloc libraries, mt-malloc and umem.

2.1.1.8.1 Usage

a. Using mt-malloc:
LD_PRELOAD=libmtmalloc.so

b. Using libumem:
LD_PRELOAD=libumem.so

cc [ flag... ] file... -lumem [ library... ]

跟我的想法是一樣的,因為開矩陣還是需要很多時間的。

2007-08-16

Ethernet Codes: Vendor codes

Ethernet Codes: Vendor codes

Grid Topics

The Globus Alliance

gen()


#include
#include

#define N1 5000
#define N2 5000


void gen( int** a, int** b)
{
int i, j;
for (i = 0; i < N1; i++) {
for (j = 0; j < N2; j++) {
srand( 0 );
a[i][j] = rand() % 5 + 1;
srand( 1 );
b[i][j] = rand() % 5 + 1;
}
//printf("i: %d\n", i);
}
pthread_exit(NULL);
}

void mul( int** a, int** b)
{
int i, j, k;
int c[N1][N2];

for (i = 0; i < N1; i++) {
for (j = 0;j < N2; j++) {
c[i][j] = 0;
for (k = 0; k < N1; k++)
c[i][j] += a[i][k] * b[k][j];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}

int main(int argc, char *argv[])
{
int** a = NULL;
int** b = NULL;
int** c = NULL;

a = (int**) malloc( sizeof(int) * N1 * N2);
b = (int**) malloc( sizeof(int) * N1 * N2);
c = (int**) malloc( sizeof(int) * N1 * N2);

pthread_t* thread = NULL;
thread = (pthread_t*) malloc( sizeof(pthread_t) * N1);
int result;

int i;
for (i = 0; i < N1; i++) {
a[i] = (int *) malloc( sizeof(int) * N2);
b[i] = (int *) malloc( sizeof(int) * N2);
c[i] = (int *) malloc( sizeof(int) * N2);
}

gen(a, b);

return 0;
}

$ gcc m1.c && time ./a.out

real 3m55.660s
user 3m55.391s
sys 0m0.184s


This result without threading.

2007-08-12


#include <pthread.h>
#include <stdio.h>

#define N 10

void *test(void *c)
{
printf("\tI am thread: %d\n", (int)c);
pthread_exit(NULL);
}

int main()
{
int i, result;
pthread_t t[N];

for(i = 0; i < N; i++) {
result = pthread_create(&t[i], NULL, test, (void *)(i));
if (result)
printf("Cannot do create.\n");
}

return 0;
}


出來每次結果都不同。 :( 需要明確地等待

BlueGene/L Apply Form

Using BG/L

Cluster Building

NCHC Formosa PC Cluster, 感覺親切。
研討會資料, HP 64bit Cluster
硬體資料
NCHC PC Cluster
國家高速網路與計算中心-PC Cluster 討論區
HIGH PERFORMANCE COMPUTING LAB. // 高效能計算實驗室 //, 東海大學

Reaching the Goal with the Regensburg Marathon-Cluster, Hubert Feyrer
High Performance Computing Training

Books,
*Beowulf Cluster Computing with Linux




*Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers




*An Introduction to Parallel Computing: Design and Analysis of Algorithms

Passing Multidimensional Arrays


#include <iostream>
using std::cout;

void print_m35(int m[3][5]);
void print_mi5(int m[][5], int dim1);
//void print_mij_(int m[][], int dim1, int dim2);
void print_mij(int* m, int dim1, int dim2);


void print_m35(int m[3][5])
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';
}
}

void print_mi5(int m[][5], int dim1)
{
for (int i = 0; i < dim1; i++)
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';

}

/*
void print_mij_(int m[][], int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << [i][j] << '\t';
cout << '\n';
}
}
*/

void print_mij(int* m, int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << m[i * dim2 + j] << '\t';
cout << '\n';
}
}

int main()
{
int v[3][5];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
v[i][j] = j;

print_m35(v);
print_mi5(v, 3);
print_mij(&v[0][0], 3, 5);

return 0;
}

2007-08-11

libc-dev

I have installed the icc with stdlibc++.so.5 in my box, a box grow on 2.6 series kernel. And I also have the gcc-4.1.2 with libc6 libraries. Then one time, I'd like to debug with an executable file called "a.out", but I have no idea to do it. The gdb says that,

Failed to read a valid object file image from memory

When I run it during debug process.

As the "file" results:

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux 2.4.1, not stripped

But actually, it should be like below,

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped


I'm not dare to remove the _big_base_ libc6, but I reinstall the "libc-dev" then it returns back to my hoping status. :D

SunFire 15K (Solaris & Debian)

HCL for Solaris OS
Platform Group:   sun4u


Current Status, Debian on SPARC platform
Supported are Sun4m and Sun4u machines (with a 32-bit userland).

UltraLinux

gprof

Linux/Alpha or How to Make Your Applications Fly
Linux Performance Analysis Tools

[Author], David Mosberger

---
Useful Tools tutorial

gprof TIPS:

* Don't optimize before profiling
* Be careful not to optimize before profiling!
* Profile before you optimize.

hahaha~~~ :D I compiled it with -O3 options of icc and gcc. :D

2007-08-07

Apache+Subversion Recipe

subversion with lighty?
Apache+Subversion Recipe, Good boy!!

Linux to Power Google GPhone

HTC

 
 

Sent to you by Alan via Google Reader:

 
 

via OSNews by donotreply@osnews.com (Eugenia Loli-Queru) on Aug 04, 2007

"Google's first mobile phone reportedly will run a Linux operating system on a Texas Instruments "Edge" chipset, and will likely ship to T-Mobile and Orange customers in the Spring of 2008. "GPhone" call minutes and text messages will apparently be funded by mobile advertising, according to reports." The report found at the popular embedded systems Linux news site LinuxDevices.

 
 

Things you can do from here:

 
 

2007-08-06

Matrix Transpose

I did ten thousand times multiplication with 800x800 matrix, each element is raged from one to five, integer type.

yrchen tole me a hint yesterday afternoon, that, the matrices should be tramsposed before did a huge compute. In today's experiment, I wrote two version codes, one doesn't has any transpose loop (called m1), the other does (called m1_t). Both them compiled with gcc, with -O3 optimization. The result is:

m1_t:
real 5m31.300s
user 5m31.245s
sys 0m0.020s


m1:
real 5m30.802s
user 5m30.265s
sys 0m0.008s


It looks like that -O3 did the transpose before has the huge matrices multiplication.


#include
#include

#define DIE 800

void gen( int a[][DIE]);
void mul( int a[][DIE], int b[][DIE]);

int main(int argc, char *argv[])
{
int a[DIE][DIE];
int b[DIE][DIE];

int i;
for (i = 0; i < 10000; i++) {
srand(0);
gen(a);
srand(1);
gen(b);
mul(a, b);
}

return 0;
}

void gen( int a[][DIE] )
{
int i, j;
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
a[i][j] = random() % 5 + 1;
}

void mul( int a[][DIE], int b[][DIE])
{
int i, j, k;
int c[DIE][DIE];

//Transpose
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
mul[i][j] = b[j][i];

for (i = 0; i < DIE; i++) {
for (j = 0;j < DIE; j++) {
c[i][j] = 0;
for (k = 0; k < DIE; k++)
c[i][j] += a[i][k] * mul[i][k];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}

2007-08-04

Matrix Mutiplication Hint

先做轉置 (det)。

因為 CPU 會一次 fetch 1byte in each row, 而 matrix mul 是 col * row,所以可以直接把做一次 det(row) -> col,就能直接 fetch det(row) -> col。速度較快!

不要使用 recursive,因為 OS 要 handle 很多 stacks is a heavy-loading job。直接改用多個 whilie 把 huge-matrix 展開,開 threads 去分割成 strsen algo smaller-matrix.

這是 yrchen 給的 common hint.

2007-07-27

Linux: The 0.01 Release



 
 

Sent to you by Alan via Google Reader:

 
 


"This is a free minix-like kernel for i386(+) based AT-machines," began the Linux version 0.01 release notes in September of 1991 for the first release of the Linux kernel. "As the version number (0.01) suggests this is not a mature product. Currently only a subset of AT-hardware is supported (hard-disk, screen, keyboard and serial lines), and some of the system calls are not yet fully implemented (notably mount/umount aren't even implemented)." Booting the original 0.01 Linux kernel required bootstrapping it with minix, and the keyboard driver was written in assembly and hard-wired for a Finnish keyboard. The listed features were mostly presented as a comparison to minix and included, efficiently using the 386 chip rather than the older 8088, use of system calls rather than message passing, a fully multithreaded FS, minimal task switching, and visible interrupts. Linus Torvalds noted, "the guiding line when implementing linux was: get it working fast. I wanted the kernel simple, yet powerful enough to run most unix software." In a section titled "Apologies :-)" he noted:

"This isn't yet the 'mother of all operating systems', and anyone who hoped for that will have to wait for the first real release (1.0), and even then you might not want to change from minix. This is a source release for those that are interested in seeing what linux looks like, and it's not really supported yet."

read more


 
 
 
 

Lighttpd Configuration Reference

http://trac.lighttpd.net/trac/wiki/Docs%3AConfigurationOptions

2007-07-26

Uninstall DRBL

for i in `acs drbl|cut -f 1 -d " "`; do agr -y "$i";done

Schedule

1. Matrix Multiplication
2. 1 + 2 + 3 + ... + 999999 with pthreads method
3. Dividing the huge matrices into small parts
4. Redo last step with pthreads
5. Knowing how to manipulate icc

pthread

POSIX Threads

Native POSIX Thread Library (NPTL), getconf GNU_LIBPTHREAD_VERSION, NPTL 2.3.6

NPTL Trace Tool

IBM Linux Technology Library, Linux threading models compared: LinuxThreads and NPTL

2007-07-06

HPC Links

Gluster is a GNU cluster distribution aimed at commoditizing Supercomputing and Superstorage. Core of the Gluster provides a platform for developing clustering applications tailored for a specific tasks such as HPC Clustering, Storage Clustering, Enterprise Provisioning, Database Clustering etc.

Z RESEARCH enables System Integrators, with little or no experience in clustering, to build Clustered File Storage, HPC Clusters and Supercomputers from Commodity off the Shelf Components (COTS) using Clustered architecture and Z RESEARCH'S software stack 'Gluster'.

amar, 可愛的網域。 :) 是一位印裔工程師。

白爛的圖片

Computer cluster

2007-07-05

e1000_request_irq: Unable to allocate MSI interrupt Error: -22

結論是,暫時不要用 linux-image-2.6.20-15-generic 或 Feist 的版本。 衝 gutsy!!

Links:
google://
dmesg eth0 e1000_request_irq Unable to allocate MSI interrupt Error: 22

wired ethernet interface missing
e1000 high latency problem, msi error on boot.

2007-06-21

人家只是轉圖檔而已...

竟然造成 kernel panic!! 因為 Out of memory!

for i in `ls -1 *.jpg`;do (convert -quality 48 -crop +0-1000 "$i" tmp/"$i" &); done

如此而已就 :(
寫信來去論壇問看看

2007-06-20

Perldoc, Day 1

perlintro.html

Using my in combination with a use strict; at the top of your Perl scripts means that the interpreter will pick up certain common programming errors. For instance, in the example above, the final print $b would cause a compile-time error and prevent you from running the program. Using strict is highly recommended.

類似 gcc -Wall


unless ( condition )
if (!condition)


Note that the braces are required in Perl, even if you've only got one line in the block.

Too bad


print "LA LA LA\n" while 1;          # loops forever


Cool!!


A list of them is given at the start of perlfunc and you can easily read about any given function by using perldoc -f functionname .



You can read from an open filehandle using the <> operator. In scalar context it reads a single line from the filehandle, and in list context it reads the whole file in, assigning each line to an element of the list:



Reading in the whole file at one time is called slurping. It can be useful but it may be a memory hog.

寫的真傳神! hog *grin* :P


When you're done with your filehandles, you should close() them (though to be honest, Perl will clean up after you if you forget):

哈! 好笑! though to e honest. :P


if ($a =~ /foo/) { ... }  # true if $a contains "foo"

The // matching operator is documented in perlop. It operates on $_ by default, or can be bound to another variable using the =~ binding operator (also documented in perlop).

In [perlop.html],
Binary "=~" binds a scalar expression to a pattern match. Certain operations search or modify the string $_ by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or transliteration. The left argument is what is supposed to be searched, substituted, or transliterated instead of the default $_. When used in scalar context, the return value generally indicates the success of the operation. Behavior in list context depends on the particular operator. See "Regexp Quote-Like Operators" for details and perlretut for examples using these operators.

If the right argument is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time.

Binary "!~" is just like "=~" except the return value is negated in the logical sense.



These are documented at great length in perlre, but for the meantime, here's a quick cheat sheet:
XDDD 快速騙人小抄 (quick cheat sheet)



while (<>) {
next if /^$/;
print;
}

我覺得寫的很美!

while ((c = get()) != NULL) {
printf ("%s\n", c);
}



http://cpan.stu.edu.tw/

第一次嘗試 CPAN install Bundle::CPAN 跑出一大堆鬼東西,看起來這個系統寫的很完整,也很大!

2007-06-19

‘Bad fd number’ error in Ubuntu 6.10 (Edgy Eft)

PCMan, Day 1

Demystifying Subclassing
Advice from the creator of C++

A Tour of C++
Procedural Programming
Decide which procedures you want; use the best algorithms you can find.

Modular Programming
Decide which modules you want; partition the program so that data is hidden within modules.

IBM Blade Center
Bjarne Stroustrup's homepage

Separate compilation is an issue in all real programs. It is not simply a concern in programs that present facilities, such as a Stack, as modules. Strictly speaking, using separate compilation isn't a language issue; it is an issue of how best to take advantage of a particular language implementation. However, it is of great practical importance. The best approach is to maximize modularity, represent that modularity logically through language features, and then exploit the modularity physically through files for effective separate compilation.

2007-05-16

How can I get input without having the user hit [Enter]?

Using standard C/C++, you cannot. However, if you're lucky your compiler may have the non-standard conio.h header (which might include getch()), if you're on *nix (UNIX, Linux, etc.) you can try the ncurses library or switching the terminal mode. On Windows, try the different API input routines (such as those included in the Win32 API).

Got this answer from, password input.

2007-05-08

Linus said st in Linux kernel coding style

開宗明義說

10 First off, I'd suggest printing out a copy of the GNU coding standards,
11 and NOT read it. Burn them, it's a great symbolic gesture.

怎麼會這樣啦~

這變成 Humorous Quotes Seen on UseNet 的收藏。

這個東西酷斃了,排版好漂亮!


整篇 Linux Kernel coding style 都是很搞笑,而且文筆寫的很直接,帥氣!! XDDDDD


131 Heretic people all over the world have claimed that this inconsistency
132 is ... well ... inconsistent, but all right-thinking people know that
133 (a) K&R are _right_ and (b) K&R are right. Besides, functions are
134 special anyway (you can't nest them in C).



182 When declaring pointer data or a function that returns a pointer type, the
183 preferred use of '*' is adjacent to the data name or function name and not
184 adjacent to the type name. Examples:
185
186 char *linux_banner;
187 unsigned long long memparse(char *ptr, char **retptr);
188 char *match_strdup(substring_t *s);

很好,因為我這次的 Ch5-1 就是寫在 type name。 :P 因為我覺得滿美觀的呀,尤其是要同時宣告很多這種變數的時候,就一個 * 套用到宣告出來的多個變數。


What is unary
Meaning one; a single entity or operation, or an expression that requires only one operand.



209 C is a Spartan language

我以為看到 三百兄貴


209 C is a Spartan language, and so should your naming be. Unlike Modula-2
210 and Pascal programmers, C programmers do not use cute names like
211 ThisVariableIsATemporaryCounter.


XDDDDDDDD



224 Encoding the type of a function into the name (so-called Hungarian
225 notation) is brain damaged - the compiler knows the types anyway and can
226 check those, and it only confuses the programmer. No wonder MicroSoft
227 makes buggy programs.

brain damaged 翻譯成「頭殼壞掉」是最適合不過了!!整段寫的超搞笑,笑死我了啦~~~~~
我之前學過 Hungarian notation in VB,覺得 btn 代表 Button 這個元件很合適,也很容易閱讀,可是他為甚麼說只要 compiler 知道類型就好了,不考慮人的問題呢?強記?還是看宣告就行了!?



235 If you are afraid to mix up your local variable names, you have another
236 problem, which is called the function-growth-hormone-imbalance syndrome.
237 See chapter 6 (Functions).

看到 function-growth-hormone-imbalance syndrome 還以為什麼專業的單字,害我猛起勁來查 stardict,結果得到 「生長功能荷爾蒙失調併發症」!!幹~~~~ 寫這篇的人到底在寫什麼啦?這篇根本是笑話集!



244 It's a _mistake_ to use typedef for structures and pointers.

我承認 Ch5-1 裡面有用到

typedef struct {...} student;
student* stu;

這種他說的錯誤。而且還犯了兩種錯誤。



397 Comments are good, but there is also a danger of over-commenting. NEVER
398 try to explain HOW your code works in a comment: it's much better to
399 write the code so that the _working_ is obvious, and it's a waste of
400 time to explain badly written code.

所以寫 comment 是為了解釋「工作內容」,而非「如何工作」。



402 Generally, you want your comments to tell WHAT your code does, not HOW.
403 Also, try to avoid putting comments inside a function body: if the
404 function is so complex that you need to separately comment parts of it,
405 you should probably go back to chapter 6 for a while. You can make
406 small comments to note or warn about something particularly clever (or
407 ugly), but try to avoid excess. Instead, put the comments at the head
408 of the function, telling people what it does, and possibly WHY it does
409 it.

盡量避免一個 function or class 做太多功能,這樣才能節省 comment 的長度,和讀者了解的「墾掘深度」。



420 /*
421 * This is the preferred style for multi-line
422 * comments in the Linux kernel source code.
423 * Please use it consistently.
424 *
425 * Description: A column of asterisks on the left side,
426 * with beginning and ending almost-blank lines.
427 */
428
429 It's also important to comment data, whether they are basic types or derived
430 types. To this end, use just one data declaration per line (no commas for
431 multiple data declarations). This leaves you room for a small comment on each
432 item, explaining its use.

一個資料描述一行,逗號後面換行。




437 That's OK, we all do. You've probably been told by your long-time Unix
438 user helper that "GNU emacs" automatically formats the C sources for
439 you, and you've noticed that yes, it does do that, but the defaults it
440 uses are less than desirable (in fact, they are worse than random
441 typing - an infinite number of monkeys typing into GNU emacs would never
442 make a good program).

這未免也太人身攻擊了吧,p 老師就是 emacs 愛用者,該不會 emacs 的使用者都跑去 non-Linux dist 吧!? :P 難怪 Linux kernel loading balancing 沒有比某個 BSD 來的好!



473 recognize the authority of K&R (the GNU people aren't evil, they are
474 just severely misguided in this matter),

哈!我看到這裡,實在是... 想要知道當初是什麼條件讓 Linus Torvalds 願意將 Linux Kernel 以 GPL 釋出!?出櫃? XDDDD

@_@!? 出櫃不是 screw-up... : 出櫃(英文“come out of the closet”的直譯,指暴露同志身份)



RTL : http://www.answers.com/topic/rtl
Register Transfer Level


GNU Manuals Online
JTC1/SC22/WG14 - C
WG14 is the international standardization working group for the programming language C

2007-04-29

Char's pointer's pointer

This is a good example to know how to pass char's pointer to the function.

char *name[3];
name[0] = "a2n";
name[1] = "c9s";
name[2] = "ccn";

Known name at 0x1, and its content is:

{0x100, 0x101, 0x102}

Meaning indicates to "a2n", "c9s" and "ccn", respectively.


The array "name" saves the three string's address in its array space, hence, pass the array "name" to other function might via the address, and access the content of array "name" via address again. In the other word, I shall using "Pointer into Pointer" in the parameters field of array "name". :-)



Example:



void show(char **name)
{
for (int i = 0; i < 3; i++) cout << *name[i] << endl;
}

char *name[3];
name[0] = "a2n";
name[1] = "c9s";
name[2] = "ccn";
show(name);

2007-04-11

How can I create a program alias?

How can I create a program alias?

A. It is possible to create an alias for a program, for example to define johnword.exe to actually run winword.exe. To do this perform the following:

    *Start the registry editor (regedit.exe)
    *Move to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
    *From the Edit menu select New - Key
    *Enter the name of the alias, e.g. johnword.exe and press Enter
    *Move to the new key and double click on the (Default) value (it is blank by default)
    *Set to the fully qualified file name it should run, e.g. C:\Program *Files\Microsoft Office\Office\winword.exe. Click OK
    *Optionally you can create a new String called Path which is where the program will first start running (Edit - New - String Value - Path, double click and set to the starting path)
    *Close the registry editor

If you now select Run from the start menu and type johnword.exe it would start Microsoft Word, cool!

If you type your alias from the command prompt it will not find it, however if you type

C:\> start

it will work fine.

The actual program name does not have to be an .exe program -- it can be any file that has an association (such as "C:\temp\ntfaq.url"). The alias itself can remain as an .exe.

If the alias is an .exe, then the "run" or "start" command does not need to include the extension. If the alias is NOT an .exe, then you need to use the full name but then you are not limited to any extensions (but it must have some extension). Your alias can be John.Savill which you have aliased to "C:\ProgramYadaYadaYada\Winword.exe" and Word will start up just fine.

2007-03-30

Pointer Discrepancy between vc++ & g++


1 #include
2
3 using namespace std;
4
5 int main()
6 {
7 int a = 1, b = 2;
8 int *x;
9
10 cout << "x: " << x << '\t';
11 cout << "*x: " << *x << '\t';
12 cout << "&x: " << &x << '\t';
13
14 cout << endl;
15
16 x = &a;
17 cout << "x = &a" << '\t';
18 cout << "x: " << x << '\t';
19 cout << "*x: " << *x << '\t';
20 cout << "&x: " << &x << '\t';
21
22 cout << endl;
23
24 x = &a - 1;
25 cout << "x = &b" << '\t';
26 cout << "x: " << x << '\t';
27 cout << "*x: " << *x << '\t';
28 cout << "&x: " << &x << '\t';
29
30 cout << endl;
31 return 0;
32 }


Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


modified code...

x = &a x: 0012FF7C *x: 1 &x: 0012FF74
x = &a-1 x: 0012FF78 *x: 2 &x: 0012FF74


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


x: 0xb7f518dc *x: -1 &x: 0xbf97f214
x = &a x: 0xbf97f218 *x: 1 &x: 0xbf97f214
x = &a-1 x: 0xbf97f214 *x: -1080561132 &x: 0xbf97f214



g++ 讓我驚訝!! 結果 VC++ 2005 Expression 也讓我受精。 XD

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86



x = &a x: 0012FF60 *x: 1 &x: 0012FF48
x = &a-1 x: 0012FF5C *x: -858993460 &x: 0012FF48

Pointer sequence #2


1 #include
2
3 using namespace std;
4
5 int main()
6 {
7 int a = 1, b = 2;
8 int *x;
9
10 cout << "x: " << x << '\t';
11 cout << "*x: " << *x << '\t';
12 cout << "&x: " << &x << '\t';
13
14 cout << endl;
15
16 x = &a;
17 cout << "x = &a" << '\t';
18 cout << "x: " << x << '\t';
19 cout << "*x: " << *x << '\t';
20 cout << "&x: " << &x << '\t';
21
22 cout << endl;
23
24 x = &b;
25 cout << "x = &b" << '\t';
26 cout << "x: " << x << '\t';
27 cout << "*x: " << *x << '\t';
28 cout << "&x: " << &x << '\t';
29
30 cout << endl;
31 return 0;
32 }



g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


x: 0xb7f078dc *x: -1 &x: 0xbff350c4
x = &a x: 0xbff350cc *x: 1 &x: 0xbff350c4
x = &b x: 0xbff350c8 *x: 2 &x: 0xbff350c4




Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


跑到 line 10 就結束!

then modified code.
x = &a x: 0012FF7C *x: 1 &x: 0012FF74
x = &b x: 0012FF78 *x: 2 &x: 0012FF74

Pointer sequence #1


#include

using namespace std;

int main()
{
int a, b, c, d, e;
int i;

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
cout << "A: " << &a << "\nB: " << &b
<< "\nC: " << &c << "\nD: " << &d << "\nE: " << &e;

cout << endl;
return 0;
}



Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


1
2
3
4
5
A: 0012FF7C
B: 0012FF78
C: 0012FF74
D: 0012FF70
E: 0012FF6C


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


1
2
3
4
5
A: 0xbfdc2cec
B: 0xbfdc2ce8
C: 0xbfdc2ce4
D: 0xbfdc2ce0
E: 0xbfdc2cdc




#include

using namespace std;

int main()
{

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
for (i = 0; i < 5; i++)
cout << "Var" << i << ":\t"
<< &a - i << " : "
<< *(&a - i) << '\n';

cout << endl;
return 0;
}


Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


1
2
3
4
5
Var0: 0012FF7C : 1
Var1: 0012FF78 : 2
Var2: 0012FF74 : 3
Var3: 0012FF70 : 4
Var4: 0012FF6C : 5


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


1
2
3
4
5
Var0: 0xbfdea9e0 : 1
Var1: 0xbfdea9dc : 2
Var2: 0xbfdea9d8 : 3
Var3: 0xbfdea9d4 : 4
Var4: 0xbfdea9d0 : 5

2007-03-08

All mail -> Gmail

看到 Yi-Feng Tzeng’s Blog用 Gmail 收取外部郵件後,開始動手設定我的幾個信箱都納入 Gmail 管理。

兩個學術單位信箱,Y! 需要付費才有 POP3 收信功能,加上最近的 spam 都直接進入 inbox,所以想要放棄 Y! 了,目前它的功能只剩下 tw.clubs 和網拍的認證而已。

Gmail 方便至極,不用我多說。哈哈,但是我還是覺得有些改進的空間,找個時間去寫 feedback 給他們。

2007-02-18

MITOCW grabber

NAME
    grabber.sh - Grabbing the MIT OCW course data.

SYNOPSIS
    sh grabber.sh

DESCRIPTION
    今天清晨睡不著起來寫的一支小程式,專門用來抓 MIT OCW 的課程資料。獲益就是複習和增進 Regular Expression 的用法,並且搭配很多 Unix pipe (|),小小的心得而已,跟大家分享我的程式。

KNOWN BUGS

    1. Welcome.htm 拉到 index.htm 有瑕疵
    2. URL.txt 裡面有重複的列,因為課程名稱一樣

AUTHOR
    Alan Lu. (alan0098/a/gmail/d/com)




有行數程式碼放在 http://163.26.225.215/~a2n/src/grabber_nu.sh.txt
無行數的程式碼放在 http://163.26.225.215/~a2n/src/grabber.sh.txt


RegExp 小記:

2007-01-13

Remote backup

SSH:
dd if=/dev/foo | ssh foo@foo dd of=foo


FTP:
ftp foo
ftp> bin
ftp> put "| dd if=/dev/foo" foo
ftp> get foo "| dd of=/dev/foo"
ftp> get foo.tar.bz2 "| tar -xj -"


ref: 1. http://www.wsp.krakow.pl/~bar/DOC/ssh_backup.html
2. http://0rz.net/741kp
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
topic=/com.ibm.aix.doc/infocenter/howto/HT_prftungd_slowTSMbkupperf.htm
google: backup dd if= ftp -ssh

2007-01-11

GNU GLOBAL

GNU GLOBAL is a source code tag system that works the same way across diverse environments.


17:02:46 :: linux-2.6.19.1 $ time gtags

real 25m56.492s
user 1m44.167s
sys 1m47.283s

17:28:48 :: linux-2.6.19.1 $ time htags

real 43m1.615s
user 3m19.044s
sys 21m41.105s

19:09:04 :: linux-2.6.19.1 $ du -sh HTML/
2.1G HTML/


目前轉好兩個專案,分別是 7-zip 和 FileZilla,放在 野人 。提供這種原始碼線上瀏覽的網站,有大名鼎鼎的 Cross-Referencing Linux ,使用 LXR 系統轉換的。

Update: Notepad++ 399 已新增。

2007-01-05

PCman alasing

PCMan for win32 的版本,針對英文與中文文章時,中文的 refresh 速度比英文慢,難道是 TryeType 的問題嗎?