I'm not a used-to blogger, so it has been a long time to insert a single thread.
As a Java newbie, I decided to have some sort of certification on it, to give myself a test and increase my competitive power.
Finally, got the SCJP certification on 8 of June, 2007 :)
Tuesday, June 12, 2007
Friday, February 9, 2007
Mongrel 1.0.1 + Rails 1.1.6 + Ruby 1.8.5
Try to deploy the application in FreeBSD with the combination mentioned, amazingly.... SLOW.... I don't know what's wrong with it, the Mongrel cluster making the system overhead when process only one single simple request, what's wrong with the latest version?? I switch back to Mongrel previous stable version, it performing very good.
Sunday, February 4, 2007
Spring IoC Learning Note 1 - Hello World
recently start to study springframework.org; The Spring Framework (or Spring for short) is an open source application framework for the Java platform (Definition from Wikipedia). It introduce the so-called 'lightweight framework' to Java world to be an alternative of the 'heavy-weight framework' like Enterprise JavaBean.
first step, write hello world.
Use XML beans definition to inject the collaborator.
So, lets get the Bean!!
Use ant to run the task
Done :-)
first step, write hello world.
//MessageProvider.java
package org.nixeon.ioctest;
public interface MessageProvider {
public String getMessage();
}
//MessageRenderer.java
package org.nixeon.ioctest;
public interface MessageRenderer {
public MessageProvider getMessageProvider();
public void setMessageProvider(MessageProvider mp);
public void render();
}
//HelloWorldProvider.java
package org.nixeon.ioctest;
public class HelloWorldProvider implements MessageProvider {
public String getMessage(){
return "Hello World!";
}
}
//HelloWorldRenderer.java
package org.nixeon.ioctest;
public class HelloWorldRenderer implements MessageRenderer {
private MessageProvider messageProvider;
public void setMessageProvider(MessageProvider mp){
messageProvider = mp;
}
public MessageProvider getMessageProvider(){
return messageProvider;
}
public void render(){
System.out.println(messageProvider.getMessage());
}
}Use XML beans definition to inject the collaborator.
<!--messenger-meta.xml-->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="renderer" class="org.nixeon.ioctest.HelloWorldRenderer">
<property name="messageProvider">
<ref local="provider"/>
</property>
</bean>
<bean id="provider" class="org.nixeon.ioctest.HelloWorldProvider"/>
</beans>
So, lets get the Bean!!
//Messenger.java
package org.nixeon.ioctest;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.nixeon.ioctest.MessageRenderer;
public class Messenger {
public static void main (String [] args) throws Exception {
BeanFactory factory = getBeanFactory();
MessageRenderer mr = (MessageRenderer) factory.getBean("renderer");
mr.render();
}
private static BeanFactory getBeanFactory() throws Exception {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"messenger-meta.xml"));
return factory;
}
}
Use ant to run the task
Buildfile: build.xml
run:
[java] Feb 4, 2007 5:01:38 PM org.springframework.core.CollectionFactory
[java] INFO: JDK 1.4+ collections available
[java] Feb 4, 2007 5:01:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[java] INFO: Loading XML bean definitions from file [D:\java_workspace\ioctest\messenger-meta.xml]
[java] Hello World!
BUILD SUCCESSFUL
Total time: 1 second
Done :-)
Monday, January 29, 2007
无神论 by 黄立行 Stanley Huang
i wanna believe in all the miracles too
i wanna believe in all the the fairy tales with you
i want the happy ever after really i do
but how can that be when i don't know if heavens true
but theses no eternity for an atheist like me
when i die is that the end no other way in
i'll never see your face again again again again babe
i want die happy ever after i want it with you
but how can that be when i don't know if heavens true
but theses no eternity for an atheist like me
when i die is that the end no other way in
i'll never see your face again again again again babe
and if you should go without me
just promise me that you will always be happy
我希望相信世界有
奇迹出现
我想要我们的童话
不只是瞬间
我希望今后都能快乐
永不分离
但我上不去天堂
我不能够陪你
不存在一种永恒
不相信世界有神
死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念
我真的希望我们快乐
永不分离
只有你能上天堂
我到不了那里
只要想念没改变
不管多远
我会在你心里面
死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念
i wanna believe in all the the fairy tales with you
i want the happy ever after really i do
but how can that be when i don't know if heavens true
but theses no eternity for an atheist like me
when i die is that the end no other way in
i'll never see your face again again again again babe
i want die happy ever after i want it with you
but how can that be when i don't know if heavens true
but theses no eternity for an atheist like me
when i die is that the end no other way in
i'll never see your face again again again again babe
and if you should go without me
just promise me that you will always be happy
我希望相信世界有
奇迹出现
我想要我们的童话
不只是瞬间
我希望今后都能快乐
永不分离
但我上不去天堂
我不能够陪你
不存在一种永恒
不相信世界有神
死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念
我真的希望我们快乐
永不分离
只有你能上天堂
我到不了那里
只要想念没改变
不管多远
我会在你心里面
死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念
Thursday, January 25, 2007
Prototype.js 1.5 API Doc
Ruby/Javascript lovers are happy to receive the gift from Prototype.js team. Finally, Prototype.js 1.5 is released to be the stable version and another surprise -- the API doc :-)
http://prototypejs.org/api
http://prototypejs.org/api
Monday, January 15, 2007
FreeBSD+Mongrel Cluster+Pound, Kickass Rails Environment
How easy to setup a Rails web server?? you may try this combination, FMcP(FreeBSD+Mongrel_Cluster+Pound). Note that pound is not a web server, it's just a reverse proxy and balancer that interact with mongrel clusters.
step 1: install mongrel & mongrel_cluster
$sudo gem install mongrel
$sudo gem install mongrel_cluster
step 2: install Pound reverse proxy
$pkg_add -r pound
[/usr/local/etc/pound.cfg]
ListenHTTP 0.0.0.0,80
UrlGroup ".*"
BackEnd 127.0.0.1,8000,1
BackEnd 127.0.0.1,8001,1
BackEnd 127.0.0.1,8002,3
EndGroup
UrlGroup ".*.(js|css|jpg|jpeg|bmp|gif|swf)"
BackEnd 127.0.0.1,8003,1
BackEnd 127.0.0.1,8004,1
EndGroup
[end]
$echo "pound_enable=\"YES\"" >> /etc/rc.conf
step 3: configure mongrel cluster
$cd railsapp
$mongrel_rails cluster::configure -a 127.0.0.1 -p 8000 -N 5 -e production
$mongrel_rails cluster::start
$tail log/mongrel.log <-- to see whether the service start successfully
step 4: start pound
$pound -f /usr/local/etc/pound.cfg
That's it!! Run ur rails app at http://127.0.0.1
more about Pound
step 1: install mongrel & mongrel_cluster
$sudo gem install mongrel
$sudo gem install mongrel_cluster
step 2: install Pound reverse proxy
$pkg_add -r pound
[/usr/local/etc/pound.cfg]
ListenHTTP 0.0.0.0,80
UrlGroup ".*"
BackEnd 127.0.0.1,8000,1
BackEnd 127.0.0.1,8001,1
BackEnd 127.0.0.1,8002,3
EndGroup
UrlGroup ".*.(js|css|jpg|jpeg|bmp|gif|swf)"
BackEnd 127.0.0.1,8003,1
BackEnd 127.0.0.1,8004,1
EndGroup
[end]
$echo "pound_enable=\"YES\"" >> /etc/rc.conf
step 3: configure mongrel cluster
$cd railsapp
$mongrel_rails cluster::configure -a 127.0.0.1 -p 8000 -N 5 -e production
$mongrel_rails cluster::start
$tail log/mongrel.log <-- to see whether the service start successfully
step 4: start pound
$pound -f /usr/local/etc/pound.cfg
That's it!! Run ur rails app at http://127.0.0.1
more about Pound
Sunday, January 14, 2007
PEAR.... em.. what it is??
"I like PHP because it has alot of library, like pear,gd2....",
"oh? so what is pear??"
"pear is a extension for us to load more php library...."
"......... superb!... how is it works???"
"......"
Some windows PHP developer may not know they have a PHP package-manager in their PC. PEAR stands for "PHP Extension and Application Repository". The instruction shown below may "enable" the PEAR with your PHP in your windows box:
1.execute C:\PHP\go-pear.bat the cmd-line wizard will shown, just choose ur best option.
2. make sure the include_path=".;C:\PHP\pear;c:\php\includes" entry is set in ur php.ini
3. thats it, run the pear command by using the command php.exe c:\php\pear\pearcmd.php you'll see the usage of it
you can manage the PHP extended library by using pear, like install, remove, list and so on. just like yum, apt-get, pkg_add in linux and BSD.
"oh? so what is pear??"
"pear is a extension for us to load more php library...."
"......... superb!... how is it works???"
"......"
Some windows PHP developer may not know they have a PHP package-manager in their PC. PEAR stands for "PHP Extension and Application Repository". The instruction shown below may "enable" the PEAR with your PHP in your windows box:
1.execute C:\PHP\go-pear.bat the cmd-line wizard will shown, just choose ur best option.
2. make sure the include_path=".;C:\PHP\pear;c:\php\includes" entry is set in ur php.ini
3. thats it, run the pear command by using the command php.exe c:\php\pear\pearcmd.php you'll see the usage of it
you can manage the PHP extended library by using pear, like install, remove, list and so on. just like yum, apt-get, pkg_add in linux and BSD.
上帝给我们机会相遇,却没有给我们时间相爱
Remarks: Nice post from other forum... ya, it's written chinese, I'm not goin to translate. learn chinese if you're interested :p
“有一种人,我们注定一辈子不能拥有。上帝给了机会让我们相遇,却没留时间给我们相爱。”看到这句话时,心跳突然停止,呼吸突然遏止。花非花,雨非雨,非梦非醒,非痴非醉。幸福似乎很近又似乎很遥远,犹如流星瞬间划过星空却无法把它抓牢。
或许,我还无法深刻地理解这句话其中的意义。但是,我深深地感受到了你的心声。有时,我们不需要言语,不需要见面,却可以心灵相通,直到现在我也没有后悔相遇,更要感谢上苍,给了我们那么美丽的相遇。
爱,没有谁对谁错。只有缘浅缘深。爱,其实很容易,就是轻轻地把你放进我的心里。爱,其实不容易,就是无法走进你的心里。有一道门,我们永远都打不开,因为我们拿错了钥匙。或者说,是我们走错了门。迷失地我们,竟然把所有门都当成了一种,如果只是想要取暖,如果只是想要关怀,其实并不一定只有爱才可以拥有。
曾,多想做你的专属天使,多想带你飞向我的天堂。拥有你,哪还需要别的愿望,没有谁能取代你在我心上。今,我的心从没有搬到另一个地址,也无法为你而留。我也明白,有一种人,这一辈子只能做朋友,哪怕相爱也一样无法跨越那道打不开的门。
我们在伤痕累累后相遇,我们在痛彻心非时拥抱。我们怕彼此再次受到伤害,我们都想彼此可以幸福,所以我们不得不忍痛舍弃。只为了微笑着说再见。有时,放弃很容易,为了更值得我们去做的事去为的人,那就真的很容易。
我们只懂付出,不求回报。我们只会为对方着想,我们只想一个人承受一切。我们相信,放弃后对方就可以拥有更好的幸福。太多的我们,太多的善良,太多的关心,太多的了解,太多的相似。我们注定再美丽的相遇,也无法相爱。
放弃相爱,并不是放弃彼此。我们在最美丽的邂逅之后,上演一幕最动人的人生。
“有一种人,我们注定一辈子不能拥有。上帝给了机会让我们相遇,却没留时间给我们相爱。”看到这句话时,心跳突然停止,呼吸突然遏止。花非花,雨非雨,非梦非醒,非痴非醉。幸福似乎很近又似乎很遥远,犹如流星瞬间划过星空却无法把它抓牢。
或许,我还无法深刻地理解这句话其中的意义。但是,我深深地感受到了你的心声。有时,我们不需要言语,不需要见面,却可以心灵相通,直到现在我也没有后悔相遇,更要感谢上苍,给了我们那么美丽的相遇。
爱,没有谁对谁错。只有缘浅缘深。爱,其实很容易,就是轻轻地把你放进我的心里。爱,其实不容易,就是无法走进你的心里。有一道门,我们永远都打不开,因为我们拿错了钥匙。或者说,是我们走错了门。迷失地我们,竟然把所有门都当成了一种,如果只是想要取暖,如果只是想要关怀,其实并不一定只有爱才可以拥有。
曾,多想做你的专属天使,多想带你飞向我的天堂。拥有你,哪还需要别的愿望,没有谁能取代你在我心上。今,我的心从没有搬到另一个地址,也无法为你而留。我也明白,有一种人,这一辈子只能做朋友,哪怕相爱也一样无法跨越那道打不开的门。
我们在伤痕累累后相遇,我们在痛彻心非时拥抱。我们怕彼此再次受到伤害,我们都想彼此可以幸福,所以我们不得不忍痛舍弃。只为了微笑着说再见。有时,放弃很容易,为了更值得我们去做的事去为的人,那就真的很容易。
我们只懂付出,不求回报。我们只会为对方着想,我们只想一个人承受一切。我们相信,放弃后对方就可以拥有更好的幸福。太多的我们,太多的善良,太多的关心,太多的了解,太多的相似。我们注定再美丽的相遇,也无法相爱。
放弃相爱,并不是放弃彼此。我们在最美丽的邂逅之后,上演一幕最动人的人生。
How to build a simple Radius Tag
In RadiantCMS (CMS system written in Rails), developers use Radius Tag to render the view content instead of ActionView. Here's a small tips to generate your own tag.
to render a text:
define_tag 'hello' do |tag|
'Hello World!'
end
<r:hello/> will output 'Hello World!'
to render with attribute(s):
define_tag 'hello' do |tag|
name = tag.attr["name"]||'World'
'Hello #{name}!'
end
<r:hello name="nixeon"> will output 'Hello nixeon!'; if name is not present, still show 'Hello World!'
to render using current page info:
define_tag 'hello' do |tag|
page = tag.locals.page
"Hello! #{page.title}"
end
<r:hello> will output "Hello! current_page_title"
to render content inside of tags:
define_tag 'hello' do |tag|
name = tag.expand
"Hello #{name}!"
end
<r:hello>Nixeon</r:hello> will output "Hello Nixeon!"
easy huh? tags can be also defined in behavior by using define_tags method to initialize the batch tags definition.
more about radiantCMS, visit the official official site
to render a text:
define_tag 'hello' do |tag|
'Hello World!'
end
<r:hello/> will output 'Hello World!'
to render with attribute(s):
define_tag 'hello' do |tag|
name = tag.attr["name"]||'World'
'Hello #{name}!'
end
<r:hello name="nixeon"> will output 'Hello nixeon!'; if name is not present, still show 'Hello World!'
to render using current page info:
define_tag 'hello' do |tag|
page = tag.locals.page
"Hello! #{page.title}"
end
<r:hello> will output "Hello! current_page_title"
to render content inside of tags:
define_tag 'hello' do |tag|
name = tag.expand
"Hello #{name}!"
end
<r:hello>Nixeon</r:hello> will output "Hello Nixeon!"
easy huh? tags can be also defined in behavior by using define_tags method to initialize the batch tags definition.
more about radiantCMS, visit the official official site
Using ActiveRecord externally
Try to write a ruby executable code using ActiveRecord to interact with mysql db. actually the method has been present in Pragmatic's Rails Recipes #26, but the code seems to be missing something before require 'active_record'. Actually, require 'rubygems' must be added before it, as active_record is resides in the gems' path.
here's the code, its actually a simple schedule-able program for me to retrieve yahoo finance data and insert it to the database, which later may use the same model to retrieve it from Rails.
Some strange thing happen here, u may see the line stock.updated_at = Time.now logically it should not be presented here... it should use the ActiveRecord's brefore_save callback to fill the attribute. But callbacks seems to be not working if I use ActiveRecord external Rails... :-(
here's the code, its actually a simple schedule-able program for me to retrieve yahoo finance data and insert it to the database, which later may use the same model to retrieve it from Rails.
require 'rubygems'
require 'active_record'
require 'yaml'
require File.join(File.dirname(__FILE__),"../app/models/http_getter")
require File.join(File.dirname(__FILE__),"../app/models/stock")
logger = Logger.new(File.join(File.dirname(__FILE__),"../log/stocks.log"))
ActiveRecord::Base.establish_connection(YAML.load_file(
File.join(File.dirname(__FILE__),"../config/database.yml"))["development"]
)
ActiveRecord::Base.logger = logger
fields = %w{ symbol current_price update_date update_time change open range_to range_from volumn}
symbol = ARGV[0]
url = "http://sg.finance.yahoo.com"
resource = "/d/quotes.csv?s=#{symbol}&f=sl1d1t1c1ohgv&e=.csv"
data = HttpGetter.csv_start(url,resource,fields)
stock = Stock.new(data)
stock.updated_at = Time.now
unless stock.save
logger.error("ERROR: Can't save the record!")
logger.error("ERROR_OBJ_DUMP: "+stock.inspect)
logger.error("ERROR_DATA_DUMP: "+data.inspect)
else
logger.info("SUCCESS "+stock.updated_at.to_s+": Record Saved. Symbol:"+stock.symbol)
end
Some strange thing happen here, u may see the line stock.updated_at = Time.now logically it should not be presented here... it should use the ActiveRecord's brefore_save callback to fill the attribute. But callbacks seems to be not working if I use ActiveRecord external Rails... :-(
New B10g is here
I am not going to update my chinese blog anymore... maybe sometime later.
here's my new blog which written in English. hope tat my poor english can be improved :-D
here's my new blog which written in English. hope tat my poor english can be improved :-D
Subscribe to:
Posts (Atom)