2007-05-29

High-efficiency power supplies for home computers and servers (pdf)

簡化裡面的元件可以省能源,只是週邊的採購也要能配合。

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 的問題嗎?

2006-12-25

libc6-dev

stdio.h is in libc-dev package.

GNU C Library: Development Libraries and Header Files

2006-12-18

youtube-dl

youtube-dl is a small command-line program to download videos from YouTube.com. It requires the Python interpreter, version 2.4 or later, and it's not platform specific. It should work in your Unix box, in Windows or in Mac OS X. The latest version is 2006.12.07. It's licensed under the MIT License, which means you can modify it, redistribute it or use it however you like complying with a few simple conditions.

http://www.arrakis.es/~rggi3/youtube-dl/

2006-12-08

agup daily

I've been execute "apup" to "sodu apt-get upgrade" daily, it's more than edgy distribution, so it's a experiment one. I am afraid of that there're many holes in my box, that if I haven't update one.