Archive for the ‘Uncategorized’ Category

Microsoft TouchWall!!~

Thursday, May 15th, 2008

今日 CodeProject 個Daily Newsletter – Microsoft TouchWall can inexpensively turn any flat surface into a multi-touch display 介紹 TouchWall, 睇落幾正, 佢話只須幾百蚊(美金), 不過唔會真係出, 唔知有冇個 hardware setting, 可以比其他人 DIY 呢.

What’s next?

Wednesday, May 14th, 2008

個 fyp present 經已完左, 下一個想做一個 tag-base 既 photo album.  應該都會搵身邊影開相既人做一 d research.  而 business value 應該係自己 host 返自己 d 相, 唔使用 public album, 第二係想加返 d web2.0 既野入去, 最好就當然搞埋 semantic web.  相片上轉方法應該係用 FTP upload, 之後自己 build index, phase 2 果時加多個類似 rss reader 既野訂閱人地既 photo, 如果加到 georss 既話應該可以 link 埋去 google map 度, 咁到時就真係正啦.

Phase 1 Requirements:

  • tag-base
  • build index from file system
  • album

Phase 2 Requirements:

  • supporting on OpenID
  • GeoRSS implementation
  • meta data implementation

Create Trigger to Run Jar using Shell in Oracle 10g

Friday, March 14th, 2008

First login to sys and grant the permission in sqlplus

EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
EXEC dbms_java.grant_permission('ABC', 'SYS:java.io.FilePermission', '/bin/sh', 'execute');

And then, login to ABC and create java in sqlplus:

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
  public static void executeCommand(String command) {
    try {
      String[] finalCommand;
      if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
        finalCommand = new String[4];
        finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
        finalCommand[1] = "/y";
        finalCommand[2] = "/c";
        finalCommand[3] = command;
      } else {
	// Linux or Unix System
        finalCommand = new String[3];
        finalCommand[0] = "/bin/sh";
        finalCommand[1] = "-c";
        finalCommand[2] = command;
      }

      // Execute the command...
      final Process pr = Runtime.getRuntime().exec(finalCommand);

      // Capture output from STDOUT...
      BufferedReader br_in = null;
      try {
        br_in = new BufferedReader(
            new InputStreamReader(pr.getInputStream()));
        String buff = null;
        while ((buff = br_in.readLine()) != null) {
          System.out.println("stdout: " + buff);
          try {Thread.sleep(100); } catch(Exception e) {}
        }
        br_in.close();
      } catch (IOException ioe) {
        System.out.println("Error printing process output.");
        ioe.printStackTrace();
      } finally {
        try {
          br_in.close();
        } catch (Exception ex) {}
      }

      // Capture output from STDERR...
      BufferedReader br_err = null;
      try {
        br_err = new BufferedReader(
            new InputStreamReader(pr.getErrorStream()));
        String buff = null;
        while ((buff = br_err.readLine()) != null) {
          System.out.println("stderr: " + buff);
          try {Thread.sleep(100); } catch(Exception e) {}
        }
        br_err.close();
      } catch (IOException ioe) {
        System.out.println("Error printing execution errors.");
        ioe.printStackTrace();
      } finally {
        try {
          br_err.close();
        } catch (Exception ex) {}
      }
    }
    catch (Exception ex) {
      System.out.println(ex.getLocalizedMessage());
    }
  }
};

after that, create procedure in sqlplus:

CREATE OR REPLACE PROCEDURE host (p_command IN VARCHAR2)
   AS LANGUAGE JAVA
   NAME 'Host.executeCommand (java.lang.String)';

set the output display if neccessary in sqlplus:

CALL DBMS_JAVA.SET_OUTPUT(1000000);
SET SERVEROUTPUT ON

You can test the procedure using following command:

exec host('/bin/ls');

Create a sh file in linux:

#!/bin/bash
source /home/abc/.bash_profile
cd /home/abc
java -jar /home/abc/abc.jar

Remember to change mode in linux:

chmod a+x /home/abc/run.sh

Finally, create the trigger:

create or replace trigger abc_run
after update on abc.testing
begin host('/home/abc/run.sh');
end;
commit;

Reference: Ref1 Ref2