Friday, December 30, 2005

 

為Steve Jobs設計的電影海報

Design a Steve Jobs Movie Poster
如果Steve Jobs拍了部電影
不知道他的電影海報會不會這麼有趣
其中我覺得最好笑的就是這張The Lord of the iPods裡面的那個Gollum XD


Wednesday, December 28, 2005

 

狂賀shumi正取師大資教所!

恭喜shumi推甄上了國立台灣師範大學 資訊教育研究所 數位學習組
再度成為我的學妹 XD
而且還是正取第二名喔 :)

這是榜單


Monday, December 26, 2005

 

Secrets of the Millionaire Mind

Secrets of the Millionaire Mind
有錢人想的和你不一樣
博客來關於此書的簡介

嗚嗚嗚~博客來賣的竟然更便宜!
早知道就在博客來買了
就不用跑好幾間書店找這麼久

這本書中的很多觀念都很不錯
其實也可以不要把當作理財的書來看
生活中很多地方都可以用到書中的觀念和守則
的確是本值得看的書喔!


 

Lord of the Flies

蒼蠅王 Lord of the Flies

這大概是本學期看到現在最令我震撼的電影吧!
尤其聽了老師的解釋感觸更多

有關這本書和電影的介紹也很多
大部分的人提到了另外兩部電影
漂流教室大逃殺
有機會希望能看看
不過我對於大逃殺沒什麼好感
光看簡介就覺得太恐怖了!!
我還是喜歡喜劇 這種東西太嚴肅了!!


Wednesday, December 21, 2005

 

Burning My Feed

http://feeds.feedburner.com/ciyawasay

雖然我不知道燒這個feed有什麼好處
不過還是趕個流行吧 @@

這東西似乎是可以讓別人就算用browser直接連到我的feed
還是可以看到不錯的網頁介面,而不是直接秀出恐怖的XML
Blogger其實已經有這種功能了
不過這個站除了提供比較好看的介面,還提供一些分析的功能
嗯嗯...其實好像還有更多其他功能
先用用看再慢慢研究吧~

後記:
經過一番研究後
我發現這個FeedBurner實在是功能太強大了
不只是可以給你分析數據
也提供許多web 2.0的服務
像是結合我的Flickr、del.icio.us一起發佈到這個feed中
甚至Google AdSense也可以加進來(Ya!)
只可惜對中文的支援很差
不過它還真是個蠻酷的東西 :)


 

Observer Pattern - OO and AO Implementation

參考Aspect-Oriented Design Pattern Implementations
由於版面關係,覺得字體太小請麻煩自行用瀏覽器放大

OOP Implementation

AOP Implementation

  ObserverProtocol.java

import java.util.WeakHashMap;
import java.util.List;
import java.util.LinkedList;

public abstract aspect ObserverProtocol {

   protected interface Subject {}

   protected interface Observer {}

   private WeakHashMap<Subject, List<Observer>> perSubjectObservers;

   protected List<Observer> getObservers(Subject subject) {
      if (perSubjectObservers == null) {
         perSubjectObservers = new WeakHashMap<Subject, List<Observer>>();
      }
      List<Observer> observers = perSubjectObservers.get(subject);
      if (observers == null) {
         observers = new LinkedList<Observer>();
         perSubjectObservers.put(subject, observers);
      }
      return observers;
   }

   public void addObserver(Subject subject, Observer observer) {
      getObservers(subject).add(observer);
   }

   public void removeObserver(Subject subject, Observer observer) {
      getObservers(subject).remove(observer);
   }

   protected abstract pointcut subjectChange(Subject s);

   after(Subject subject): subjectChange(subject) {
      for (Observer o : getObservers(subject)) {
         updateObserver(subject, o);
      }
   }

   protected abstract void updateObserver(Subject subject, Observer observer);
}
Point.java

import java.awt.Color;
import java.util.HashSet;

public class Point implements ChangeSubject {

   private HashSet<ChangeObserver> observers;

   private int x;

   private int y;

   private Color color;

