Rails三兩事 A website introduce you ruby&rails and technology news.

5Mar/090

About

這個網站寫有關Ruby On Rails及些技術的東西.

5Dec/090

Power Language In Sniper IDE (H.T.S)

偶然的機會使用到Sniper IDE.真的是最不好用的IDE....

如果想在HTS內把自己的想法實現,除了內建的一些指標,寫好的功能,可能就得使用SniperIDE了.
SniperIDE所使用的Power Language是類似VB的語言,但有少許不同.
但幾乎找不太到文件,也許該歸功於引進公司? 還是這語言太冷門? 還是我不會查?

稍微查了一下,SniperIDE應該不只用在HTS上,似乎來自日本較多....
一些基本語法 : http://tw.myblog.yahoo.com/jw!lbDyLRWQEQV_5hHZAYRp4oPJyg--/article?mid=67&prev=71&next=52

寫慣了Ruby,OO語言. 回去寫這種語言真的蠻痛苦的.
因為本身不甚了解金融,解說一下觀念 :
若 4000->左方欄->SniperTool->SniperIDE(程式語言)->檔案->新增
則會顯示視窗.選擇你要哪一種. 共五種,依照類型不同,也會有不同的限制.
我用到的只有
指標->K棒
函數->自己寫好的,可能是計算開高收低,又或其他. 基本上,內建寫好的函數也是用SniperIDE去寫.
剩的 沒試過.. 若你有試過.. 歡迎指教.

若寫在指標,則該程式會針對"每一個K棒"做處理.
假設你寫

AlertEnabled
if Time<090000 then
   Alert("XXX")
end if

則,在09:00之前的所有K棒都會alert.

剛開始還沒會意過來,還以為像OO語法,一直要找K棒的本身.
比如 K.text="" K.color=""
過了好一陣子,我才會意到,面對的是非"OO"語言....

儘管自己將所需資訊輸出,並使用Ruby做分析..
不過,也幾乎把所有在"函數視窗"裡的東西都看了一遍..
幾個比較重要的.

1. FileAppend(pathto, string) 讓你脫離苦海的好東西.
不過,FileAppend有一個缺點.
如果你在IDE內檢驗(Alt+F再按V),則會發現檔案輸出一次.
再一次,卻發現檔案並非被覆蓋,而是直接新增到現有檔案. 也就是同一份檔案有兩份一模一樣的姿料.
這很愚蠢. 這意味著,你每次開啟載入有FileAppend的外掛,他都會Output File一次.... 還不是Replace...
如果沒注意,File可能就會變成x Mb. 甚至xxMb.....
但是SniperIDE開放的功能又少得可憐..

待續....

25Nov/090

Productive Ruby on Rails

這陣子一直忙於專案.
之前的專案沒有使用Restful,於是寫起來有點辛苦,也不好整理.
這個專案一開始便使用Restful,配合Scaffold寫起來真的很快....
雖然,這是眾所皆知的東西了,但還是想紀錄一下.. :$

這是寫在Facebook上的文章,懶得重翻,將就一下囉.
英文不好請見諒. :p

I know why everybody say Ruby on Rails is productive now.
As most of parts, Ruby on Rails is there for you.
The only thing you need to do is just type some command and change some works.
For example. "Scaffold" is one of great tool that generate ready to go model for you.
In the one going project ,I scaffolded 4 times for all CRUD works.
Each scaffold for one set of CRUD, and it's ready with Restful style.
Only thing you need to do is build views and setting up some routes, some relationship between databases, and do a little bit work for your controller.

If you don't know what is Restful, and tried to understand how does scaffold works, it might drive you crazy.
Official docs guide you in pretty clear way : This
As others like iHower's PPT : This
And this : This

They all provide lots of information.

How easy if you go with Restful?
Sometimes,we want to create some relationship in this way : " find A user's POST "
In old way, you might create another action called "search post", and have lots of conditions in.
Maybe "find POST by user name", "find POST by comment".... as you can image, that will be lots of work to do.

In Restful way. you only need to set up relationship in routes like :

map.resources :users, :has_many=>{:posts,:comments}

then go into your each controller action "index" and add something like :

@post=find(:all,:conditions=>["user_id=?",params[:user_id]]) if params[:user_id]!=nil

then, when you type address like " users/1/posts/ " , it will show all posts by user_id 1 for u.
Cool, isn't it?

If you have further question, welcome discuss with me.

24Nov/090

Shift to Xubuntu

Ubuntu有好多版本.
你知道差別嗎,你最喜歡哪個?

我最喜歡Xubuntu. 因為他快. :)

Ubuntu有點慢,即使桌面特效全關. 尤其升9.10後(有人知道為什麼嗎?)
Xubuntu很快,開機動畫我也喜歡. 很穩定.
Kubuntu自從9.04?之後,桌面改得亂七八糟,一堆Widget. 就不想用了....

