2008年2月29日星期五

MacBook Air

唉,澳大的假期太奇怪了
由上年十二月的聖誕假一直放到今個月的十八號
中間只有考試,完全不用上課
結果天天躲在家裏不知道干啥
人都變得十分秃癈

之前老媽的NoteBook要還給別人了
真不捨得,但老媽工作太辛苦受不了
學校也不讓她繼續干下去,沒辦法
結果來去如空
也罷
………………………………
老爸跟我說想買自己買一台就告訴他
但他自己一直想買車都沒錢
哪裏來一萬元OTL
自己又沒工作,真愁
加上Linear又Fail了
下年要重修
第一年就Fail了一科,以後都不知道怎麼辦
明明會寫Program,但成績實在強差人意
唉,前路芒芒

老爸還提起MacBook Air
說在報紙看到,超薄的NoteBook
Apple的市場策略真不賴呢
不止是老爸,我身邊的朋友都有提起
其實超薄的NoteBook它又不是第一台
掛着Apple的名字迴響就那麼大?
如果Sony的宣傳有它一半成功就好了
我朋友告訴我,賣游戲機的老闆都把PSP踩到垃圾不如
但他自己有賣PSP的
在香港賣PS3的鋪頭都叫客人買Wii和NDS
這樣的環境,可想而知Sony有多失敗

其實我一直都覺得Apple的産品賣得太貴
MacBook Air的那個配置
根本不值一萬三千大元
來到澳門時可能還不止萬三呢!
萬三可以買更好的NoteBook呢!

有趣的事,MacBook Air發佈會上
乔老說可以放進envelope
事實上它是從公文袋拿出來的
但全世界都翻譯成從信封拿出來
要知道,中國人對信封的理解和公件袋差很遠的呢~!

2008年2月23日星期六

自己動手寫os

看了標題是不是以為我會寫os呢
當然這是不可能的
只是介紹一本免費的eBook,叫「自己動手寫OS

此書的作者因為看了一本教書OS的書,但裏面用的都是商業軟件
於是他就試着用開源軟件實現書中的例子
最後就自己寫書了
先不管他寫的怎樣
但他這個行為值得學習的~

計算超長位數整數

今個星期開始了第二個學期的課(之前從聖誔開始就一直放假呀OTL)
Data的第一堂科就教了怎麼計算50位整數相加和乘法

花了兩天時間終於寫好了
現在給上代碼
………………………………
/* addtimes.c */
/* this program can do addition and multiplication for two very very long integers,
* the maximum range of digits is 1000, but it can change
* so the longest digits of addition is 1000 and
* the longest digits of multiplication is 500
* because multiply will have most double digits of the result
*
* the base principle of this program is save the long integer in an array
* digits by digits
* so when we need to do the addition
* just add two small integers which is one digits of the very very long integer
* and the multiplication also the same
*
* this program can add tow very very long integers,
* and it can mutiply very long integers
*
* Written by Jimmy DA728071
* @ 080223
* Ver 1.0
*/

#include <stdio.h>

/* define a mirco that is the maximum of the array */
#define MAX 10000

int Isdigit(char cha) {
/* this function can check a character is digital or not
* like the function "isdigit" in ctype.h
*/
int x = 0; /* the return value */

if (cha >= '0' && cha <= '9') {
x = 1; }

return x;
}
void carry(short int numbers[], int n)
{
/* this function can do the carry of an array
* after add or times calculation, can use this function to do carry */

int i; /* the index of an array */

for (i=0; i<n-1; i++) {
/* note that the heighest digit of result array also no need carry */
if (numbers[i] > 9) {
numbers[i+1] += numbers[i] / 10;
numbers[i] = numbers[i] % 10; } }

}

