2013-07-22

Change Console Resolution in Grub2

edit below file.

sudo vi /etc/default/grub

uncomment the setting "GRUB_GFXMODE=640x480", and change to the resolution what you want.

update grub and reboot.

sudo update-grub
sudo reboot

i test it on ubuntu 13.04, and it works.


Reference:

ubuntu 10.04 console resolution
Grub 2 and the VGA parameter

2013-06-23

備份一下 自己加的 css

code

code {
  padding: 2px 4px;
  color: #d14;
}

pre

pre {
  font-family: monospace;
  padding: 6px;
  margin: 0;
  font-size: 12.025px;
  line-height: 18px;
  word-break: break-all;
  word-wrap: break-word;
  background-color: #f5f5f5;
  border: 1px solid #ccc;
  -webkit-border-radius: 4px;
     -moz-border-radius: 4px;
          border-radius: 4px;
}

blockquote

blockquote {
  color:#222;
  background-color: #FFD5A0;
  padding: .3em .5em;
  border: 2px #E2C8AF dashed;
}

reference

reference {
  display: block; /* fixes a strange ie margin bug */
  background: #FEE url(http://chenkaie.googlepages.com/Code_REF.gif) left top repeat-y;
  border: 1px dotted #933;
  padding: 10px 10px 10px 20px;
  margin: 5px 0 0 5px;
  font-size: 13px;
  font: Courier New;
  line-height: 1.6em;
}

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 的差異

2011-11-16

Magical Methods in PHP Class

Named starting with __ as magical

__construct()
will be called on each newly-created object

__destruct()
will be called there are no other references to a particular object in any order during the shutdown sequence.

__isset()
is triggered by calling isset() or empty() on inaccessible properties.

__unset()
is invoked when unset() is used on inaccessible properties.

__set()
is run when writing data to inaccessible properties.

__get()
is utilized for reading data from inaccessible properties.

__call()
is triggered when invoking inaccessible methods in an object context.

__callStatic()
is triggered when invoking inaccessible methods in a static context.

__sleep()
serialize() checks __sleep().
executed prior to any serialization.

__wakeup()
unserialize() checks __wakeup().
this function can reconstruct any resources that the object may have.

__toString()
when it is treated like a string. must return a string

__invoke()
call an object as a function.

__set_state()
be called for classes exported by var_export()

__clone()
Once the cloning is complete,
if a __clone() method is defined,
then the newly created object's __clone() method will be called

Reference:

http://php.net/manual/en/language.oop5.magic.php 石頭閒語 - http://blog.roodo.com/rocksaying/archives/10796767.html
石頭閒語 - http://blog.roodo.com/rocksaying/archives/2683180.html

[PHP] Equal vs. Identical

Equal: ==
Identical: ===
兩個都是用來進行比較運算的 "Comparison Operators"
有什麼不一樣呢?

如果是要比較不同的資料型態時,
使用 "Equal" 時,會先轉換成相同的資料型態,再進行比較
使用 "Identical" 時,不會轉換資料型態


Reference:
http://blog.roodo.com/rocksaying/archives/2565180.html
http://www.php.net/manual/en/language.operators.comparison.php
http://www.php.net/manual/en/types.comparisons.php

2011-10-30

GTK-Warning: pixmap

作業系統換上全新的 Ubuntu 11.10 ,遇到了一些問題
新出來的東西嘛,難免的

錯誤訊息:
Gtk-WARNING **: 無法在module_path 中找出佈景主題引擎:‘pixmap’

解決方案:
安裝缺少的套件就好了~
sudo apt-get install gtk2-engines-pixbuf

Reference:
Tsung's Blog - Ubuntu 修復 GTK WARNING(module_path, pixmap)

2011-10-03

ID3 Tag - 轉換編碼

在 Linux 上要播 MP3 時,常常會看到音樂的相關資訊變成亂碼,
這是因為 MP3 裡的 ID3 tags 編碼不是 UTF-8。

要解決這個問題不難,有個工具可以輕鬆的轉換編碼,就是 mid3iconv

安裝

只要安裝 python-mutagen 套件,就可以有好用的 mid3iconv 可以用了
$ sudo apt-get install python-mutagen

操作方法

裝好之後就可以開始轉換了。

如果確定要轉換編碼的 ID3 Tag 原本是 big5 的話,
就用以下指令轉換當前資料夾裡的所有 MP3 的 ID3 編碼
$ mid3iconv -e big5 *.mp3 參數
-e 編碼
    資料原本的編碼
-p, --dry-run
    不會改變原檔案

更進階的用法:
轉換目前目錄下所有子目錄的 MP3
find . -iname "*.mp3" -execdir mid3iconv -e big5 {} \;
Ubuntu Linux - 用mid3iconv及exfalso批次整理舊MP3的ID3標籤
[筆記]在Ubuntu下大量轉換ID3之編碼

2011-06-01

[Apache] 使用者自己的網頁目錄 & Config Indexes

要讓使用者有自己的網頁目錄不麻煩
把 apache2 的 userdir mod 啟動就可以了


在 ubuntu 下的方法:
# a2enmod userdir
# /etc/init.d/apache2 restart


