Monday, December 20, 2004

Install nVidia GForce Driver under Fedora Core 3

Edit /etc/inittab from runlevel5 to runlevel 3: 'id:5:initdefault:' to 'id:3:initdefault:'
sh NVIDIA-Linux-x86-1.0-6629-pkg1.run, ignore the module conflict, recompile the driver.
Change /etc/X11/xorg.conf from Driver 'nv' to 'nvidia'
the following two lines deal with FC3 bug:
cp -a /dev/nvidia* /etc/udev/devices
chown root.root /etc/udev/devices/nvidia*
startx to start X server
Change /etc/inittab back to runlevel 5

Tip: It is not a bad idea to set display resolution to 1024X768 when installing the driver and change back after X server can start up normally.
nvidia-installer --uninstall will uninstall the driver.

Search Engine

A new search engine called Clusty

Friday, December 17, 2004

Change Default Shell to bash under MacOS X

As root, niutil -createprop . /users/zhibin shell /bin/bash

Thursday, December 16, 2004

Experience with JDBC

I got a java.lang.OutOfMemoryError when I used select * this morning, and used Java -Xmx640000000 to realloc heap size to solve it.

When using ResultSet.updateRow() to update records, you must use a statement created this way:
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
and your table must have a primary key.

Monday, December 13, 2004

Call ActiveX from Java

JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java.

Windows Look and Feel in Java

WinLAF Windows Look and Feel Fidelity
winlaf-0.5.jar contains workarounds for Windows Look and Feel issues. Starting with the 0.5 release, WinLAF is a "standard" Java look and feel. To make your application look more like a real Windows app:
  • Put the winlaf-0.5.jar file on the CLASSPATH of your application.
  • In your main() method, set WinLAF as the active look and feel:
    try
    
    {
    UIManager.setLookAndFeel(
    "net.java.plaf.windows.WindowsLookAndFeel"
    );
    }
    catch ( Exception e ) {}

JGoodies: http://www.jgoodies.com/downloads/libraries.html

Friday, December 10, 2004

WebOnSwing

WebOnSwing is a revolutionary multiple environment application framework that allows you to create web applications in the same way you develope a desktop one. You dont need to use JSP files, special tags, XML files, requests, posts, etc. Everything is Java and pure HTML files that comes directly from the graphic designer.

This is a very interesting project which allows you to create web sites via Swing. What you need to do is to add -Xbootclasspath/a:"c:\bin\WebOnSwingBoot.jar" when you start Tomcat. It works fine under Windows system, but there are problems when using under linux and there is no window server. To solve the problem, you need to start Tomcat under a X window system link Gnome.

JavaServer Faces

http://java.sun.com/j2ee/javaserverfaces/index.jsp

A free IDE that is capable to create JSF is Oracle JDeveloper.

Thursday, December 09, 2004

A Place to Learn Java Tech

Wednesday, December 08, 2004

Windows XP Logon Screen Loader

TinySpell

It is a small utility that allows you to easily and quickly check the spelling of words in any Windows application.

Location: http://www.megspace.com/computers/tinyspell/

Connect through a Proxy before Java 1.5

Just realized that it was more complicated to connect through a proxy before java 1.5. Here is the link: http://www.rgagnon.com/javadetails/java-0085.html

Connect through a Proxy
You have to set the following properties :

proxySet, proxyHost and proxyPort.

This can be done when starting the JVM for a JAVA application from the command line:

java -DproxySet=true -DproxyHost=myProxyServer.come -DproxyPort=80 MyJavaApp

Or in your source :

import java.util.Properties;
...

Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","myProxyServer.com") ;
systemSettings.put("http.proxyPort", "80") ;

Tuesday, December 07, 2004

Send Email Under Unix with Perl

open(SENDMAIL, "|/usr/lib/sendmail -oi -t");
print SENDMAIL qq{From:
To:
Subject: New user schedule confirmed
This mail was created by UHN Microarray Centre tutorial Confirmation page.

User $row[0] $row[1] with email: $row[2] has been confirmed to attend the tutorial on $sdate.
};

close(SENDMAIL);

Friday, December 03, 2004

DHTML Tree

From http://www.mattkruse.com/javascript/mktree/

Implementing the DHTML Tree is extremely simple. Follow the steps below to have it up and running in your page in no time!

  • Include mktree.js in your page

    • For example, in the <HEAD> of your page, put the following:
      <SCRIPT SRC="mktree.js" LANGUAGE="JavaScript"></SCRIPT>

  • Include mktree.css in your page

    • For example, in the <HEAD< of your page, put the following:
      <LINK REL="stylesheet" HREF="mktree.css">

  • Set CLASS="mktree" in your <UL<

    • For example, change your root <UL< tag to this:
      <UL CLASS="mktree">

That's it! That's all that is needed to make your unordered list an expandable and collapsable tree.

Controlling The Tree
  • Expanding All

    • To have a link or button which fully expands your tree, do the following:
      1. Setup your tree as above

      2. In addition to a CLASS attribute in your UL tag, also give an ID attribute. For example:
      <UL CLASS="mktree" ID="tree1">
      The ID must be unique on the page, that is, no other tag can share the same ID

      3. Fire a javascript function call (most likely via onClick) like this:
      expandTree('tree1');

  • Collapsing All

    • To have a link or button which fully collapses your tree, do the following:
      1. Setup your tree as above

      2. In addition to a CLASS attribute in your UL tag, also give an ID attribute. For example:
      <UL CLASS="mktree" ID="tree1">
      The ID must be unique on the page, that is, no other tag can share the same ID

      3. Fire a javascript function call (most likely via onClick) like this:
      collapseTree('tree1');

  • Opening to a node

    • To have a link or button which fully collapses your tree, do the following:
      1. Setup your tree as above

      2. In addition to a CLASS attribute in your UL tag, also give an ID attribute. For example:
      <UL CLASS="mktree" ID="tree1">
      The ID must be unique on the page, that is, no other tag can share the same ID

      3. Any node which you will want to expand to needs its own unique ID. For example, somewhere in your tree:
      <LI ID="node234">

      4. Fire a javascript function call (most likely via onClick) like this:
      expandToItem('tree1','node234');