你呢?

小抱怨,Linux上的FF怎麼那麼爛... 很慢.. 尤其開Facebook.. 整個就是 慢速播放*8倍...
又懶得花時間去搞..

24Nov/090

Really need to edit the theme of this blog….

嗯. 很久沒有寫.. 真的得花時間整理整理這個blog.
除了改一改Theme,Css. 還得多補充一點內容.

等下個月. 開發到一段落.比較不那麼忙時..

話說,誰說寫網頁很簡單. 一堆雞毛的事....
當然也一堆Trick & Security Issue.
除非只是做個公司形象網站那種的,另當別論.

不過..
要這樣講的話,寫應用程式很簡單.
只是拉一拉方塊,寫一寫對應,一個簡單的計算機10分鐘就出來了.

要這樣講的話,做業務很簡單.
只是話講一講,喝個茶,出一張嘴.

要這樣講的話,做行銷也很簡單.
只是SEO弄一弄,企劃打一打,圖弄一弄
搖搖叫一叫(是叫來演出廣告...:p)

要這樣講的話,做美工也很簡單.
只是線拉一拉,圖貼上剪下,淡化一下,調一下色
最多拍個照片,修一修就好了

但是,從來都不是那麼簡單.
任何事,都不要小看. :)

Filed under: Uncategorized No Comments
24Nov/090

Q101 on Ubuntu

3G網卡要在Linux驅動是很麻煩的一件事.
9.10前的版本更是麻煩,得設定,還得寫script.
9.10後就有更快地作法了.

按Alt+F2,輸入gksudo gedit /etc/udev/rules.d/30-q101.rules後,按執行
把以下內容貼進去

#
# first, q101 will be detected as usb_storage of 0408:1000
# you have to force it suspend to change running mode from
# storage to 3.5g card

SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ACTION=="add", ATTRS{idVendor}=="0408", ATTRS{idProduct}=="1000", RUN+="/bin/sh -c 'cd /sys$env{DEVPATH};until test -f power/level;do cd ..;done;if [ -f power/level ];then echo suspend > power/level;fi'"
存檔後重開機

插入網卡過幾秒應該就可以看到,選TW Mobile.
Edit Connection:

Number: *99#
Username: username
password: passwd
APN: Internet

(重開)即可.

5Nov/090

關於HostingRails Domain

最近都在弄Domain的東西.
有鑑於上次有忘記怎麼弄,還去查官方說明,所以紀錄一下.

若多個指向一個(原本預設之根目錄),則去ParkDomain新增即可.
若指向非預設資料夾,則去AddonDomain新增.
:)

6Oct/091

Heroku is a great host for RoR. But still has some problems

Heroku的簡便,其實也造就了他的問題.
因為不是第一次被人推薦了,所以就去官網上看看.
不過,看了就覺得並不是太想用.
除了價格昂貴,再來就是他的優點,其實也是缺點.

Heroku的優點是兩面刃

由於你只要註冊好Heroku,然後 :
sudo gem install heroku
heroku create yourapp

當你要建好專案要上傳 :
git push heroku
就上傳好了

當要做些工作,比如migrate :

heroku domains:add yourdomain.com  #(加網域名,應該是加到DNS?)
heroku rake db:migrate
heroku bundles:capture

可是,他的方便也是不便.
我是不太喜歡一直和Host方溝通,比較喜歡一次就擁有很多自主權.
所以,當有問題,我該寫信去???

問題1, 如果想增加sub domain? 更改MX records,CName,etc...?
問題2, 原先配置為Thin+Nginx. 若想改用其他?
問題3, 目前尚未支援Custom SSL.
問題4, 太貴....
問題5, 還沒想到. 如果你有解答,歡迎討論互動.

就像Xdite說的,在我看來,現在還是Project比較適合. 若要Production,太貴,也不太適合.

--後記 :
初碰Heroku可能面臨問題.
Q : Install?
A : $>sudo gem install heroku

Q : Create?
A : $>git init
$>heroku create

Q : Upload?
A : $>git push heroku YouBranchName(master)

Q : See?
A : $>heroku open

Q : No ssh public key found in /root/.ssh/id_[rd]sa.pub. You may want to specify the full path to the keyfile.
A : ssh-keygen -t rsa

Q : Move Database?
A : $>sudo gem install taps
$>heroku db:push

Q : Rename App?
A : $>git remote rm heroku
$>git remote add git@heroku.com:YOURAPPNAME.git

Q : Manage Custom Gems?
A : 1. Create a file ".gems" under folder
2. Add "yourgem --version x.x.x --source xxxxxxxx" (ex : geokit --version '>=1.5.0' )
Each Gem one line.
3. "git commit -a" & "git push heroku xxx"