int add(const short int n1[], int nn1, /* the first long integer and the number of digits */
const short int n2[], int nn2, /* the second long integer and the number of digits */
short int result[]) /* the result */
{
/* this function do the add action */
int i, /* the index of two integer arraies */
nru; /* total number in calculate result */

if ( nn1 > nn2 ) {
/* if the integer n1 is longer than n2 */
/* the result should have same digits as the first integer */
nru = nn1;
/* start calculate the sum */
for (i=0; i<nn2; i++) {
/* just put the sum to the result array first */
result[i] = n1[i] + n2[i]; }
for (i=nn2; i<nn1; i++) {
/* get the leavings digit to result */
result[i] = n1[i]; } }

else if ( nn1 <= nn2 ) {
/* if the integer n1 is shorter than n2 */
/* the result should have same digits as the second integer */
nru = nn2;
/* start calculate the sum */
for (i=0; i<nn1; i++) {
/* just put the sum te the result array first */
result[i] = n1[i] + n2[i]; }
/* if two long integer is not as long as same,
* need to get the leavings digit to result */
if ( nn1 != nn2) {
for (i=nn1; i<nn2; i++) {
result[i] = n2[i]; } } }

/* then, check the carry */
carry(result, nru);

/* return the nru */
return nru;
}

int stimes(const short int n1[], int nn1, /* the first long integer */
int nn2, /* the multiplicator */
short int result[]) /* the calculation result */
{
/* this function do tha times action
* a simple multiplication action */
int nru, /* total number in calculate result */
i; /* the index of array */

/* count how many digit of the result integer */
nru = nn1;

/* start calculate, multiply one digit by one digit */
for (i=0; i<nn1; i++) {
/* just put the product to the result array */
/* here is a protype, so only multiply the first digit of n2 */
result[i] = n1[i] * nn2; }

/* then check the carry */
carry(result, nru);

/* return the nru */
return nru;
}

int ctimes(const short int n1[], int nn1,
const short int n2[], int nn2, short int result[])
{
/* this function do the complex multioplication action
* do this complex action, can separate to several simple multioplication
*/

int nru = 0, /* total number of digits in calculate result */
n = 0, /* mark which place of digit in the long integer */
mutor, /* the multiplicator */
nt1,
nt2, /* the number of digits inside temp integer */
i,
j; /* the index of array */
short int tn2[MAX],
tn1[MAX]; /* a temp integer */

/* the result must be had digits which is digits of n1 plus digits of n2 minus 1 */
nru = nn1 + nn2 - 1;

if (nn1 > nn2) {
/* if the first integer is longer than the second integer */

for (i=0; i<nn2; i++) {
/* clean the temp integer, just make it has none digit inside */
nt1 = 0;

/* put some zero after the integer, because after multiply the unidigit
* the multiplicator will have more 0,
* so put the 0 to multiplier make the calculation more easier */
for (j=0; j<n; j++) {
tn1[j] = 0;
nt1++; }
/* than copy the digits inside the first integer to temp integer */
for (j=0; j<nn1; j++) {
tn1[nt1] = n1[j];
nt1++; }
/* get the multiplicator from the second integer */
mutor = n2[i];
/* get the product of temp integer and multiplicator */
nt2 = stimes(tn1, nt1, mutor, tn2);
/* add the product to result */
nru = add(result, nru, tn2, nt2, result);
n++; } }

else if (nn1 <= nn2) {
/* if the first integer is shorter than the second integer
* or as same length as the second integer */

for (i=0; i<nn1; i++) {
/* clean the temp integer, just make it has none digit inside */
nt1 = 0;

/* put some zero after the integer, because after multiply the unidigit
* the multiplicator will have more 0,
* so put the 0 to multiplier make the calculation more easier */
for (j=0; j<n; j++) {
tn1[j] = 0;
nt1++; }
/* than copy the digits inside the second integer to temp integer */
for (j=0; j<nn2; j++) {
tn1[nt1] = n2[j];
nt1++; }
/* get the multiplicator from the first integer */
mutor = n1[i];
/* get the product of temp integer and multiplicator */
nt2 = stimes(tn1, nt1, mutor, tn2);
/* add the product to result */
nru = add(result, nru, tn2, nt2, result);
n++; } }

return nru;
}

void reverse(short int numbers[], int n)
{
/* this function using for reverse an array */
int i, /* the index of the array */
t; /* a temp valuable */

/* exchange the elements */
for (i=0; i<n/2; i++) {
t = numbers[i];
/* because n is the number of the elements,
* the index of the last element is n-1 */
numbers[i] = numbers[n-1-i];
numbers[n-1-i] = t; }

}

