想當年,用 28.8kbps 撥號上網,速度最高約 3KB/s
之後換了 56kpbs 的 modem撥號上網,速度最高約 6KB/s
後來家裏終於升級到「寬頻」,是 1.5Mbps ADSL 上網,速度最高約 150KB/s
隨著寬頻的發展,家中 ADSL 的速度提升到 3Mbps 再提升到 6Mbps,速度最高約 680KB/s
但這個一秒大約半MB的網速,還是和現在的速度有一段距離...
現在,家中網絡是「光纖入屋」,理論上可以達到 1Gbps 或以上的網速。
試想想,一間數據中心通常只有數 Gbps 的頻寬,在數據中心租用 1Mbps 專用頻寬的費用動輒每月數千港元,而我只需付不到二百元的月費,就可以安坐家中享受高達 300Mbps 的網速。
這樣說肯定會有人來說我不懂數據中心專用頻寬和家用上網和分別,但在香港普遍個人或家用上網服務是比較便宜的。
今次「網速比拼」主要想給自己留個紀錄,將來無論是網速再度提升,或是網絡供應商聯手大幅加價,都可以以此文章作參考。
家中網絡聲稱有 300Mbps
公司網絡聲稱有 50Mbps
租用 DigitalOcean 在新加坡的虛擬伺服器,1 Gbps port 是來真的 (但有每月總流量限制)
題外話,用手機 + Wi-Fi 上網的速度也不見得比電腦慢呢
星期五, 3月 27, 2015
簡單 ImageMagick convert 指令
縮放圖片以填滿指定大小:
Resize the image to fill the requested size. Some portion of the image may be clipped:
Resize the image to fit the requested size and maintaining the aspect ratio. Some portion of the output image may be blank:
Resize the image to the requested size ignoring the aspect ratio:
Obtain only the first frame in an animated GIF file:
Resize the image to fill the requested size. Some portion of the image may be clipped:
convert input.png -resize 100x100^ -gravity center -extent 100x100 output.png縮放圖片在指定大小以內:
Resize the image to fit the requested size and maintaining the aspect ratio. Some portion of the output image may be blank:
convert input.png -resize 100x100 -gravity center -extent 100x100 output.png縮放圖片到指定大小,不保持長寬比例:
Resize the image to the requested size ignoring the aspect ratio:
convert input.png -resize 100x100\! output.png取GIF動畫的第一格:
Obtain only the first frame in an animated GIF file:
convert input.gif\[0\] output.png
星期三, 1月 21, 2015
簡單 ffmpeg 使用
由於版權問題 ffmpeg 官網並不提供已編譯的二進位執行檔下載。建議自己編譯 ffmpeg 的原始碼,或者從官方推薦的第三方網站下載已編譯的二進位執行檔:
Mac 版 ffmpeg 下載: http://evermeet.cx/ffmpeg/
Win 版 ffmpeg 下載: http://ffmpeg.zeranoe.com/builds/
下載 HKTV m3u8 影片
Mac 版 ffmpeg 下載: http://evermeet.cx/ffmpeg/
Win 版 ffmpeg 下載: http://ffmpeg.zeranoe.com/builds/
下載 HKTV m3u8 影片
ffmpeg -i m3u8網址 -strict -2 hktv.mp4剪片 (時間格式:時:分:秒.千分一秒 00:00:00.000) 參考文章
ffmpeg -ss 開始時間 -i 原影片檔案路徑 -t 長度 -c copy -avoid_negative_ts 1 output.mp4轉換成 mp4
ffmpeg -i 原影片檔案路徑 -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4合併字幕 (注意: 需要開啟 libass 支援) 參考文章
# 合併ass字幕: ffmpeg -i 原影片檔案路徑 -vf "ass=字幕檔.ass" -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4 # 合併srt字幕: ffmpeg -i 原影片檔案路徑 -vf "subtitles=字幕檔.srt" -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4合併多段影片 參考文章
ffmpeg -f concat -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4(將會持續更新...)
星期五, 10月 24, 2014
常用 curl 指令
將網頁內容直接輸出到螢幕上:
傳送 POST 資料:
curl 網址將網頁內容儲存到檔案:
curl -O 網址將網頁內容儲存到指定檔案名稱:
curl -o filename.txt 網址捨棄網頁內容:
curl 網址 > /dev/null捨棄所有輸出:
curl 網址 2>&1 > /dev/null 或者 curl -s 網址 > /dev/null捨棄所有輸出並在背景執行:
curl 網址 2>&1 > /dev/null &
傳送 POST 資料:
curl -d "name=howang&foo=bar" 網址傳送 Cookie 資料:
curl -b "cookie1=hello;cookie2=world" 網址允許不受信任的 SSL 證書:
curl -k 網址更改 User-Agent: (這裏以Chrome作示範)
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36" 網址加入 HTTP Referer:
curl -e "http://www.example.com" 網址加入自訂 HTTP Header:
curl -H "X-Test: foo" 網址指定 HTTP request method:
curl -X GET 網址登入 HTTP Basic Authentication:
curl -u "username:password" 網址跟隨 HTTP 重新導向:
curl -L 網址囉唆模式: (除錯用)
curl -v 網址
星期三, 3月 06, 2013
在 linux 上使用 gitolite 架設 git 伺服器
基本上按著 gitolite 官方說明就可以,唯一難題是官方說明書沒教我們怎開設 gitolite 專用的登入帳號,花了點時間 Google 就有答案了。
adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git # copy my public key file (howang.pub) into /home/git cp howang.pub /home/git/ chown git:git /home/git/howang.pub # switch to the git user su - git # install and setup gitolite git clone git://github.com/sitaramc/gitolite mkdir -p $HOME/bin gitolite/install -to $HOME/bin bin/gitolite setup -pk howang.pub exit # clone the gitolite-admin repo git clone git@localhost:gitolite-admin cd gitolite-admin # here I edit the config files and add public keys # after that, commit and push to apply the new configurations git commit -m "updated config" git push origin master
星期四, 1月 17, 2013
Raspberry Pi 筆記
第一步,更新:
安裝並轉用 vim:
設定 reverse tunnel:
安裝 VNC:
安裝 Firefox:
安裝 Chrome:
播放 MP3:
設立 AirPrint:
設定時區:
播放 H.264 / MP4 影片:
暫停/繼續一個 process:
(將會持續更新...)
sudo apt-get update sudo apt-get upgrade -y
安裝並轉用 vim:
sudo apt-get install vim sudo update-alternatives --config editor
設定 reverse tunnel:
sudo apt-get install autossh # allow connect to SSH via port 65522 on server.tld autossh -NfR 65522:localhost:22 user@server.tld # add the above line with @reboot prefix in crontab crontab -e
安裝 VNC:
sudo apt-get install tightvncserver # run it once to set password tightvncserver # start vnc server with display 0 at 1920x1080 resolution vncserver :0 -geometry 1920x1080 -depth 24
安裝 Firefox:
sudo apt-get install iceweasel
安裝 Chrome:
# Install ttf fonts sudo apt-get install ttf-mscorefonts-installer ttf-wqy-zenhei # Install Chromium (Open Source version of Chrome) sudo apt-get install chromium-browser
播放 MP3:
sudo apt-get install alsa-utils ntpdate mpg123 python-virtualenv libshout3 libshout3-dev pkg-config python-dev sudo modprobe snd_bcm2835 sudo amixer cset numid=3 1 mpg123 filename.mp3
設立 AirPrint:
sudo apt-get install avahi-daemon avahi-discover libnss-mdns cups cups-pdf python-cups sudo usermod -aG lpadmin pi # add "Allow from @Local" to Location section of / , /admin and /admin/conf sudo vim /etc/cups/cupsd.conf # add mine types for AirPrint sudo echo '# # "$Id: $" # # AirPrint type image/urf urf string(0,UNIRAST<00>) # # End of "$Id: $". # ' | sudo tee /usr/share/cups/mime/airprint.types > /dev/null sudo echo '# # "$Id: $" # # AirPrint # Updated list with minimal set 25 Sept image/urf application/pdf 100 pdftoraster # # End of "$Id: $". # ' | sudo tee /usr/share/cups/mime/airprint.convs > /dev/null sudo service cups restart ### go to https://raspberrypi:631/ and setup the printer # download and run the airprint-generate script wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py chmod 0755 airprint-generate.py sudo ./airprint-generate.py -d /etc/avahi/services sudo service avahi-daemon restart 00>
設定時區:
sudo dpkg-reconfigure tzdata
播放 H.264 / MP4 影片:
omxplayer filename.mp4 ### Key bindings # Key Action # 1 Increase Speed # 2 Decrease Speed # j Previous Audio stream # k Next Audio stream # i Previous Chapter # o Next Chapter # n Previous Subtitle stream # m Next Subtitle stream # s Toggle subtitles # q Exit OMXPlayer # Space Pause/Resume # p Pause/Resume # - Decrease Volume # + Increase Volume # Left Seek -30 # Right Seek +30 # Down Seek -600 # Up Seek +600
暫停/繼續一個 process:
kill -STOP <pid> kill -CONT <pid>
(將會持續更新...)
星期一, 1月 14, 2013
不用任何外置裝置在 MacBook Air 上重裝 Window 7
標題很長,但因為我的處境太奇怪,所以只好寫成這樣...
方法主要根據 SevenForums 上的 How to Install Windows 7 FAST without a DVD or USB Device,再加上幾個步驟。
我的處境:
方法主要根據 SevenForums 上的 How to Install Windows 7 FAST without a DVD or USB Device,再加上幾個步驟。
我的處境:
- 電腦: Apple MacBook Air
- 沒有光碟機
- 沒有 USB Disk
- 主系統: Mac OS X 10.8
- BOOTCAMP 系統: Windows 8
使用軟件:
- VMware Fusion 5
- Windows XP
- ImageX
目的: 移除超難用而且兼容性太低的 Windows 8,重新安裝 Windows 7
步驟:
- 在 OS X 上,使用 vmware-rawdiskCreator 製成一個指向 BOOTCAMP 硬碟分割的 vmdk 檔案
- 修改我原有的 Windows XP VM(虛擬機) 的 VMware 設定檔 (vmx 檔),為 VM 加入 BOOTCAMP 硬碟
- 啟動 Windows XP VM,在 VMware 中掛載 Window 7 的 ISO 檔
- 在 XP 中格式化 BOOTCAMP 硬碟分割
- 根據 How to Install Windows 7 FAST without a DVD or USB Device 的方法,使用 ImageX 工具把 Windows 7 的 install.wim 套用到 BOOTCAMP 碟碟分割中
- 把 Windows XP VM 關機,修改 vmx 檔,刪去原有 Windows XP 的虛擬硬碟
- 重新啟動 Windows XP VM,這次使用 Windows 7 的 ISO 檔 boot 機,選擇 "Repair my computer" 並開啟 Command Prompt (命令提示字元)
- 輸入:
- 把 Windows XP VM 關機(重要:千萬不要在 VM 中用 BOOTCAMP 碟碟分割開機,會令安裝失敗的)
- 重新啟動電腦,使用 BOOTCAMP 開機,Windows 7 會自動完成安裝 ^.^
/Applications/VMware\ Fusion.app/Contents/Library/vmware-rawdiskCreator create /dev/disk0 1 "/Users/howang/Desktop/bootcamp" ide
ide0:0.present = "TRUE" ide0:0.fileName = "/Users/howang/Desktop/bootcamp.vmdk"
imagex /apply d:\sources\install.wim 5 e:\
c:\windows\system32\bcdboot c:\windows d:\boot\bootsect /nt60 c:
星期三, 3月 18, 2009
星期三, 10月 03, 2007
學校check學生的xanga?
一看標題,咦!?不是舊聞嗎?對!不過基於某些原因近日我回想此事有感而發,希望分享一下意見。很多人在forum大吐苦水,學校追究他/她在xanga上寫的言論,受害人多數認為xanga是私人的網上日記,不應被學校干涉。其實受害人的xanga本身可以在網上被任何人觀看,既然寫了在xanga上,就要有心理準備該日記會被任何人閱讀,受害人根本沒有考慮這一點,就把很多不見得人的文字寫上,被看到被追究是自找的。沒錯我自己也曾把不能被某些人看見的事寫在網誌中,但很多到了現在被那些不應看到的人看到也不重要了。我也曾利用xanga去查看究竟別人怎樣看我,當然寫的人不會直接對我說,但這卻令我知道那些人喜歡我,那些人討厭我,從而進行自我反思,並找出別人討厭我的原因,繼而改善我的待人接物態度,取得更好的人際關係,但世人並不是個個都像我,現實中,看的可能是老闆,可能是上司,也可能是敵人,結果會是怎樣,也不用多說吧。如果大家有什麼不吐不快,不妨試試隱藏自己的身份,又或者善用blogger的權限管理,打造真正私人的網誌。
xanga?算把啦,支持blogger無廣告、速度快!
xanga?算把啦,支持blogger無廣告、速度快!
星期四, 8月 30, 2007
初試咩機之軟件心得
擁有一部咩機*已經一個星期了,努力熟習中。
軟件心得篇 ﹣ 硬件買左就冇得變,唯有軟件可以變。
軟件心得篇 ﹣ 硬件買左就冇得變,唯有軟件可以變。
- 作業系統: Mac OS X Tiger 10.4.10 (使用語言:繁體中文)
- 瀏覽器: Firefox 2.0.0.6 & Safari 2.0.4 (419.3)
- 電郵: Gmail , Web-base mail interface , no additional software required
- 圖片管理: iPhoto (iLife '08)
- 圖像編輯: GIMP 2.2.11
- 音樂播放: iTunes 7.3.2(6)
- 音訊編輯: Audacity 1.2.5
- 影片播放: QuickTime 7.2.0 (component: Perian 1.0)
- 影片編輯: iMovie & iDVD (iLife '08)
- 光碟燒錄: SimplyBurns rev275(275)
- 文字編輯: Smultron 3.1.2
- P2P軟件: Azureus 3.0.2.0 (BitTorrent)
- 辦公室軟件: NeoOffice 2.2.1 (modified version of OpenOffice.org 2.2.1)
- 開發環境: NetBeans IDE 5.5.1 (Java) & Zend Studio 5.5.0 (PHP)
- 即時通訊: Adium X 1.1.1 & Microsoft Messenger:Mac 6.0.3 (070803)
- 虛擬電腦: Windows XP SP2 on VMWare Fusion 1.0 (51348)
- Dashboard: iTunes, Dictionary, Translator, Clock, Calculator, Notes, Google
- 系統分析: TechTool Deluxe (free with AppleCare Protection Plan)
星期一, 7月 09, 2007
血海中的小孩
在這個已經發展成熟,競爭激烈的電腦世界,大公司殺得天昏地暗,細公司積極取得少量的市場,並與大公司合作,最終被收購。市的的競爭令廿年前的藍海,變成一片血紅,誰想佔一席位?除非有極出眾的新產品及極成功的推銷手段,並且有堅定的立場不被收購合併,否則很快會成為這個血海中的血,因為這參與者的實力太低,根本不能和大公司們競爭,螳臂擋車,結果就是一敗塗地,又或者被收購、被合併,辛苦打造出來的品牌,一下子就沒有了。
我就像這個血海中的一個小孩,正努力地找尋生存空間,但這點不容易做到,因為這小孩沒有大公司的財力,有的只是技術和少許﹝少得就像沒有﹞的錢,希望能維持一段時間,但可借這小孩根本就負擔不來。這小孩曾有過自己的獨立伺服器,有過安裝及管理Linux伺服器的經驗,編寫及管理過幾個網站,但他並沒有在這些網站上取得大公司們做相同的網站所取得的利潤,反而因伺服器機件老化而最終要關閉網站。他曾有過兩個討論區,曾努力發表有用的技術文章,可惜無論他多努力,網友們寧願到一些大的討論區看那些從他那處抄回來的文章,也不會去看他的。討論區的會員數沒錯是不停地增加中,但活躍的會員數由本身有的十多名跌到沒有,連他自己都沒有心情去發表了,根本就沒人會看,寫不寫也罷。就這樣,這個血海中的小孩唯有放棄,生存實在是太困難了。
小孩現在再次張眼四看,看不到一個生存點,看到的只是一望無際的血水,有自己的,也有其他參與者的。在這個血海中,那裏會有一小片藍海還未受血淺,可以供他生存的一點點空間?
我就像這個血海中的一個小孩,正努力地找尋生存空間,但這點不容易做到,因為這小孩沒有大公司的財力,有的只是技術和少許﹝少得就像沒有﹞的錢,希望能維持一段時間,但可借這小孩根本就負擔不來。這小孩曾有過自己的獨立伺服器,有過安裝及管理Linux伺服器的經驗,編寫及管理過幾個網站,但他並沒有在這些網站上取得大公司們做相同的網站所取得的利潤,反而因伺服器機件老化而最終要關閉網站。他曾有過兩個討論區,曾努力發表有用的技術文章,可惜無論他多努力,網友們寧願到一些大的討論區看那些從他那處抄回來的文章,也不會去看他的。討論區的會員數沒錯是不停地增加中,但活躍的會員數由本身有的十多名跌到沒有,連他自己都沒有心情去發表了,根本就沒人會看,寫不寫也罷。就這樣,這個血海中的小孩唯有放棄,生存實在是太困難了。
小孩現在再次張眼四看,看不到一個生存點,看到的只是一望無際的血水,有自己的,也有其他參與者的。在這個血海中,那裏會有一小片藍海還未受血淺,可以供他生存的一點點空間?
星期二, 11月 28, 2006
javascript xEmail() function
今天我在 three.com.hk 上找到這段javascript程式碼:
錯左一樣野。睇睇第七行幾白痴!乜呢個世界只係得.com .net .org !?three.com.hk 個個月食幾千至幾萬蚊人工的程式員冇聽聞過 .biz .us .cc .hk .tv 之類的 domain 咩?簡直係 programmer 的恥辱!我現在以一個熱愛編程的人這個身份對 three.com.hk 作出強烈的遣責,並要求該班程式員立即作出改善!我不希望這些不完善的垃圾程式碼會再次出現在一個 production system 上!!!
| function xEmail(strEmail) { invalidChars ="~!$^&\*()+|=`\"\'"; if (strEmail==null || isWhitespace(strEmail)) return false; if (strEmail.indexOf(' ') > -1) return false; if ((strEmail.indexOf(".com") == -1) && (strEmail.indexOf(".net") == -1) && (strEmail.indexOf(".org") == -1)) return false; for (ai=0;ai if (strEmail.indexOf(badChar,0) > -1) { return false; } } atPos = strEmail.indexOf("@",1); if (atPos ==-1) return false; if (strEmail.indexOf("@",atPos+1) > -1) return false; if (strEmail.indexOf("@.",1) > -1) return false; if (strEmail.indexOf("..",1) > -1) return false; periodPos = strEmail.indexOf(".",atPos); if (periodPos == -1) return false; if (periodPos+2 > strEmail.length) return false; return true; } |
錯左一樣野。睇睇第七行幾白痴!乜呢個世界只係得.com .net .org !?three.com.hk 個個月食幾千至幾萬蚊人工的程式員冇聽聞過 .biz .us .cc .hk .tv 之類的 domain 咩?簡直係 programmer 的恥辱!我現在以一個熱愛編程的人這個身份對 three.com.hk 作出強烈的遣責,並要求該班程式員立即作出改善!我不希望這些不完善的垃圾程式碼會再次出現在一個 production system 上!!!
星期六, 10月 15, 2005
USL get onto SourceForge.net!
Well, today sf.net approved my registation of the USL(USB System Lock) project. It is a great solution to enhance system security. This program enable us to use a physical USB Drive to be a key to unlock the computer. Without the key, the computer will be locked by the program and cannot access by anyone. Nowadays, security become more and more important, so I am sure that this program will become very popular soon! Visit the USB System Lock webpage at http://usl.sf.net/ !
星期一, 9月 26, 2005
Valid email address correctly (PHP)
Nowadays, valid the format of the email is not enough, so, we need to valid it with making a testing connection to the email server and ask the email server that the user provided if the email account exisit! Here is a PHP function that can do this for you:
<?php
/* Return value: (true|false)
true if valid, false if invalid */
function valid_email($email)
{
global $HTTP_HOST;
if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)) {
return false;
}
list($username,$domain) = split("@",$email);
if (checkdnsrr($Domain,"MX")) {
getmxrr ($Domain, $mxhost);
$host = $mxhost[0];
}
else {
$host = $domain;
}
$connect = fsockopen($host,25};
if ($connect) {
if (ereg("^220", $returns=fgets($connect,1024))) {
fputs($connect,'HELO ' . $HTTP_HOST . "\r\n");
$returns = fgets ($connect,1024);
fputs($connect,'MAIL FROM: <' . $email . ">\r\n");
$test1 = fgets($connect,1024);
fputs ($connect,'RCPT TO: <' . $email . ">\r\n");
$test2 = fgets($connect,1024);
fputs ($connect,"QUIT\r\n");
fclose($connect);
if ((!ereg("^250",$test1)) or (!ereg("^250",$test2))) {
return false;
}
}
}
else {
return false;
}
return true;
}
?> 星期一, 8月 01, 2005
A better way to detect IP in PHP
Sometimes we cannot get the correct IP of the client by $_SERVER['REMOTE_ADDR'], so we need the following function!
<?php
function getrealip()
{
$ip = FALSE;
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ips, $ip);
$ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
if (version_compare(phpversion(), "5.0.0", ">=")) {
if (ip2long($ips[$i]) != false) {
$ip = $ips[$i];
break;
}
} else {
if (ip2long($ips[$i]) != -1) {
$ip = $ips[$i];
break;
}
}
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
?>星期日, 7月 31, 2005
Simple language detect function(PHP)
Well, I have some extra time so I develop this code snippet.
Hope this works.
<?php
function hw_delectlang() {
if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) == 'en'){
$lang = 'en'; //English
} elseif (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) == 'zh'){
if ((substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],3,2) != 'cn') && (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],3,2) != 'sg')){
$lang = 'cht'; //Chinese Trad.
} else {
$lang = 'chs'; //Chinese Simp.
}
} else {
$lang = 'en'; //Default is English
}
return $lang;
}
?>
Hope this works.
星期三, 6月 08, 2005
PHP & Java both have their 10 years old birthday in this month
Well, today is the PHP's 10 years old birthday! And Java will have its 10 years old birthday in this month too! As a PHP programmer, I think today is quite special and I should do something special today!
訂閱:
文章 (Atom)