5Oct/090

Textmate on Ubuntu9.04 - Gedit

寫Ruby, RoR的工具首推Textmate是毋庸置疑.
在Ubuntu上並沒有Textmate,但有替代方案 : Gedit (TextEditor).
Gedit是內建的, 如果你是9.04版本. 那麼更不需要安裝甚麼太多外掛.
其他的還有Theme,讓你的配色更好看.
還有自己遇到的一些問題. 希望有幫助.

Gedit Plugins

這些是網路上建議的外掛 :
Snippets - 點我下載 (9.04內建)
File Browser - 點我下載 (9.04內建)
Class Browser - 點我下載
Quick Highlight Mode - 點我下載
Word completion - 點我下載
Snap Open - 點我下載

下載完&解壓縮以後,在9.04下,全都丟到 /usr/lib/gedit-2/plugins 即可.
或是可以丟在某個資料夾內,然後開Gedit. Edit > Preferences > Font & Colors > Add
然後選你的檔案一個個加入.

一些讓你的Gedit看起來像Textmate的 Theme :

官方來源 :

下載DarkMate

(官方圖好像也掛了?)
下載Desert

(Gedit官方圖片掛了,有人有圖片煩傳給我,或告知. 感謝.)
下載Textmate

另外還有五個一組的Theme包. 下載請點我
分別有 :
Cobalt

Darkmacs

IDLE

Slush and Poppies

Twilight

其他來源 :

下載Tinge


下載 LightMate

如果還不夠,這裡還有更多. (部份重複)
Download them from GitHub

Gedit Highlight

再來就是設定一些ror檔案的highlight支援.
直接copy,然後貼在console下.

wget http://grigio.org/files/x-rhtml.xml; sudo mv x-rhtml.xml /usr/share/mime/packages
wget http://grigio.org/files/rhtml.lang;  sudo mv rhtml.lang /usr/share/gtksourceview-1.0/language-specs/

惱人的RoR檔案Highlight問題

在安裝的過程中我自己遇到一個問題,就是erb顯示不正確.
你可以透過下列操作來修正.erb的highlight問題.

Console下輸入

sudo nano /usr/share/gtksourceview-2.0/language-specs/ruby.lang

找到
<property name="globs">*.rb</property>
修改成
<property name="globs">*.rb;*.rake;*.rjs</property>
然後存檔離開.

再輸入

sudo nano /usr/share/gtksourceview-2.0/language-specs/html.lang

找到
<property name="globs">*..html;*.htm</property>
修改成
<property name="globs">*.html;*.htm;*.erb;*.rhtml</property>
存檔離開.
再開啟Gedit,就應該顯示正常了. :D

--參考資料 :
http://rorblog.techcfl.com/2008/04/19/erb-syntax-highlighting-in-gedit/
把Gedit打造為Linux下的Textmate
Textmate-like Gedit in few steps
HOWTO: add support for .rhtml, .html.erb, .rjs, .rxml, .builder
Textmate 官方首頁

4Oct/092

Rails on Ubuntu 9.04 Installtion

由於在Ubuntu下安裝Rails是一件有點煩的事,還要ln, 而且有時候有lib相依問題.
不是單純 apt-get install ruby rails 就可以.
所以就把自己安裝的經驗寫下來,下次自己安裝方便,而也可以分享.

打開Console輸入,這樣安裝包含了 Ruby, IRB, RdoC, Mysql, Sqlite, Sqlite3, 以及Libs , Dev

sudo apt-get install ruby irb rdoc libopenssl-ruby mysql-server sqlite3 sqlite libsqlite3-ruby libsqlite-ruby libmysql-ruby ruby1.8-dev

到官方下載 Rails Gem 這篇文章時,Gem為1.3.5版,點我下載1.3.5.tgz.
將之解壓縮並在Console cd到資料夾下

ruby setup.rb

再修正9.04下的安裝路徑連結錯誤

ln /usr/bin/gem1.8 /usr/bin/gem

安裝Rails

gem install rails

安裝Rake 及 Mongrel

sudo apt-get install rake mongrel

打完收工,Done!!

完成之後,可以再參考這篇Textmate on Ubuntu - Gedit

30Sep/090

更多的Google map on Rails plugins,以及Rails Gis Hacks.

睡前偶然看到這帖.
裡面寫非了蠻多在Rails上實做gmap的plugin.
除了Geokit+YM4R 還又其他 :
acts_as_geocodable , actsaslocateable .

不過看一看還是geokit比較好,至於YM4R... 我還是想自己寫...
這裡有一本寫關於gmap實作的,偶然間看到的 有興趣看看吧.