By default, this script uses 5 classes defined in the css file: mktree, liClosed, liOpen, liBullet, and bullet.

Files needed:
http://www.mattkruse.com/javascript/mktree/compact/mktree.js
http://www.mattkruse.com/javascript/mktree/mktree.css
http://www.mattkruse.com/javascript/mktree/plus.gif
http://www.mattkruse.com/javascript/mktree/minus.gif
http://www.mattkruse.com/javascript/mktree/bullet.gif

Thursday, December 02, 2004

Sites for Java Developers

http://www.javaalmanac.com - The online counterpart of the Java Developer's Almanac - highly recommended for quick code snippets, and if you like the site, buy the book.

http://www.onjava.com - O'Reilly's Java website. New articles weekly.

http://java.sun.com - The official Java developer website - new articles posted weekly.

http://www.developer.com/java - Java articles hosted by Gamelan.com

http://www.java.net - The Java community website hosted by Sun Microsystems.

http://www.builder.com - Cnet's Builder.com website - All tech articles, some Java-centric.

http://www.ibm.com/developerworks/java - IBM's Developerworks; the Java section.

http://www.javaworld.com - One of the originals. Weekly updates of Java articles.

http://www.devx.com/java - Java articles hosted at DevX.

http://www.fawcette.com/javapro - The JavaPro online magazine website.

http://www.sys-con.com/java - The Java Developers Journal online magazine website.

http://www.javadesktop.org - The desktop Java community hosted at Java.net.

http://www.theserverside.com - Often considered the resource for all discussion server-side Java specific.

http://www.jars.com - The Java review service. Covers frameworks and applications.

http://www.jguru.com - A great source for Q&A style interaction in the community.

http://www.javaranch.com

http://www.ibiblio.org/javafaq/javafaq.html - The comp.lang.java FAQ - questions asked, answered, and categorized from the comp.lang.java newsgroup.

http://java.sun.com/docs/books/tutorial/ - The Official Java tutorial from Sun - very useful for almost any feature set.

http://www.javablogs.com - Blog aggregator for the most active Java-based blogs throughout the internet.

http://java.about.com/ - Java news and articles from About.com.

http://www.esus.com/ Java Tips and Tricks

http://www.javaskyline.com/ Dedicated to Java.


Word Distance

Copied from Javalobby

Here's a small implementation of the Levenshtein Word Distance algorythm written in Java.

The algorythm is good for measuring edit distance between two words and is normally used for spell checking and similarity sorting.


    public static int LD( String s, String t) {

int n = s.length();
int m = t.length();

if (n == 0) return m;
if (m == 0) return n;

int[][] d = new int[n + 1][m + 1];

for ( int i = 0; i <= n; d[i][0] = i++ );
for ( int j = 1; j <= m; d[0][j] = j++ );

for ( int i = 1; i <= n; i++ ) {
char sc = s.charAt( i-1 );
for (int j = 1; j <= m;j++) {
int v = d[i-1][j-1];
if ( t.charAt( j-1 ) != sc ) v++;
d[i][j] = Math.min( Math.min( d[i-1][ j] + 1, d[i][j-1] + 1 ), v );
}
}
return d[n][m];
}


Someone said the N-gram could also give very good results.

Wednesday, December 01, 2004

Post Form Data to CGI (Java 1.5)


//This one uses java 1.5, the new Generics method.
package uhn;

import java.util.Stack;
import java.net.*;
import java.io.*;

/**
* Title: FormPost
* Description: Post form to CGI server on the net
* Copyright: Copyright (c) 2003
* Company: UHN
* @author Zhibin Lu
* @version 1.0
*/

public class FormPost {
private URLConnection urlConn;
private OutputStreamWriter printout;
private BufferedReader input;
private Stack para;

/** Constructor of the class
* @param url URL address to post form (action)
* @param parameters parameters to pass to the server
*/
public FormPost(String url, Stack parameters) {
para = parameters;
try {
urlConn = (new URL(url)).openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.uhnres.utoronto.ca", 3128)));
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0)");
urlConn.setRequestProperty("accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
}
catch (Exception e){
System.err.println("Constructor of FormPost: " + e);
urlConn = null;
}
}

/** Connect to the web CGI server
* @return BufferedReader to read the result from CGI server
*/
public BufferedReader connect() {
try {
printout = new OutputStreamWriter(urlConn.getOutputStream (), "ISO-8859-1");
if (!para.empty()) {
printout.write((String) para.pop());
}
while (!para.empty()) {
printout.write("&" + para.pop());
}
printout.flush ();
printout.close ();

input = new BufferedReader(new InputStreamReader(urlConn.getInputStream ()));
}
catch (IOException e) {
System.err.println("FormPost connect: " + e);
input = null;
}
finally {
return input;
}
}

/** Close the connect to the CGI server */
public void close() {
try {
input.close();
}
catch (IOException e) {
System.err.println("FormPost close: " + e);
}
}
public static void main(String[] args) throws IOException {
FormPost form;
Stack parameters = new Stack();
String line;

parameters.push("FORM=MSNH");
parameters.push("q=test");

form = new FormPost("http://search.msn.com/results.aspx", parameters);
BufferedReader in = form.connect();
while ((line=in.readLine()) != null) {
System.out.println(line);
}
in.close(); form.close();
}

}///:~