2013-02-19

[Git] 列出 commit 中的異動檔案

查看 commit 記錄

$ git show <commit>

但這樣沒辦法清楚列出到底是有哪些檔案有異動

只顯示異動的檔案,不顯示程式碼的話,請加上 --name-only 的參數

$ git show --name-only <commit>


要更進一步的只顯示檔案,連 commit 的相關資料也不要顯示的話

$ git show --pretty="format:" --name-only <commit>

以上,簡單的列出檔名

Reference:

git show - List all the files for a commit in Git - Stack Overflow

2012-01-24

[BH] 幫 Blogger 加上 "SyntaxHighlighter" 的功能

身為一個工程師,想要寫篇文章放到 blog 時,常常會遇到一個問題。
就是每當想要把程式貼到 blog 時,排版會跑掉,不是用等寬字元的方式在排版。

這時候就要用到一個很好用的 HTML tag:<pre>
用 pre tag 把程式包起來之後,程式碼就會以等寬字去排版。

很好,這樣看起來是解決了一個問題,但是還有另一個問題。
blog 上面的程式碼,沒辦法像一些 editor 一樣,依程式碼的語法去改變顏色。

嗯...在 HTML 要換顏色就是需要套用 css,所以我們可以自己動手去改顏色!?

不!
這當然是交給程式去做就好了。

網路上現在很多專門給網頁用的 syntax highlight 的程式
而我目前是用 SyntaxHighlighter 這套程式
並沒有去比較不同版本的好壞,只是很單純的選這一個

SyntaxHighlighter 加進 Blogger 的流程


1.打開你的 Blogger template 原始碼,找到</head>的 tag,並在前面加上 SyntaxHighlighter 的核心程式:
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<!-- add brushes here -->
<script type='text/javascript'>
  SyntaxHighlighter.config.bloggerMode = true;
  SyntaxHighlighter.all();
</script>

2.再跟據自己 blogger 上的需要,在 <!-- add brushes here --> 的位置加上對應的語法 js。
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/ 裡有詳細說明支援的程式

<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>

3.完成之後,就可以開始使用 SyntaxHighlighter 了:
一、用 <pre> tag:
<pre class="brush:js">
  alert('hello syntax');
</pre>
用 <pre> tag時,要注意一些 html 的特殊字元要轉成 html 專用的編碼(ex. < 換成 &lt;)

二、用 <script> tag:
<script type="syntaxhighlighter" class="brush:js"><![CDATA[
  /**
   * SyntaxHighlighter
   */
  function foo()
  {
      if (counter <= 10)
          return;
      // it works!
  }
]]></script>

Reference:
SyntaxHighlighter

2011-12-29

Ubuntu 11.10 - Eclipse 的圖示是問號!?

Ubuntu 上裝好了 Eclipse,也可以正常執行,
但是在 ubuntu 的 unity 桌面環境上卻只能看到 eclipse 的圖示是一個問號...

補上圖示的設定就好了
vi ~/.local/share/applications/eclipse.desktop

eclipse.desktop 的檔案內容:
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Name[zh_TW]=Eclipse
Comment=Eclipse IDE
Exec=/home/user/eclipse/eclipse
Icon=/home/user/eclipse/icon.xpm
Terminal=false
StartupNotify=true
Type=Application
Categories=Application;Development;

對照 eclipse 的路徑調整設定就可以了

完成後,圖示就不再是問號了

2011-12-28

[PHP] number_format()

php 提供了一個 function,讓我們可以輕鬆的格式化數字

number_format

string number_format ( float $number [, int $decimals = 0 ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

可以運用這個 function,
決定你的浮點數小數點後要輸出幾位($decimals),

或是,
調整你輸出的數字格式所要使用的小數點字元($dec_point),跟千位數的分隔字元($thousands_sep)

當然,不想用其中一個符號時,放個空字串('')也是可以的


Reference:
PHP: number_format

2011-12-18

[MySQL] char vs. varchar


可用長度:
char 0 ~ 255
varchar 0 ~ 65535

儲存資料長度:
char 為建立 table 時所決定的長度
varchar 依你所存放的資料而定,直到你決定的最大長度


char

char 在實際儲存資料時,在右邊補滿空白

name CHAR(5)

  ---------------------------------------
    value      actual_storage   Space
  ---------------------------------------
    'ex'       'ex   '          5 bytes
    'exper'    'exper'          5 bytes
    'expert'   'exper'          5 bytes
  ---------------------------------------

varchar

varchar 不填補空白,而是在額外用 1 到 2 byte 去記錄
長度在 255 內用 1 byte,超過 255 就用到 2 byte

name VARCHAR(5)

  ---------------------------------------
    value      actual_storage   Space
  ---------------------------------------
    'ex'       'ex'             3 bytes
    'expe'     'expe'           5 bytes
    'expert'   'exper'          6 bytes
  ---------------------------------------


Reference:
CHAR vs VARCHAR in MySQL
Tsung's Blog - MySQL 欄位格式 CHAR 與 VARCHAR 的差異