2008年10月31日 星期五

在Textmate下compile有eps的文件

在Textmate下compile有eps的文件的時候會出現以下錯誤訊息:
LaTeX Error: Unknown graphics extensions: .eps
然後圖檔也無法顯示在PDF中

主要是因為在使用pdflatex會出現問題
所以解決的方法是按照以下步驟compile
latex myfile.tex && dvips myfile.dvi -o myfile.ps && ps2pdf myfile.ps
最後才compile成latex
不過已經有現成的package可以使用
只要加入以下package就可以compile過啦

\usepackage{pstricks}

參考來源:
http://blog.derjohng.com/2008/03/28/latex-error-unknown-graphics-extensions-eps/
http://henrik.nyh.se/2006/10/textmate-latex-bundle-and-compiling-to-pdf-via-ps

2008年10月8日 星期三

利用Google AJAX Libraries API 載入Jquery

之前看到了幾篇評論Google AJAX Libraries API的文章
http://planet.nccucs.org/2008/05/28/266/
http://pctao.org/2008/05/29/235/
http://funp.com/t206281#p=206281

其主要的優點是可以讓使用者不用再重新下載二次函式庫
這樣可以節省流量和增快開啟網頁的速度
所以當要自己試用看看看啦

主要是參考Google code的官方網站:
http://code.google.com/apis/ajaxlibs/
http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery

主要是在head中加入以下幾行

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load JQuery
google.load("jquery", "1.2.6");
google.setOnLoadCallback(function() {

});
</script>


並且用google.setOnLoadCallback 取代 $(document).ready
這樣就不用把jquery的函式庫存在自家的主機上了

2008年9月1日 星期一

will_paginate使用心得

延續之前的文章
http://hdj-berkeley.blogspot.com/2008/08/scaffold.html
如果我們要將大量資料分類成好幾個分頁
就可以用現在的套件will_paginate

首先在model裡增加search的條件

# models/product.rb
def self.search(search, page)
paginate :per_page => 5, :page => page,
:conditions => ['title like ?', "%#{search}%"],
:order => 'title'
end

這裡的title是依照你想要的排序自己選取的
也可以改為id

接著增加controller的條件
將變數傳回給viewer

# products_controller.rb
def index
@products = Product.search(params[:search], params[:page])
end


最後修改products/index.rhtml
讓分頁呈現在網頁上
<%= will_paginate @products %>


這樣就大功告成啦

主要參考:
http://railscasts.com/episodes/51

其它參考網址:
http://iceskysl.1sters.com/?action=show&id=307&page=1
http://iceskysl.1sters.com/?action=show&id=42&page=1
http://www.ruby-lang.org.cn/forums/thread-985-1-1.html
http://www.j-kanban.com/bbs/thread-3690-1-1.html

2008年8月29日 星期五

使用scaffold心得

通常初學者在學習使用ror的時候都會使用scaffold來幫助建構出網頁的框架
但是從rails 2.0開始ror就沒有內建scaffold的套件啦
所以必須另外安裝動態scaffold

ruby script/plugin install http://dev.rubyonrails.com/svn/rails/plugins/scaffolding/


又因為動態scaffold會用到內建分頁,而內建分頁功能也被拿掉成為外掛
所以要安裝pagination

ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination


參考來源:
http://blog.pbg4.org/2007/12/20/upgrade-to-rails-2-0-2

因為靜態scaffold的用法與之前的不一樣了
所以如果要使用scaffold來配置你的網頁
必須按照底下的格式使用
ruby script/generate scaffold ModelName [field:type, field:type]

舉個例子
ruby script/generate scaffold product title:string description:text image_url:string

接著就可以到http://your_host/product/
觀看你新架好的網頁

參考來源:
http://topic.csdn.net/u/20070513/22/5931d7c7-7451-4cc3-9dc5-ca3afbb0cae8.html

此外,有在看"agile web development with Rails 2/e"的人可以參考底下網址:
http://agilewebror2.blogspot.com/2008/08/chapter-6.html
他有探討rails 2.0的一些改變

2008年8月26日 星期二

在vim上開發ruby on rails

要讓vim看的懂ruby
其實只要下載ruby.vim就可以了
不過vim的功能可沒有這麼簡單而己哦
只要配合rails.vim和project.vim
就可以讓你的vim瞬間變成功能超強的IDE
可以參考
http://blog.roodo.com/poga/archives/2667806.html

底下是自己安裝的心得
因為我是在Ubuntu 8.04下使用
所以我主要是將檔案存在我自己的家目錄下

step1 下載 rails.vim

請先下載 rails.vim
下載完解壓縮到~/.vim/底下

step2 下載project

接著下載 project
一樣解壓縮到~/.vim/底下

接著就可以開個ruby的檔試試看啦
詳細的操作方法請到參考下列網頁