   public Point(int x, int y, Color color) {
      this.x = x;
      this.y = y;
      this.color = color;
      this.observers = new HashSet<ChangeObserver>();
   }

   public int getX() {
      return x;
   }

   public int getY() {
      return y;
   }

   public void setX(int x) {
      this.x = x;
      notifyObservers();
   }

   public void setY(int y) {
      this.y = y;
      notifyObservers();
   }

   public Color getColor() {
      return color;
   }

   public void setColor(Color color) {
      this.color = color;
      notifyObservers();
   }

   public void addObserver(ChangeObserver o) {
      this.observers.add(o);
   }

   public void removeObserver(ChangeObserver o) {
      this.observers.remove(o);
   }

   public void notifyObservers() {
      for (ChangeObserver o : observers) {
         o.refresh(this);
      }
   }
}
Point.java

import java.awt.Color;

public class Point {

   private int x;

   private int y;

   private Color color;

   public Point(int x, int y, Color color) {
      this.x = x;
      this.y = y;
      this.color = color;
   }

   public int getX() {
      return x;
   }

   public int getY() {
      return y;
   }

   public void setX(int x) {
      this.x = x;
   }

   public void setY(int y) {
      this.y = y;
   }

   public Color getColor() {
      return color;
   }

   public void setColor(Color color) {
      this.color = color;
   }
}
Screen.java

import java.util.HashSet;

public class Screen implements ChangeSubject, ChangeObserver {

   private HashSet<ChangeObserver> observers;

   private String name;

   public Screen(String s) {
      this.name = s;
      observers = new HashSet<ChangeObserver>();
   }

   public void display(String s) {
      System.out.println(name + ": " + s);
      notifyObservers();
   }

   public void addObserver(ChangeObserver o) {
      this.observers.add(o);
   }

   public void removeObserver(ChangeObserver o) {
      this.observers.remove(o);
   }

   public void notifyObservers() {
      for (ChangeObserver o : observers) {
         o.refresh(this);
      }
   }

   public void refresh(ChangeSubject s) {
      String subjectTypeName = s.getClass().getName();
      subjectTypeName = subjectTypeName.substring(subjectTypeName
            .lastIndexOf(".") + 1, subjectTypeName.length());
      display("update received from a " + subjectTypeName + " object");
   }
}
Screen.java

public class Screen {

   private String name;

   public Screen(String s) {
      this.name = s;
   }

   public void display(String s) {
      System.out.println(name + ": " + s);
   }
}
ChangeSubject.java

public interface ChangeSubject {

   public void addObserver(ChangeObserver o);

   public void removeObserver(ChangeObserver o);

   public void notifyObservers();
}
CoordinateObserver.java

public aspect CoordinateObserver extends ObserverProtocol {

   declare parents: Point  implements Subject;

   declare parents: Screen implements Observer;

   protected pointcut subjectChange(Subject subject): 
      (call(void Point.setX(int)) ||
       call(void Point.setY(int)) ) && target(subject);

   protected void updateObserver(Subject subject, Observer observer) {
      ((Screen) observer)
            .display("Screen updated (point subject changed coordinates).");
   }
}
ChangeObserver.java

public interface ChangeObserver {

   public void refresh(ChangeSubject s);
}
ColorObserver

import java.awt.Color;

public aspect ColorObserver extends ObserverProtocol {

   declare parents: Point  implements Subject;

   declare parents: Screen implements Observer;

   protected pointcut subjectChange(Subject subject): 
      call(void Point.setColor(Color)) && target(subject);

   protected void updateObserver(Subject subject, Observer observer) {
      ((Screen) observer)
            .display("Screen updated (point subject changed color).");
   }
}
  ScreenObserver.java

public aspect ScreenObserver extends ObserverProtocol {

   declare parents: Screen implements Subject;

   declare parents: Screen implements Observer;

   protected pointcut subjectChange(Subject subject): 
      call(void Screen.display(String)) && target(subject);

   protected void updateObserver(Subject subject, Observer observer) {
      ((Screen) observer)
            .display("Screen updated (screen subject displayed message).");
   }
}
Main.java

import java.awt.Color;

public class Main {

