Linux user commands

Every user who has access to a Linux system needs a login and a password. Each user must belong to a primary group and for security or access purposes can belong to several secondary groups. In order to create new logins, modify or delete users, you must already be logged in as root.  The root […]

install Groovy in RedHat as4

官方网是这样写的:1,first, Download a binary distribution of Groovy and unpack it into some file on your local file system 2,set your GROOVY_HOME environment variable to the directory you unpacked the distribution 3,add GROOVY_HOME/bin to your PATH environment variable 4,set your JAVA_HOME environment variable to point to your JDK. On OS X this is /Library/Java/Home, on other […]

Your First Groovy

Your First Groovy //hello.groovy println “hello, world” for (arg in this.args ) { println “Argument:” + arg; } // this is a comment /* a block comment, commenting out an alternative to above: this.args.each{ arg -> println “hello, ${arg}”} */ To run it from command line groovy hello.groovy MyName yourName HisName Overview Groovy classes compile […]

J2ME Datagram Receiver

import java.io.IOException;import javax.microedition.io.Connector;import javax.microedition.io.Datagram;import javax.microedition.io.DatagramConnection;public class DatagramReceiver {    public static void main(String[] args) {        if (args.length != 1) {            System.out.println(“Usage: DatagramReceiver port”);            System.exit(1);        }                try {            DatagramConnection receiver =                     (DatagramConnection)Connector.open(“datagram://:” + args[0]);            byte[] buffer = new byte[256];            Datagram dgram = receiver.newDatagram(buffer, buffer.length);            for ($$) {                dgram.setLength(buffer.length);                receiver.receive(dgram);                int length = dgram.getLength();                System.out.println(“Datagram received. Length is ” + length);                // Show the content of the datagram.                for (int i = 0; i < length; i++) {                    System.out.print(buffer[i] + ” “);                }                System.out.println();                                // Send it back…                receiver.send(dgram);            }        } catch (IOException ex) {            System.out.println(“IOException: ” + ex);        }    }}

Timer Server

import java.io.InterruptedIOException;import javax.microedition.io.Connector;import javax.microedition.io.Datagram;import javax.microedition.io.DatagramConnection;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.StringItem;import javax.microedition.lcdui.TextField;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;public class TimeMIDlet extends MIDlet                    implements CommandListener, Runnable {    private Display display;    private Form addressForm;    private Form connectForm;    private Form displayForm;    private Command backCommand;    private Command exitCommand;    private Command okCommand;    private StringItem messageLabel;    private TextField serverName;    protected void startApp() throws MIDletStateChangeException {        if (display == null) {            initialize();            display.setCurrent(addressForm);        }    }    protected void pauseApp() {    }    protected void destroyApp(boolean unconditional)                        throws MIDletStateChangeException {    }    public void commandAction(Command cmd, Displayable d) {        if (cmd == okCommand) {            Thread t = new Thread(this);            t.start();        } else if (cmd == backCommand) {            display.setCurrent(addressForm);        } else if (cmd == exitCommand) {            try {                destroyApp(true);            } catch (MIDletStateChangeException ex) {            }            notifyDestroyed();        }    }    public void run() {        DatagramConnection conn = null;        display.setCurrent(connectForm);        try {            // Build the name string for the Connector open method            String server = serverName.getString();            String name = “datagram://” + server + “:” + 13;            conn = (DatagramConnection)Connector.open(name,                                    Connector.READ_WRITE, false);            // Build and send an empty datagram            Datagram dg = conn.newDatagram(10);            dg.setData(“Hello”.getBytes(), 0, 5);            conn.send(dg);            // Receive the reply            Datagram rdg = conn.newDatagram(512);            conn.receive(rdg);            messageLabel.setText(new String(rdg.getData(), 0, rdg.getLength()));            display.setCurrent(displayForm);        } catch (InterruptedIOException iex) {            display.callSerially(new Runnable() {                public void run() {                    Alert alert = new Alert(“No Reply”,                        “No reply was received.\n” +                        “Please check the server address and try again.”, null,                        AlertType.ERROR);                    alert.setTimeout(Alert.FOREVER);                    display.setCurrent(alert, addressForm);                }            });            return;        } catch (Exception ex) {            display.callSerially(new Runnable() {                public void run() {                    Alert alert = new Alert(“Invalid Address”,                        “The supplied address is invalid\n” +                        “Please correct it and try again.”, null,                        AlertType.ERROR);                    alert.setTimeout(Alert.FOREVER);                    display.setCurrent(alert, addressForm);                }            });            return;        } catch (Error err) {            System.out.println(err);            err.printStackTrace();        }    }    private void initialize() {        display = Display.getDisplay(this);        // Commands        exitCommand = new Command(“Exit”, Command.EXIT, 0);        okCommand = new Command(“OK”, Command.OK, 0);        backCommand = new Command(“Back”, Command.BACK, 0);        // The address form        addressForm = new Form(“Network Time”);        serverName = new TextField(“Time Server name:”, “tock.usno.navy.mil”,                                            256, TextField.ANY);        addressForm.append(serverName);        addressForm.addCommand(okCommand);        addressForm.addCommand(exitCommand);        addressForm.setCommandListener(this);        // The connect form        connectForm = new Form(“Sending”);        messageLabel = new StringItem(null,                    “Sending the datagram…\nPlease wait.”);        connectForm.append(messageLabel);        connectForm.addCommand(backCommand);        connectForm.setCommandListener(this);        // The display form        displayForm = new Form(“Server Reply”);        messageLabel = new StringItem(null, null);        displayForm.append(messageLabel);        displayForm.addCommand(backCommand);        displayForm.setCommandListener(this);    }}

Developing Applications with the Java APIs for Bluetooth (JSR-82)

Developing Applications with the Java APIs for Bluetooth (JSR-82) This paper covers the Java API for Bluetooth (JSR-82) with respect to Sony Ericsson devices. It starts by introducing the Bluetooth technology, followed by the Java APIs for Bluetooth, and how to use them. Currently, these APIs are currently available in the Sony Ericsson P900/P908 handsets. […]

How to write a shell script

How to write a shell scriptIntroductionA shell is a command line interpretor. It takes commands and executes them. As such, it implements a programming language. The Bourne shell is used to create shell scripts — ie. programs that are interpreted/executed by the shell. You can write shell scripts with the C-shell; however, this is not […]

Open Webmail 安裝流程

Open Webmail 官方網站:http://openwebmail.org/注意:要架設 Open Webmail 前,請務必先將 sendmail、dovecot 架設好 安裝 cdyum -y install perl-suidperl perl-Compress-Zlib perl-Text-Iconv wget http://openwebmail.org/openwebmail/download/redhat/rpm/release/openwebmail-2.52-1.i386.rpmrpm -ivh openwebmail-2.52-1.i386.rpmrm -rf openwebmail-2.52-1.i386.rpm修改 openwebmail.conf cp /var/www/cgi-bin/openwebmail/etc/openwebmail.conf /var/www/cgi-bin/openwebmail/etc/openwebmail.conf.bakvi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf55行 enable_pop3 yes 修改成–> enable_pop3 no62行 default_language en 修改成–> default_language zh_TW.Big585行 default_iconset Cool3D.English 修改成–> default_iconset Cool3D.Chinese.Traditional   76行 <default_signature>77行 —78行 Open WebMail Project (http://openwebmail.org)79行 </default_signature> #此此四行是使用者寄信的預設簽名檔,請自行修改紅字部分   202行 webdisk_rootpath /webdisk […]