參考網址:
http://blog.ntut.idv.tw/2007/12/fbsd-vim-ruby-on-rails.html
http://wiki.rubyonrails.org/rails/pages/HowtoUseVimWithRails
http://www.upulife.com/leo/?p=191
http://lightyror.thegiive.net/2007/06/vim-ruby.html
http://devpoga.wordpress.com/2008/02/05/vim-rails/
http://yueguangyuan.javaeye.com/blog/57263

2008年8月24日 星期日

Ubuntu 8.04灌ruby on rails

參考來源:
https://help.ubuntu.com/community/RubyOnRails

Step1 安裝Apache
首先安裝Apache
在commond line底下輸入
sudo apt-get install ruby-full build-essential apache2 apache2-mpm-prefork apache2-prefork-dev


Step2 安裝RubyGems 1.1.0
目前gems已經出到1.2.0了
之前有人說1.2.0有些許的問題
不過我測試的結果 似乎可以直接使用了
指令如下
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
tar xzvf rubygems-1.2.0.tgz
cd rubygems-1.2.0
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo gem update --system


升級完了之後再灌rails
sudo gem install rails
sudo gem install passenger
sudo passenger-install-apache2-module


Step3 修改apache設定檔

最後在/etc/apache2/httpd.conf
加入
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8



寫了幾個測試程式
一直出現
No such file or directory - /tmp/mysql.sock

這是因為Rails 預設會去找 /tmp/mysql.sock 檔,
不過 Debian 或者 Ubuntu 上的 Mysql 卻不是在/tmp/底下,
通常是在 /var/run/mysqld/mysqld.sock,
所以需要改 database.yml,
如下:
development:
adapter: mysql
socket: /var/run/mysqld/mysqld.sock
database: test_development
username: xyz
password: xxxx
host: localhost

這樣改完就可以看到測試的程式

參考來源:
http://blog.roodo.com/syshen/archives/2143083.html

2008年8月19日 星期二

讓你的Gvim也可以compile latex

回國之後我都是用Texmaker編寫我的論文,但是Texmaker用起來總是卡卡的
讓人覺得好像看得很不順眼,而且他的spell checking 也不是很直覺
用起來一整個不順,拼錯字了自己也不知道

後來我發現原來Gvim有內建拼字檢查,這真的是我的救星丫
反正我本來就滿習慣用vim的,而且vim本身就滿好用的
對我來說真的是個好消息

不過還有一個問題就是編好的latex檔要怎麼compile丫??
難不成還要我再開texmaker compile剛才用vim編寫好的tex檔嗎?
當然不用啦
只要灌好vim-latex這個套件
我的Vim就可以幫我compile剛編好的tex檔

Vim-latex的官方網站:
http://vim-latex.sourceforge.net/

安裝有四個步驟:
Step1

先到
http://vim-latex.sourceforge.net/index.php?subject=download&title=Download
下載vim-latex套件

Step2
下載回來之後解壓縮到 C:\Program Files\Vim\vimfiles\

Step3
修改你的
C:\Program Files\Vim\_vimrc
加入

" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'


不過我自己試的結果
好像有沒有加這一行都沒有差耶
請參考
http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html
這樣設定完就可以看到Gvim上多了一些選項可以點選,像是latex常用的符號之類的東西

================================================
灌好vim-latex之後,只要在常態模式之下按\ll
vim就會自動幫你compile你的tex檔
但是它預設是compile成dvi檔
如果想到得到pdf檔
可以點選 TeX-suite > Target format
將dvi改成pdf

不過這樣compile出來的pdf檔圖片會顯示不出來
最好是依序compile dvi > ps > pdf
當然我不會想自己手動這麼作
只要自己新增一個
C:\Program Files\Vim\vimfiles\ftplugin\tex.vim

並在裡面加入

let g:Tex_FormatDependency_pdf = 'dvi,ps,pdf'
let g:Tex_CompileRule_dvi = 'latex --interaction=nonstopmode $*'
let g:Tex_CompileRule_ps = 'dvips -Ppdf -o $*.ps $*.dvi'
let g:Tex_CompileRule_pdf = 'ps2pdf $*.ps'


之後要compile成pdf的時候,就只要按下\ll
一切就完成啦

此外如果想要預設compile成pdf檔的話
只要再剛才的
C:\Program Files\Vim\vimfiles\ftplugin\tex.vim
檔案中加入

let g:Tex_DefaultTargetFormat = 'pdf'


預設產生的檔案就是pdf檔啦
不用每次開檔還要重新設定

參考來源:
http://vim-latex.sourceforge.net/documentation/latex-suite/customizing-latex-suite.html
http://vim-latex.sourceforge.net/documentation/latex-suite/compiler-dependency.html
http://vim-latex.sourceforge.net/documentation/latex-suite/customizing-compiling.html

================================================
此外,如果想要自行設定Windows 的 Gvim 背景色彩
可以參考:
http://blog.longwin.com.tw/archives/000056.html
Related Posts Plugin for WordPress, Blogger...