   public static void main(String argv[]) {
      // Creating Screen s1,s2,s3,s4,s5 and Point p
      Screen s1 = new Screen("s1");
      Screen s2 = new Screen("s2");
      Screen s3 = new Screen("s3");
      Screen s4 = new Screen("s4");
      Screen s5 = new Screen("s5");
      Point p = new Point(5, 5, Color.blue);

      // s1 and s2 observe color changes to p
      p.addObserver(s1);
      p.addObserver(s2);

      // s3 and s4 observe coordinate changes to p
      p.addObserver(s3);
      p.addObserver(s4);

      // s5 observes s2's and s4's display() method
      s2.addObserver(s5);
      s4.addObserver(s5);

      System.out.println("Changing p's color:");
      p.setColor(Color.red);

      System.out.println("Changing p's x-coordinate:");
      p.setX(4);
   }
}
Main.java

import java.awt.Color;

public class Main {

   public static void main(String argv[]) {
      // Creating Screen s1,s2,s3,s4,s5 and Point p
      Screen s1 = new Screen("s1");
      Screen s2 = new Screen("s2");
      Screen s3 = new Screen("s3");
      Screen s4 = new Screen("s4");
      Screen s5 = new Screen("s5");
      Point p = new Point(5, 5, Color.blue);

      // s1 and s2 observe color changes to p
      ColorObserver.aspectOf().addObserver(p, s1);
      ColorObserver.aspectOf().addObserver(p, s2);

      // s3 and s4 observe coordinate changes to p
      CoordinateObserver.aspectOf().addObserver(p, s3);
      CoordinateObserver.aspectOf().addObserver(p, s4);

      // s5 observes s2's and s4's display() method
      ScreenObserver.aspectOf().addObserver(s2, s5);
      ScreenObserver.aspectOf().addObserver(s4, s5);

      System.out.println("Changing p's color:");
      p.setColor(Color.red);

      System.out.println("Changing p's x-coordinate:");
      p.setX(4);
   }
}
Output
Changing p's color:
s1: update received from a Point object
s2: update received from a Point object
s5: update received from a Screen object
s3: update received from a Point object
s4: update received from a Point object
s5: update received from a Screen object
Changing p's x-coordinate:
s1: update received from a Point object
s2: update received from a Point object
s5: update received from a Screen object
s3: update received from a Point object
s4: update received from a Point object
s5: update received from a Screen object
Output
Changing p's color:
s1: Screen updated (point subject changed color).
s2: Screen updated (point subject changed color).
s5: Screen updated (screen subject displayed message).
Changing p's x-coordinate:
s3: Screen updated (point subject changed coordinates).
s4: Screen updated (point subject changed coordinates).
s5: Screen updated (screen subject displayed message).
Problem
  • design pattern侵入原本的程式,將之複雜化
  • 如果要將observer再加以功能區分,程式將會更複雜
Improvement
  • 更好的模組化
  • 容易擴充、縮減

Tuesday, December 20, 2005

 

The Christmas Song

Chestnuts roasting on an open fire,
Jack Frost nipping on your nose,
Yuletide carols being sung by a choir,
And folks dressed up like Eskimos.

Everybody knows a turkey and some mistletoe,
Help to make the season bright.
Tiny tots with their eyes all aglow,
Will find it hard to sleep tonight.

They know that Santa's on his way;
He's loaded lots of toys and goodies on his sleigh.
And every mother's child is going to spy,
To see if reindeer really know how to fly.

And so I'm offering this simple phrase,
To kids from one to ninety-two,
Although its been said many times, many ways,
A very Merry Christmas to you!

聖誕節快到啦~
為大家帶來一首我十分喜歡的聖誕歌曲
這首The Christmas Song是於1944年,Mel Torme與Bob Wells所寫,Nat King Cole所唱
除了是電影中配樂的常客外
也有許多人拿來翻唱
我最早是在看Catch Me If You Can這部電影中聽到的
劇情很感人我就不多說了
反正就是祝大家聖誕快樂囉 :)


Sunday, December 18, 2005

 

