[Vim] 將 Tab 轉換成 Space

Update 2010.08.28: Pspad 轉換既有 Tabs to Spaces by bootleq 為了統一 Windows 跟 Linux 底下的編輯器在使用 Tab 功能相同,所以調整了 Vim 及 Pspad(我常用編輯器)的設定,底下是針對 Vim 及 Pspad 的解決方法。首先當大家使用 Vim 編輯器撰寫程式,常常會使用 Tab 來縮排程式碼,我們可以使用 expandtab 來插入空白鍵(Space)取代 Tab: 1 :set expandtab 控制插入 Tab 時所需要的空白鍵(Tab)字元數,例如用4個空白鍵取代 Tab: 1 :set tabstop=4 在我們設定完 expandtab 之後,所有的 Tab 鍵將會被 Space 所取代,但是原本在檔案文件中的 Tab 將不會改變,為了取代原有的 Tab 到新的設定,我們必須鍵入: 1 :retab 針對程式縮排所需要的 Space 個數,我們可以使用 shiftwidth 選項 1 :set shiftwidth=4 底下舉個例子: 將文件中 Tab 取代成 Space 所有 Tab 用4個 Space 取代 1 2 3 :set tabstop=4 :set shiftwidth=4 :set expandtab Pspad 設定 Settings -> Programing Settings -> Editor (Part 2) [Read More]
Vim 

Html5 模板架構(Boilerplate)

HTML5 Boilerplate - A rock-solid default for HTML5 awesome._1282574693481 今年在 COSCUP 大會上最主流的議題就是 Html5,今天看到一個網站 HTML5 Boilerplate,這網站提一個全新 html 5 模板,自從離開 Dreamweaver 樣板軟體,利用 Pspad 手動撰寫 html,此網站就發揮非常大的用處,提供全新 html,CSS 以及 javascript,支援了底下很多功能:

  • 跨瀏覽器 (IE6…)
  • 支援多種 html5 Tag
  • Compress 和 cache html 檔案
  • CSS IE6 , IE7 Hack
  • IE6 Png Fix (連這個都幫忙解決了)
  • 支援 CDN jQuery,避免在 local 端沒讀取到檔案 你還可以根據自己需要的功能做添加或者是減少,CSS reset、跨瀏覽器 CSS、robots.txt、Apache .htaccess cache 壓縮也有支援,如果不需要的功能,也可以參考看看,對於初學者也是非常好的學習例子。

Git 版本控制:利用 git reset 恢復檔案、暫存狀態、commit 訊息

這次來介紹一下 git reset 的用法,為什麼會介紹這指令呢?因為今天想要看專案狀態,用 git status 觀看,發現被我玩爛了,所以出現了底下錯誤訊息:

$ git status
error: bad index file sha1 signature
fatal: index file corrupt
解決此問題非常簡單,要先刪除 index 檔案,請先砍掉

.git/index,恢復此 index 請用

git reset
這行指令相當於

git reset –mixed HEAD,或者是可以用 git read-tree 來取代 git reset,當然 git reset 不只是有這功能而已,假如您已經建立了 commit 訊息,也可以將此訊息拿掉,重新在 commit,或者是您修改過的檔案在暫存區,git 也可以幫您恢復到未暫存,或者是不想要這次的修改,也可以恢復到未修改的檔案喔。

取消已經暫存的檔案 假如我們有兩個檔案需要 commit,但是不小心按到 git add * 全部加入到暫存區,那該怎麼恢復呢?

# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       modified:   Makefile
#       modified:   user/easy_setup/easysetup.h
#
上面是以經在暫存區裡面等待被 commit 檔案(

Changes to be committed),大家可以看到括號裡面有提示如何拿掉 (use “git reset HEAD …” to unstage),所以我們下:

git reset HEAD user/easy_setup/easysetup.h
之後會看到 『

user/easy_setup/easysetup.h: locally modified』此訊息,這時候在用 git status 看狀態

# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       modified:   Makefile
#
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#
#       modified:   user/easy_setup/easysetup.h
#
[Read More]

Git 版本控制: 「You have some suspicious patch lines」

