星期三, 5月 20, 2015

2015 網速比拼

想當年,用 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:
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 影片
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 指令

將網頁內容直接輸出到螢幕上:
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