TIME Magazine's Person of the Year in Times Square

有沒有看到我的照片被貼在Time Square上廣告的照片阿?
最近Time辦了一個有趣的人人都可以當Person of the Year活動
網址在http://www.impoy.com/
跟我一樣無聊的人可以去參加
雖然看起來還真的蠻好笑就是...


Friday, December 16, 2005

 

String Escaper 0.1

download now
使用方法:
解壓縮後在有java的windows環境下執行run.bat
使用ctrl+x (剪下)、ctrl+c (複製)、ctrl+v (貼上)與上面的按鈕進行操作

之前在玩Jakarta Commons
看到了一個還蠻有意思的class
就是org.apache.commons.lang.StringEscapeUtils
它可以幫你把一些特殊字元在各種不同的應用中進行跳脫
我也為這個有趣的class弄了一個對我而言還算方便(其實是簡陋)的GUI介面來使用
最近卻發現我使用它的機會還蠻大的
像是在blog上po程式碼的時候...
所以雖然程式很簡單我還是跟大家分享一下
歡迎大家為它弄出一個更好的介面或功能再分享回來 :)
code:


package org.swanky.tools;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;

import org.apache.commons.lang.StringEscapeUtils;

/**
 * StringEscaper
 * 
 * @author swanky
 * @version 0.1, 2005-11-27
 */
@SuppressWarnings("serial")
public class StringEscaper extends JFrame {
   /** frame width */
   public static final int WIDTH = 1024;

   /** frame height */
   public static final int HEIGHT = 768;

   /** text area */
   private JTextArea ta = new JTextArea();

   /** tool bar */
   private JToolBar toolBar = new JToolBar();

   /**
    * constractor
    * 
    * @param arg0
    *            frame title
    * @throws HeadlessException
    */
   public StringEscaper(String arg0) throws HeadlessException {
      super(arg0);
      ta.setFont(new Font("Courier New", Font.PLAIN, 12));
   }

   public static void main(String[] args) {
      StringEscaper f = new StringEscaper("String Escaper");

      // add actions
      f.toolBar.add(f.new EscapeHTML());
      f.toolBar.add(f.new EscapeJava());
      f.toolBar.add(f.new EscapeJavaScript());
      f.toolBar.add(f.new EscapeSQL());
      f.toolBar.add(f.new EscapeXML());

      // set components on content pane
      f.add(f.toolBar, BorderLayout.NORTH);
      JScrollPane sp = new JScrollPane(f.ta);
      f.add(sp, BorderLayout.CENTER);

      // show frame
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(WIDTH, HEIGHT);
      f.setVisible(true);
   }

   class EscapeHTML extends AbstractAction {
      EscapeHTML() {
         putValue(Action.NAME, "EscapeHTML");
         putValue(Action.SHORT_DESCRIPTION, "Escape HTML");
      }

      public void actionPerformed(ActionEvent arg0) {
         ta.setText(StringEscapeUtils.escapeHtml(ta.getText()));
      }
   }

   class EscapeJava extends AbstractAction {
      EscapeJava() {
         putValue(Action.NAME, "EscapeJava");
         putValue(Action.SHORT_DESCRIPTION, "Escape Java");
      }

      public void actionPerformed(ActionEvent arg0) {
         ta.setText(StringEscapeUtils.escapeJava(ta.getText()));
      }
   }

   class EscapeJavaScript extends AbstractAction {
      EscapeJavaScript() {
         putValue(Action.NAME, "EscapeJavaScript");
         putValue(Action.SHORT_DESCRIPTION, "Escape JavaScript");
      }

      public void actionPerformed(ActionEvent arg0) {
         ta.setText(StringEscapeUtils.escapeJavaScript(ta.getText()));
      }
   }

   class EscapeSQL extends AbstractAction {
      EscapeSQL() {
         putValue(Action.NAME, "EscapeSQL");
         putValue(Action.SHORT_DESCRIPTION, "Escape SQL");
      }

      public void actionPerformed(ActionEvent arg0) {
         ta.setText(StringEscapeUtils.escapeSql(ta.getText()));
      }
   }