int main(void)
{
/* main function */

int nn2 = 0, /* how many numbers that user input in n2 */
nn1 = 0, /* how many numbers that user input in n1 */
nru = 0, /* how many numbers that in claculate result */
i = 0; /* the index of two long integer array */
char op = ' ', /* the operation that user want, read from input */
cha = ' '; /* the charact read from user input */
short int n1[MAX], /* the first long integer, save in an array */
n2[MAX], /* the second long integer */
result[MAX], /* the result of calculate */
mark = 0, /* mark that save the number to n1 or n2 */
over = 0; /* mark that the long integer is over range or not */

/* print out something so that user can know program started running */
printf(": ");

/* initial the n1, n2, result
for (i=0; i<MAX; i++) {
n1[i] = 0;
n2[i] = 0;
result[i] = 0; } */

/* read the input from user, the format like number1 + number2 */
/* because upper has used i, so initial i */
i = 0;
do {
cha = getchar();
if ( Isdigit(cha) && !mark ) {
/* if the charact that read from user is digital,
* put it into the number1's array */
/* because user input is charact, so need to convert into integer */
/* the charact 0 ~ 9 is in order, so just minus charact 0 */
n1[i] = cha - '0';
i++;
nn1++; }
else if ( Isdigit(cha) && mark ) {
/* if mark is true, it means the integer is n2 */
n2[i] = cha - '0';
i++;
nn2++; }
else if ( cha == '+' || cha == '*' ) {
/* if cha is + operation, that is the operation user input */
op = cha;
mark = 1;
i = 0; }
/* check the integer, if it is over range, print out an error message and exit */

} while ( cha != '\n' );

if ( over == 0 ) {
/* reverse the arraies
* infect, it's possible that do not do the reverse
* save the heightest digit in the 0 index
* but i like save it in the heightest index, so reverse it */
reverse(n1, nn1);
reverse(n2, nn2);

/* print out the result */
/* note that the highest digit is at the end of the array,
* because the array have beed reverse
* and the lowest digit should be the total number of digits minus one */
for (i=nn1-1; i>=0; i--) {
printf("%d", n1[i]); }
printf(" %c ", op);
for (i=nn2-1; i>=0; i--) {
printf("%d", n2[i]); }
printf("\n= ");

if ( op == '+' ) {
/* do the addition action */
/* check the two very long integer, confirm that they will NOT over range */
nru = add(n1, nn1, n2, nn2, result); }
else if ( op == '*' ) {
/* do the multiplication action */
/* check the two very long integer, confirm that they will NOT over range */
nru = ctimes(n1, nn1, n2, nn2, result); }

/* note that the result's order as same as two long integers */
for (i=nru-1; i>=0; i--) {
/* print out the calculate result */
printf("%d", result[i]); }

printf("\nProgram Exit!!\n"); }
return 0;
}

回想起某一天
在IRC上,有人問起怎麼計算200位整數開平方根
當時有人給出大大堆Lib叫他用
其實呢,我覺得這樣濫用API是不好的
應該抱着學習心態地去研究怎麼實現,而不應該全都用現成的代碼

不過人各有志~
別人喜歡怎麼做我都沒辦法的
只是見到有些人,因為自己知道有一堆API就以為自己是超厲害的高手
四處『認叻』
真討厭

2008年2月16日星期六

把bmp和png圖像轉換成jpg

寫了個小Script
是nautilus用的
可以把bmp和png格式的圖片轉換成70%質量的jpg
完全是因為壓縮比的關系
使用很簡單,儲存成XXX.sh
然後放到$HOME/.gnome2/nautilus-script/下面即可
在nautilus裏選取需要轉換的圖片(可以選好幾張)
右鍵 Script -> XXX.sh 即可
………………………………

#!/bin/bash
# This Script can convert the images which in png format or bmp format to jpg format with 70% quality
# User can use this Script to Compress the png images or bmp images to the jpg images which has a smaller size, but the jpg format images may not as clear as the original format images

