November 25,2008
Convert vdi to vmdk using CloneZilla
利用 qemu-img convert 要把 VirtualBox vdi 轉為 vmdk 時,似乎有 2G 的限制,轉出的 vmdk 檔案永遠只有 2G。
沒辦法,只好把腦筋動到 VirtualBox 上。
VirtualBox 可以掛載 vmdk,所以可以用 qemu-img 建立 vmdk 檔案,然後再用 Clonezilla 來進行磁碟複製的工作,雖然麻煩,但不失為一個好方法。
沒辦法,只好把腦筋動到 VirtualBox 上。
VirtualBox 可以掛載 vmdk,所以可以用 qemu-img 建立 vmdk 檔案,然後再用 Clonezilla 來進行磁碟複製的工作,雖然麻煩,但不失為一個好方法。
November 14,2008
svk mirror 錯誤
如果你在 svk mirror 時,出現類似 "xxx is not a mirrored path." 或 "xxx 不是一個映射路徑。" 的錯誤時,請使用 svk propedit svm:mirror // 指令進行編輯,將有問題的路徑移除之後,就不會有問題了。
解法參考自:
解法參考自:
November 6,2008
python + opengl = pyopengl
安裝:
參考資料:
- 安裝Python,我用 2.5。
- 安裝EasyInstall,這是類似 Perl CPAN、Ruby Gems的工具。等等會利用這個來安裝 PyOpenGL。
- 打開命令提示字元,切換到 c:\python25\scripts,執行 easy_install pyopengl。
- 最後,你還需要 GLUT:Nate Robins - OpenGL- GLUT for Win32,下載以後,丟到 c:\windows\system32 即可。
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
def display():
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glPushMatrix()
#glTranslatef(0.,1.,-1.) #move to where we want to put object
glBegin( GL_TRIANGLES )
glColor3f( 1., 0., 0. )
glVertex2d( -1., 0. )
glColor3f( 0., 1., 0. )
glVertex2d( 1.,0. )
glColor3f( 0., 0., 1. )
glVertex2d( 0., 1. )
glEnd()
glPopMatrix()
glutSwapBuffers()
return
glutInit( sys.argv )
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |GLUT_DEPTH)
glutInitWindowSize(400,400)
glutCreateWindow("Hello, World")
glClearColor(0.,0.,0.,1.)
glutDisplayFunc(display)
glutMainLoop()
想試試的原因,最主要是想說,Python 可以比較方便地進行測試與練習,接觸以後,發現代碼也很容易轉換為 C/C++,就這樣。參考資料:
November 5,2008
trinity.vim
前兩天想說找找看 Vim 有沒有 GNU Global 的 plugin 時,看到了 trinity.vim。
這個 plugin 整合了三個 plugin:Source explorer, taglist, NERD tree 在 Vim 模擬出接近 Source Insight 的效果。
有用過 Source Insight 的人,相信都知道很難找到替代品,我前幾年也曾經試圖找過,但都一直沒找到。
這個 plugin 真的不錯,讓Vim更好用了~
有優點當然也有缺點:
這個 plugin 整合了三個 plugin:Source explorer, taglist, NERD tree 在 Vim 模擬出接近 Source Insight 的效果。
有用過 Source Insight 的人,相信都知道很難找到替代品,我前幾年也曾經試圖找過,但都一直沒找到。
這個 plugin 真的不錯,讓Vim更好用了~
有優點當然也有缺點:
- Source explorer 裡呼叫 ctags 的地方是寫死的,所以如果你的 ctags 放在別的地方,最好自行去搜索有呼叫到 ctags 的地方,加上路徑。
- 把 Source explorer 打開的時候,速度會變慢,這是因為它試圖利用 ctags 資料庫去找跟游標所在位置有關的程式片段。我自己是比較少用,不能用對我影響不大。
October 21,2008
以 bash script 為 sqlite database 產生 C/C++ struct
最近寫的一個 bash script,用來幫你把 sqlite database 裡的 table schema 轉成 C/C++ struct。
這裡只處理 text 與 integer 型態,text 轉成 wstring/string,integer 則轉為 int。轉換的工具是使用 awk/sed。
只要稍稍改動一下,也適用在其他語言上。
這裡只處理 text 與 integer 型態,text 轉成 wstring/string,integer 則轉為 int。轉換的工具是使用 awk/sed。
只要稍稍改動一下,也適用在其他語言上。
#!/bin/bash
if test -z "$1"
then
echo "You need to specify the database file name."
exit -1
fi
db=$1
dbname=`basename $1 .db`
tables=`sqlite3 $db ".table"`
output="db_${dbname}_schema.h"
touch $output
cat >> $output << EOF
#ifndef __db_${dbname}_schema_h__
#define __db_${dbname}_schema_h__
#include <string>
#ifdef _UNICODE
typedef std::wstring db_string;
#else
typedef std::string db_string;
#endif
EOF
for table in $tables
do
echo "typedef struct {" >> $output
sqlite3 $db ".schema $table" | awk '/^\ /{printf("%s %s;",$2,$1);}' | sed -e 's/,/\ /g' | sed -e 's/text/db_string /g' | sed -e 's/integer/int /g' >> $output
struct_name=`echo $table | awk -f cap.awk`
echo "}$struct_name;" >> $output
echo "" >> $output
done
cat >> $output << EOF
#endif
EOF
# call "astyle" to format the code. Beside "astyle", you can use "indent".
astyle $output
exit 0
October 14,2008
Project.vim
同事最近拋棄了 Source Insight 3,開始用 Vim 寫 code,所以有人跟我一起研究了。
他最近介紹我一個 plugin : project - Organize/Navigate projects of files (like IDE/buffer explorer),看起來不錯用,他可以把某個目錄下所有檔案都建立為專案檔,讓你可以快速瀏覽所有檔案,不過美中不足的是他沒有把 CVS、.svn、_svn 等目錄過濾掉,我在 VimDirListing 函數裡添加了兩行把這些目錄過濾掉。
這是原來的樣子:
他最近介紹我一個 plugin : project - Organize/Navigate projects of files (like IDE/buffer explorer),看起來不錯用,他可以把某個目錄下所有檔案都建立為專案檔,讓你可以快速瀏覽所有檔案,不過美中不足的是他沒有把 CVS、.svn、_svn 等目錄過濾掉,我在 VimDirListing 函數裡添加了兩行把這些目錄過濾掉。
這是原來的樣子:
if isdirectory(glob(fname))
let {a:dirvariable}={a:dirvariable}.a:padding.fname.a:separator
let {a:dircount}={a:dircount} + 1
else
" other stuff
改過以後:
if isdirectory(glob(fname))
if fname != 'CVS' && fname != '.svn' && fname != '_svn'
let {a:dirvariable}={a:dirvariable}.a:padding.fname.a:separator
let {a:dircount}={a:dircount} + 1
endif
else
如果你懶得看英文的話,對岸的朋友翻譯了該 plugin 的文檔:VIM-Project Plugin - I Know you Know - C++博客
September 24,2008
Ubiquity command - findbook(更新)
上一版沒有對 uri 作 encoding,所以找中文時會出錯,現在補上,只要呼叫 Ubiquity 內建的 encodeURIComponent() 就行了...
CmdUtils.CreateCommand({
name: "findbook",
contributors: ["elleryq"],
license: "MPL",
description: "讓買書變成更簡單的決定!",
takes: {"書名關鍵字": noun_arb_text},
icon: "http://findbook.tw/favicon.ico",
execute: function(directObject) {
Utils.openUrlInBrowser( "http://findbook.tw/search?keyword_type=keyword&q=" + encodeURIComponent(directObject.text) );
}
});
August 29,2008
Ubiquity command - findbook
Ubiquity已經很多人介紹了,這裡是分享一個 commands,如果你有用 Findbook 的話,可以用用看...
安裝 command 方法很簡單,打開 Ubiquity Command Editor 後,把下面的程式碼貼上去即可:
CmdUtils.CreateCommand({
name: "findbook",
author: { name: "elleryq"},
contributors: ["elleryq"],
license: "MPL",
description: "讓買書變成更簡單的決定!",
takes: {"書名關鍵字": noun_arb_text},
icon: "http://findbook.tw/favicon.ico",
execute: function(directObject) {
Utils.openUrlInBrowser( "http://findbook.tw/search?keyword_type=keyword&q=" + directObject.text );
}
});
July 23,2008
Banshee 的 PlayQueue
1.0 版以後多了一個新功能-PlayQueue,我很喜歡這功能,因為你可以一直把想聽的歌丟進去,Banshee會播放這個Queue裡的歌直到Queue沒有歌為止。
本來以為這是內建的功能,後來看了之後,才發現這是一個 Extension。
它主要繼承 PlaylistSource、IBasicPlaybackController,把自己實作成一個 Playlist 來源,在Banshee播放時,實際上來源已經不是原來的 Music library 了。
所以如果要取得這個 Source,應該是利用 ServiceManager.SourceManager 來取得,要加入 PlayQueue 的話,則是使用 AddSelectedTracks()。
目前我還沒研究出如何在 Extension 裡面呼叫其他 Extension 的方法...
本來以為這是內建的功能,後來看了之後,才發現這是一個 Extension。
它主要繼承 PlaylistSource、IBasicPlaybackController,把自己實作成一個 Playlist 來源,在Banshee播放時,實際上來源已經不是原來的 Music library 了。
所以如果要取得這個 Source,應該是利用 ServiceManager.SourceManager 來取得,要加入 PlayQueue 的話,則是使用 AddSelectedTracks()。
目前我還沒研究出如何在 Extension 裡面呼叫其他 Extension 的方法...
July 21,2008
.NET framework essential Chapter 5
這一章主要講 ADO.Net。
DataSet、DataTable、DataRow、DataRelation... 這一組類別完全是一個抽離實體層的類別,所以有 DataAdapter 這一組與 Connection、Command、DataReader ...等類別溝通。
DataSet、DataTable、DataRow、DataRelation... 這一組類別完全是一個抽離實體層的類別,所以有 DataAdapter 這一組與 Connection、Command、DataReader ...等類別溝通。
- GetChildRows[] 可以依據 Relationship 來取得子Table與父Table相關的資料列。
- 一個 DataAdapter 基本上對應一個 DataTable,但他不管所在的 DataSet,所以你可以都塞到同一個 DataSet 裡面去。另外 DataAdapter 不處理 Relationship,所以用 Fill 取得資料並放到 DataSet 裡的 DataTable 之後,得自己加上 Relationship。
- 由於 DataSet 與 XML 有一定的關係,第五章最後簡單地介紹了 XML 的相關函數。