相信大家對 Git 並不陌生,這次在升級 Moztw 的討論區,從 3.0.5 升級到 3.0.7 p1,過程由其他 Moztw 成員升級,我在將最後程式 commit 到 github,因為兩個版本差異性很大,所以有新增多個檔案,commit 過程出現了錯誤訊息:「You have some suspicious patch lines」,這是因為 git 會檢查每行程式碼最後是否有多餘空白或者是 Tab 按鍵,為瞭解決此問題,可以去修改 .git/hooks/pre-commit,將底下程式碼: if (s/^\+//) { $lineno++; chomp; if (/\s$/) { bad_line("trailing whitespace", $_); } if (/^\s* \t/) { bad_line("indent SP followed by a TAB", $_); } if (/^([<>])\1{6} |^={7}$/) { bad_line("unresolved merge conflict", $_); } } 改成: if (s/^\+//) { $lineno++; chomp; # if (/\s$/) { # bad_line(" [Read More]

[C/C++] cstring (string.h) 函式:strcat, strncat, strcmp, strncmp

串接函式 strcat strcat 此函式用來連接兩字串合併成單一字串,直接看底下範例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* strcat example */ #include <stdio.h> #include <string.h> int main () { char str[80]; strcpy (str,"these "); strcat (str,"strings "); strcat (str,"are "); strcat (str,"concatenated."); puts (str); return 0; } output: 1 these strings are concatenated. 看一下 strcat 原始碼: 1 2 3 4 5 6 7 8 9 char * strcat(char * __restrict s, const char * __restrict append) { char *save = s; for (; *s; ++s); while ((*s++ = *append++)); return(save); } 設定指標 save 成 source,再將 s 指標指向最後,接下來根據 append 字串一個一個往後串接,直到碰到 \0 終止 while 迴圈,最後在將指標 *save 回傳即可。 [Read More]

[C/C++] cstring (string.h) 搜尋函式:strstr, strchr

這次介紹 C 語言常用 string 函式:strstr,主要是針對兩個輸入參數做比對,Parameters 1 是輸入字串,Parameters 2 是找尋字串,strstr 會先將頭一次比對成功的 pointer 回傳,也就是如果要找尋 appleboyappleboy 字串中的 boy,函式會回傳第一次比對成功的 boy pointer,而並非回傳最後一個比對到的,底下是一個參考範例: strstr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* strstr example */ #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; /* 找尋 simple 字串 */ pch = strstr (str,"simple"); /* 將 simple 換成 sample */ strncpy (pch,"sample",6); puts (str); return 0; } 看一下 Kernel 原始檔案,strstr 函式: [Read More]

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C# C# 比較字串 MSDN 比較字串 Request.Form Collection Request Query String / Form Parametrs ASP.NET QueryString Usage Using include files with ASP.NET html [將所有 的內容包到一個 中][7] apache Fixing mod_rewrite and .htaccess on GoDaddy Hosting javascript jQuery Week Calendar Javascript: reference the parent window from a popup How to get and set form element values with jQuery How to check and uncheck a checkbox with jQuery Loop through parameters passed to a Javascript function perl-completion. [Read More]

[Kernel Driver] 撰寫簡易 Timer 機制

在底層 Linux Kernel 提供了時序(timing)機制,方便驅動程式設計者所使用,核心是依據硬體發出的『計時器中斷』來追蹤時間的流動狀況。我們可以依據 HZ 的值來設計 Delay 機制,讓驅動程式可以每隔固定一段時間啟動或者是發出訊號,也可以利用 Timer 來讓 LED 閃爍變化,在介紹 Timer API 之前,可以先參考 Linux Kernel: 簡介HZ, tick and jiffies 這篇文章,瞭解一些相關名詞,舉例:如果想知道一秒後的 jiffies 時間,可以寫成底下: #ifdef CONFIG_BMA150_TIMER #include #endif j = jiffies; /* 一秒之後 */ stamp_1 = j + HZ; /* 半秒之後 */ stamp_1 = j + HZ/2; /* 20秒之後 */ stamp_1 = j + 20*HZ; Timer API 用法 筆記一下自己在寫 BOSCH Sensortec 三軸加速偵測器(BMA150 Sensor) Driver 的時候,遇到底層要回報 input event X,Y,Z 到 Android HAL(Hardware abstraction layer),所以利用 Timer 的機制定時 report 給 Android。 首先宣告: [Read More]

[Linux Kernel] 簡單 hello world: License and Module 介紹(part 3)

在 Kernel 2.4 或以上版本,在編譯模組完成,要進行 load module 之前,你會發現底下訊息: # insmod hello-3.o Warning: loading hello-3.o will taint the kernel: no license See http://www.tux.org/lkml/#export-tainted for information about tainted modules 很顯然這訊息是要您在 kernel module 裡面加上版權宣告,例如:"GPL","GPL v2"…等來宣告您的 module 並非 open source,利用 MODULE_LICENSE() 巨集來宣告程式 License,同樣的,可以用 MODULE_DESCRIPTION() 來描述此模組或者是 Driver 的功用跟簡介,以及用 MODULE_AUTHOR() 來定義此模組作者,這些巨集都可以在 linux/module.h 裡找到,但是這些並非用於 Kernel 本身,如果大家想看範例程式,可以到 drivers/ 資料夾底下觀看每一個 Driver 程式,底下是簡單 hello world 範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 巨集需要檔案*/ #include static int __init hello_init(void) { pr_info(" [Read More]

[高雄美食]道明中學武廟路好吃愛嬌姨臭豆腐

IMG_1290

我相信在高雄要吃到好吃的臭豆腐,無非就是豪記臭豆腐,大家可以參考懶喵兒滴窩:『[高雄-三民]豪記臭豆腐王【港式臭豆腐專賣店】 (新址)』,但是這次要來介紹也許在高雄比較少人知道的路邊攤臭豆腐,它位於高雄市武廟路上一間不起眼的臭豆腐,道明中學對面巷子走進去接到武廟路就可以吃到了,營業時間是下午15:30~19:40,時間不長,但是大排長龍阿,想要去吃的,最好不要挑晚餐時間,因為自己那個時間去吃,至少等了半小時。

[Read More]