#for i in $1
# get all files' path
# note: the file name can NOT content spaces
for i in $NAUTILUS_SCRIPT_SELECTED_URIS
do
# get the file name without 'file://'
imgne=`echo $i | cut -c8-`
echo $imgne
#zenity --info --text=$imgne
# get the position of the suffix of the file name
declare -i imnw=`echo $imgne | wc -m`-5
declare -i imnww=$imnw+1
# get the file name without suffix
imgnen=`echo $imgne | cut -c-$imnw`
# get the suffix of the file name
iinn=`echo $imgne | cut -c$imnww-`
# check the suffix is png or bmp
if [ "$iinn" = ".png" ]||[ "$iinn" = ".bmp" ]
then
# check that is any jpg file has the same file anme
# if yes, put a number after original file name
declare -i a=0
b='1'
while [ "$b" -eq "1" ]
do
a=$a+1
if [ -e $imgnen".jpg" ]
then
imgnen="$oimgnen""_"`echo $a`
else
b='0'
fi
done
# try to convert the image, and get the error message
mesg=`convert $imgne -format jpg -quality 70 $imgnen".jpg" 2>&1`
if [ "$?" = "0" ]
then
# if it is successful to convert, remove the original image
mv $imgne "$HOME"/.Trash/
else
# if it is not successful, print out an error message
zenity --info --text="[$imgne]Convert Not success!!!\n---\n$mesg"
fi
else
# if the input file is not a support format
zenity --info --text="Image format does NOT support!!!"
fi
done


還有一個Script是壓縮png的
因為mplayer截圖是沒壓縮過的png,太大了
所以要壓一下,但貌似壓縮比不算太過
我用來壓一張網上的圖,原來四百多K。壓完後變了八百多OTL
………………………………

#!/bin/bash
# This Script can compress the png format images
# Because png format is non-lossy compression format, so it can compress to a smaller size without any loss
# but it depend the compression level of the original image
# the highest compression level is 9
# User also can use this script to compress bmp images to png images
# it will NOT loss any details of the original image and the quality is same
# This script also has more one function, that is convert pdf file to png images
# because jpg format is lossy compression algorithm, the words in pdf file will NOT as clear as the original, but pdf does NOT have this problem.

#for i in $1
# get all files' path
# note: the file name can NOT content spaces
for i in $NAUTILUS_SCRIPT_SELECTED_URIS
do
# get the file name without 'file://'
imgne=`echo $i | cut -c8-`
echo $imgne
#zenity --info --text=$imgne
# get the position of the suffix of the file name
declare -i imnw=`echo $imgne | wc -m`-5
declare -i imnww=$imnw+1
# get the file name without suffix
imgnen=`echo $imgne | cut -c-$imnw`
# get the suffix of the file name
iinn=`echo $imgne | cut -c$imnww-`
# check the suffix to decide which command should use
# because png images no need to change the file name, but other images should change the suffix to png
# this is png images
if [ "$iinn" == ".png" ]
then
# try to convert the image, and get the error message
mesg=`convert $imgne -format png -quality 9 $imgne 2>&1`
if [ "$mesg" == "" ]
then
# if it is successful to convert, remove the original image
#mv $imgne "$HOME"/.Trash/
echo "Compress Finished!!!"
else
# if it is not successful, print out an error message
zenity --info --text="[$imgne]Convert Not success!!!\n---\n$mesg"
fi
# this is images which is other format
elif [ "$iinn" == ".bmp" ]||[ "$iinn" == ".pdf" ]
then
# try to convert the image, and get the error message
mesg=`convert $imgne -format png -quality 9 $imgnen".png" 2>&1`
# if the image file is NOT pdf, it should be remove
if [ "$mesg" == '' ]
then
# if it is successful to convert, remove the original image
if [ "$iinn" != ".pdf" ]
then
mv $imgne "$HOME"/.Trash/
fi
echo "Compress Finished!!!"
else
# if it is not successful, print out an error message
zenity --info --text="[$imgne]Convert Not success!!!\n---\n$mesg"
fi
else
# if the input file is not a support format
zenity --info --text="Image format does NOT support!!!"
fi
done

2008年2月15日星期五

仮面ライダーキバ

Kiva
………………………………

新的仮面騎仕-牙
是電王之後的新仮面騎仕
今次的造型相當不錯,主題是蝙蝠
維基,牙是繼555後井上敏樹再次擔壬腳本
而且是石森障太郎70周年記念作
應該不錯的~