預設的網頁目錄是
~/public_html/
就在 userdir.conf 裡的
<Directory /home/*/public_html>

網址則是
http://localhost/~user/

還可以設定哪些 user 可以使用 userdir
# 預設是 disabled root
UserDir disabled root

如果 userdir 下的 php 沒辦法打開,會變成下載 php 檔的話,那要調整一下 apache 的 php 設定

就在 /etc/apache2/mods-available/php5.conf 裡有註明
# To re-enable php in user directories comment the following lines
# (from to .) Do NOT set it to On as it
# prevents .htaccess files from disabling it.


就如 conf 檔裡所看到的,comment the following lines 吧

另外,這設定好像是 php5.3 才新加的

避免 /var/www/ 的目錄中沒有 index.html 而被瀏覽者看到目錄中的檔案或資料夾


# vim /etc/apache2/sites-enabled/000-default
<Directory /var/www/>:
Options Indexes FollowSymLinks MultiViews #將 Indexes 刪除
AllowOverride None
Order allow,deny
allow from all
</Directory>

# /etc/init.d/apache2 restart

2011-05-31

Zim - 桌面 wiki

一直以來,想找一個好工具可以讓我很方便的做筆記,試過了許多的程式,都差強人意
不過程式太大開太慢,就是筆記太過於單調,不容易整理

官方網站:http://zim-wiki.org/
Latest release: 0.52

PPA網址:https://launchpad.net/~jaap.karssenberg/+archive/zim

Zim 也有 Windows 版本跟 Mac 版本
Mac 版沒試過,Windows 版本沒在 Linux 上那樣的好用就是了

如何安裝


Ubuntu 本身的套件庫裡就有 Zim 了,不需要任何額外的動作就可以安裝
# apt-get install zim

不過 Ubuntu 本身的套件庫更新速度不快,所以你可以加上 Zim 的 PPA 這樣會比較快更新的最新版的 Zim
# add-apt-repository ppa:jaap.karssenberg/zim
# apt-get update
# apt-get install zim


怎麼用


最初開始使用 Zim 時,程式會要求你建立一個筆記本,
選定資料夾並設定完成之後,就可以正式開始使用了,而你所有的資料都會在所指定的資料夾

Zim 裡,你可以:
跟 wiki 一樣,很輕鬆的編輯跟排版你的文件
有樹狀式的目錄整理文件
對整個筆記進行蒐尋
放上其他文件的連結,建立起文件之間的關連

總之就是許多讓你可以更容易整理資料的功能

特別的功能


這裡另外再列出整個我覺得很有特色的功能

Calendar
會有一個月曆可以讓你選日期,點下去後就會連到該日期的文件
直接拿來當日記用,或是要用日期整理東西不錯用

checkbox
用 "[" 跟 "]" 建立一個 checkbox
用這個 checkbox,你可以建立起工作清單
完成之後打個勾,或是打個叉取消它
再加上事件清單的外掛,你可以更容易的看到你全部的工作項目

tag
0.52這版新的功能!
用"@"為文件標上 tags,用 tags 來整理文件

奔流 X 科技+玩意 - 跨平台桌面維基 - Zim
Ching Wei : This is My Life - 工作、攝影、旅遊 - 【軟體】Zim - A Desktop Wiki (桌上型維基)
XEPC.org - 新軟體推介: Zim – 桌面維基

2011-05-30

在 ubuntu natty 上安裝 LAMP server

好像沒什麼特別好介紹的,就分別裝上 Apache, Mysql, php 就完成了

安裝 mysql:


# apt-get install mysql-server
安裝過程中要設定 mysql 的 root password
更重要的是要把密碼記住

安裝 apache2:

# apt-get install apache2
安裝好 apache2 後,就可以連到 http://localhost/ 看看是否正常運作,
有跑起來的話,畫面上會顯示 "It works!"

安裝 php:


# apt-get install php5 php5-mysql libapache2-mod-php5

下列套件將會被【移除】:
apache2-mpm-worker

裝 php 時,會把 apache2-mpm-worker 移除,換成 apache2-mpm-prefork

安裝 phpmyadmin:

# apt-get install phpmyadmin
安裝過程會要求設定 phpmyadmin:
選擇 http server 類型,這個就是選擇我們這裡裝的 apache2 了
設定phpmyadmin 使用者密碼

phpmyadmin 裝好之後,可以連到 http://localhost/phpmyadmin/ 可以看到 phpmyadmin 的登入畫面

現在,你成功的架設了 LAMP Server,可以開始你的 PHP 之路了

Book.Study.Nyo - 在debian squeeze 上裝 LAMP

2011-04-07

[Linux] 列出指定位置下的所有資料夾

任務目標:

針對指定的路徑,列出底下所有的資料夾,但是不列出檔案

用 find
$ find . -type d

用 ls 跟 grep
$ ls -lR | grep '^d'

用 tree
$ tree -d

2011-02-18

[Linux] ln 製作 Linux 上的捷徑

ln - make links between files
要在 Linux 底下建立捷徑,只要用 ln 這個指令就 OK 啦


$ ln [參數] 來源檔案或資料夾 要建立的 link 名稱

沒有參數的時候是建立 hard link,沒辦法跨 file system,沒辦法 link directory
-s : symbolic link
-f : 要建立的 link 如果存在,會先移除掉再建立


比較常用的似乎是 symbolic link

在修改 link 裡的資料時,實際上就是去修改 link 所指向的原資料


鳥哥的 Linux 私房菜 - 實體連結與符號連結: ln
凍仁的 Ubuntu 筆記 - 【Ubuntu】ln - Linux 上的捷徑

2011-02-14

[Linux] 釋放虛擬記憶體

Linux Kernel 2.6.16 之後新加入了 drop caches 的機制,可以讓系統空出大量的記憶體

Freeing the page cache:
$ echo 1 > /proc/sys/vm/drop_caches
$ sysctl -w vm.drop_caches=1


Free dentries and inodes:
$ echo 2 > /proc/sys/vm/drop_caches

Free the page cache, dentries and the inodes:
$ echo 3 > /proc/sys/vm/drop_caches

這使 kernel 更勤於回收 cache
$ sysctl -w vm.vfs_cache_pressure=n (n > 100)

Tsung's Blog - Linux 手動回收 已經被 Cache 的記憶體