   class EscapeXML extends AbstractAction {
      EscapeXML() {
         putValue(Action.NAME, "EscapeXML");
         putValue(Action.SHORT_DESCRIPTION, "Escape XML");
      }

      public void actionPerformed(ActionEvent arg0) {
         ta.setText(StringEscapeUtils.escapeXml(ta.getText()));
      }
   }
}


 

Eclipse 3.1記憶體調教

JavaWorld@TW中的一個討論串
改了以後真的有差喔~ :)
下面的是我改的數值:

-vmargs
-Xms128m
-Xmx512m
-XX:MaxPermSize=128m
-Dcom.sun.management.jmxremote
-XX:+UseParallelGC


Wednesday, December 14, 2005

 

AOP Presentation

這兩個禮拜我在group meeting的AOP報告
上禮拜報告投影片的前兩個部分
這禮拜show了eclipse+AJDT、Java logging API、JUnit與三個AspectJ的範例程式
不過投影片後面的兩個部分應該要以後再說了 @@

然後目前的研究目標就訂為探討AOP對OOP能作的改進
以及AOP如何與workflow system中的各個元件配合
怎麼去設計、實作其中的種種問題


Tuesday, December 13, 2005

 

Google AdSense

最近開始在blog上掛上許多廣告
也就是Google的AdSense
目的是希望賺了很多錢、挖了很多角的Google能夠也分一些美金給我

目前AdSense有幾種廣告方式
第一種最常見的就是AdSense for Content
許多大網站在旁邊都有這種提供公司或是產品連結的一個區塊
可以是文字或是圖片的連結
我把這種廣告放在我blog名稱的旁邊
但是卻發現在我這個充滿中文的blog中
會出現所謂的公益廣告
只有在當該網頁的內容裡面出現了足夠的關鍵字之後
才會變成有用的廣告
而關鍵字目前大多為英文的
所以只有在我的某些文章單篇連結頁面中才會有辦法出現有用的廣告連結
以後看到這種不是公益廣告的廣告可以放心的點下去沒有關係

第二種是AdSense for Search
也就是左邊那個提供網站搜尋的小表單欄位
可以讓你用Google針對我的站進行搜尋
搜尋的結果頁面會出現廣告
在裡面點選廣告或是連結的時候就可以賺到錢

第三種是Referrals
像我左邊那兩個AdSense與Firefox Toolbar的button就是這種特殊目的的廣告
點了以後你申請AdSense的帳號,或是下載了Firefox Toolbar
這筆帳就會算在我的頭上
現在你是不是很心動想要在你的網站或是blog上加上這些廣告呢?
點選本站旁邊的"Get targeted ads on your site with Google AdSense"有個綠白勾勾的button
馬上開始你的賺洋人錢的夢想吧!

P.S.
但也要你的網站人氣夠旺才真的賺得到錢啦...
像我擺這麼久了也賺沒有美金0.3元...(都是自己狂點...)


 

Mozart is Good

Mutter - Mozart: The Violin Concertos

有仔細看過The Incredibles(超人特攻隊)的應該會記得裡面有個少根筋的保母在當保母的時候放Mozart給小超人聽
結果小超人聽一聽就High起來變成超人了...
這是因為根據某某研究指出聽Mozart會讓小朋友變聰明
因此產生了近年來流行的Mozart Effect
除了放給出生了或是還沒出生的小朋友聽以外
還有放給大人聽的
說是可以增加工作的效率、舒緩壓力等等功效
雖然說是真是假還沒有個絕對的說法
不過Mozart的音樂真的是相當地好聽
這張我前些日子買的「Mutter - Mozart: The Violin Concertos」就還蠻不賴的
最近看書時或是看書看累了就會放來聽聽
不但頭腦變清楚
精神變好
而且整個人都變得有氣質起來 (自己感覺)

雖然演奏者好像很有名
但我對這方面沒有什麼研究
所以也沒有什麼好介紹
另外2006年是Mozart的250年生日
所以明年應該也會有很多Mozart的新專輯出來祝他生日快樂
大家可以去聽聽看囉~