不過最重要的是,土豆上有得看!
(剛剛發現,連甲斗都有!)
雖然土豆的速度不怎麼快,但總算有得看~

Vexille - 日本鎖國

日本鎖國,據說是Apple Seed監督的新作
於2007年8月時上映
內容大概就是講日本封鎖國家進行生化實驗
由於科技發達,聯合國禁止生化技術的研究。於是日本就鎖國進行實驗
還用全國國民做實驗體,注射金屬病毒。感染者會慢慢變成生化人
我就不再作甚麼介紹了,想看的話在騾仔上搜vexille吧~
………………………………
看完後覺得不錯~
打鬥部份雖然只有開頭一小段
但我不是為了看他們打打殺殺的
故事性很好,結构完整
與Apple Seed和其他SF作品一樣,最後留下一個耐人尋味的結局
Maria最後說的那句
我覺得像是講「再見」
好明顯,她是想成全SWORD那兩個「幸存者」-- Vexille和Leon
其實我比較感興趣的是,到底Leon有沒有被金屬病毒感染
看那個腦殘大和重鋼社長拿着有病毒的針筒不知干啥
有沒有給Leon注射了都不清濋
如果我是監督,我就會改成Vexille留在日本成為統治者
Leon被病毒感染了,和Maria一起隱居

貌似受感染的人不一定會掛掉,幸運的話會變成完全體
長生不死的~
Leon和Maria會不會掛掉變成垃圾就留代觀眾去想像~

看完後回想起Apple Seed的結尾
デュナン並沒有成功輸入密碼,但最後那些炮台還是停止了
聽說是七老人的禮物
其實我都不清濋
但那時有能力做這件事的似乎也只有七老人了
或者七老人見到她的努力,最後卻還差幾隻字。就幫她輸入完

其實Apple Seed的感覺和Vexille不太一樣
Apple Seed更古怪,伏筆太多而且很多要點都缺了
不過這就是改篇動畫的缺點
由於是改篇的,加上動畫的時間有限,沒法包括原作的全部內容
有缺漏是正常的事
我們觀眾只需要知道當中發生的事就可以了,不必太過考究

中文字支離破碎


看上圖
那些中字都是支離破碎的!
研究了源碼
發現CSS中指定了「新細明體」
Google一下就發現,Linux裏用微軟的新細明體字會爛掉的!
其實可以直接刪掉該字體
不過這裏有一個解決辦法
Firefox 偏好設定 => 內容 => 字型與色彩裏的進階 => 取消勾選優先使用網頁指定的字型

這樣顯示就沒問題了~
試試看吧~

2008年2月2日星期六

M+Y

微軟收購Yahoo了~
看晚間新聞才知道
微軟居然想把這麼大間的Yahoo呑了
其實我不認為這對微軟有利的,難道那個搜尋引擎市場份額真的那麼重要?
老實說,微軟的Live Search真的是超級差,你呑了Yahoo後希望會有所以變吧
………………………………
想起以前YM和MSN互通,有今天的收購是意料中事
(貌似現在還沒完成交易)
而我一直用yahoo的E-mail作為MSN ID也算了合理了(以前一直都想轉回hotmail的)
之前傳的Live Messenger和Gtalk互通,我反而覺得不好
一來現在的Live Messenger能好好的用了
emesene的SVN版已經可以接收檔案
二來互通頂多也是文字互通,意義不大
MSN的語音聊天我覺得很有趣,但互通了也不會帶給Gtalk的
所以現在我最希望的是Skype能加入Gtalk
加入XMPP這個大家庭~
這樣Linux下也能用Gtalk進行視頻聊天了~
現在Linux下只有Skype能進行視頻&語音聊天
所以我一直都很希望能玩Skype
但奈何我的朋友都用Live Messenger的
真的互通了那就有更多人用Skype了~

2008年2月1日星期五

3.90M33

昨天搜尋psp vnc時無意中在這裏發現了3.90M33
於是我立刻拿PSP出來,試試按網絡升級
果然能升到3.90M33
網絡升級下載回來的只有升級的installer
期間它還會幫我上網下載3.90官方固件
真方便~

熱門文章