February 23, 2004

Social networking diagram

February 23, 2004 - Categories: -Uncategorized, connecting

Should be fun to run this on a mailing list, using the References: tag…

- http://www.jibble.org/piespy
http://www.daimi.au.dk/~terryp/pics/emacs-current.png

planner.el broken up into lots of little files

February 23, 2004 - Categories: emacs

It should compile cleanly under Emacs 21.3 (CVS). I’m still trying to
figure out how to install the fsf-compat package under XEmacs so that
I can get it to compile cleanly there.

WARNING! Many user-visible changes. In particular, you will now need
to require a bunch of other things in order to get the old behavior. I
should figure out how to set up the appropriate autoloads. In the
meantime, add some variant of the following to your .emacs:

(require 'remember)
(require 'planner)
(require 'remember-planner)
(require 'planner-experimental)
(require 'planner-bbdb)
;; (require 'planner-diary)
(require 'planner-gnus)
(require 'planner-id)
;; (require 'planner-notes)
(require 'planner-rss)
;; (require 'planner-schedule)
;; (require 'planner-timeclock)
(require 'planner-w3m)

This will no doubt break a number of things. Please complain loudly.
If you want the old version, you can get a tar.gz from
http://sacha.free.net.ph/notebook/emacs/planner/planner-current.tar.gz
.

Nvu, a WYSIWYG HTML editor for Linux

February 23, 2004 - Categories: -Uncategorized

http://www.nvu.com/index.html

Sample ArrayList code

February 23, 2004 - Categories: -Uncategorized

Here’s sample code for ArrayLists, which is a Java class that can
store any kind of object in an array that automatically grows.

Note: ArrayLists store objects. Generic objects. You’ll probably
need to convert (“cast”) them to another type before you can use them.
See example below.

Note: Only objects. You can’t store doubles, ints or booleans unless
they’re wrapped in another object. You can’t say list.add(5), but you
can wrap it in an Integer object and say list.add(new Integer(5));.
Then you can say Integer x = (Integer) list.get(0);
System.out.println(x.intValue());

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
// NEW: You need this for ArrayList
import java.util.*;

public class OrderApplet extends Applet implements ActionListener
{
    private TextField nameField;
    private TextField orderField;
    private TextField valueField;
    private TextField indexField;
    private TextField nameFilterField;
    private Button addButton;
    private Button removeButton;
    private Button showAllButton;
    private Button showOnlyButton;
    private TextArea outputArea;

    // NEW: Declare the array list
    private ArrayList orderList;

    public void init()
    {
        // NEW: Create the array list
        orderList = new ArrayList();

        Label nameLabel = new Label("Name: ");
        add(nameLabel);
        nameField = new TextField(10);
        add(nameField);

        Label orderLabel = new Label("Order: ");
        add(orderLabel);
        orderField = new TextField(10);
        add(orderField);

        Label valueLabel = new Label("Value:");
        add(valueLabel);
        valueField = new TextField(5);
        add(valueField);

        addButton = new Button("Add order");
        addButton.addActionListener(this);
        add(addButton);

        Label indexLabel = new Label("Index:");
        add(indexLabel);
        indexField = new TextField(5);
        add(indexField);
        removeButton = new Button("Remove order at index");
        removeButton.addActionListener(this);
        add(removeButton);

        showAllButton = new Button("Show all orders");
        showAllButton.addActionListener(this);
        add(showAllButton);

        nameFilterField = new TextField(10);
        add(nameFilterField);
        showOnlyButton = new Button("Show selected orders");
        showOnlyButton.addActionListener(this);
        add(showOnlyButton);

        outputArea = new TextArea(20, 50);
        add(outputArea);

    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == addButton)
        {
            // Get the values from the text fields
            String name = nameField.getText();
            String order = orderField.getText();
            double value = Double.parseDouble(valueField.getText());
            // Create an Order object for these three items
            Order o = new Order(name, order, value);
            // Add the value to the list of orders
            // NEW: Add o to the list.
            orderList.add(o);
            showAllOrders();
        }
        else if (e.getSource() == removeButton)
        {
            int index = Integer.parseInt(indexField.getText());
            // NEW: Remove the object at the specified position.
            orderList.remove(index);
            showAllOrders();
        }
        else if (e.getSource() == showAllButton)
        {
            showAllOrders();
        }
        else if (e.getSource() == showOnlyButton)
        {
            showOrders(nameFilterField.getText());
        }
    }

    // TODO: Add a total
    public void showAllOrders()
    {
        // FIXME: Declare a temporary sum variable and set it to 0.0.

        // Update the order display no matter what button is clicked.
        outputArea.setText("");
        // NEW: Getting the size with the size() method.
        for (int i = 0; i < orderList.size(); i++)
        {
            // An ArrayList stores generic Objects.
            // All objects in Java are of the Object class.
            // If we want to use special methods of the Order
            // class, we have to tell Java it's an Order object.
            // (Order) before orderList.get(i) converts the
            // result into an Order object.

            // NEW: Casting (converting one object to another), .get(index)
            Order order = (Order) orderList.get(i);
            // What happens if you remove (Order) from the line above?

            outputArea.append("[" + i + "]: "  // index
                              + order.getName() + ": "
                              + order.getOrder() + ": "
                              + order.getValue() + "\n");
            // FIXME: Add the order value to the sum
        }
        // FIXME: Display the sum
    }

    // TODO: Add a total
    public void showOrders(String name)
    {
        // FIXME: Declare a temporary sum variable and set it to 0.0.

        // Show only the orders by a certain person
        outputArea.setText("");
        for (int i = 0; i < orderList.size(); i++)
        {
            Order order = (Order) orderList.get(i);
            // What happens if you remove (Order) from the line above?
            if (order.getName().equals(name))
            {
                outputArea.append("[" + i + "]: "  // index
                                  + order.getName() + ": "
                                  + order.getOrder() + ": "
                                  + order.getValue() + "\n");
                // FIXME: Add the order value to the sum
            }
        }
        // FIXME: Display the sum
    }
}

class Order
{
    private String name;
    private String order;
    private double value;

    public Order(String name,
                 String order,
                 double value)
    {
        // "this.name" refers to the name attribute,
        // but "name" by itself refers to the parameter.
        this.name = name;
        this.order = order;
        this.value = value;
    }

    public String getName()
    {
        // The "this." in this.name here is optional, but
        // we use it anyway: it's good practice
        return this.name;
    }

    public String getOrder()
    {
        return this.order;
    }

    public double getValue()
    {
        return this.value;
    }

}

../../notebook/school/current/cs21a/OrderApplet.java

Sample ArrayList code

February 23, 2004 - Categories: -Uncategorized

Here’s sample code for ArrayLists, which is a Java class that can
store any kind of object in an array that automatically grows.

Note: ArrayLists store objects. Generic objects. You’ll probably
need to convert (“cast”) them to another type before you can use them.
See example below.

Note: Only objects. You can’t store doubles, ints or booleans unless
they’re wrapped in another object. You can’t say list.add(5), but you
can wrap it in an Integer object and say list.add(new Integer(5));.
Then you can say Integer x = (Integer) list.get(0);
System.out.println(x.intValue());

Also at http://sacha.free.net.ph/notebook/cs21a/OrderApplet.java and
http://sacha.free.net.ph/notebook/cs21a/order.html

ASSIGNMENT: We don’t have classes on Wednesday. Add totals to this
code (should display total for all orders shown). Also, practice
layouts by making this neater.

Once you get the idea behind this applet, redo it until you can write
it from scratch without referring to your notes. Feel free to make
similar programs. This will take a few hours, but will be well worth
it!

Send me your OrderApplet.java with totals and whatever other
files you’d like me to look at by 11:59:59pm on Thursday.

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
// NEW: You need this for ArrayList
import java.util.*;

public class OrderApplet extends Applet implements ActionListener
{
    private TextField nameField;
    private TextField orderField;
    private TextField valueField;
    private TextField indexField;
    private TextField nameFilterField;
    private Button addButton;
    private Button removeButton;
    private Button showAllButton;
    private Button showOnlyButton;
    private TextArea outputArea;

    // NEW: Declare the array list
    private ArrayList orderList;

    public void init()
    {
        // NEW: Create the array list
        orderList = new ArrayList();

        Label nameLabel = new Label("Name: ");
        add(nameLabel);
        nameField = new TextField(10);
        add(nameField);

        Label orderLabel = new Label("Order: ");
        add(orderLabel);
        orderField = new TextField(10);
        add(orderField);

        Label valueLabel = new Label("Value:");
        add(valueLabel);
        valueField = new TextField(5);
        add(valueField);

        addButton = new Button("Add order");
        addButton.addActionListener(this);
        add(addButton);

        Label indexLabel = new Label("Index:");
        add(indexLabel);
        indexField = new TextField(5);
        add(indexField);
        removeButton = new Button("Remove order at index");
        removeButton.addActionListener(this);
        add(removeButton);

        showAllButton = new Button("Show all orders");
        showAllButton.addActionListener(this);
        add(showAllButton);

        nameFilterField = new TextField(10);
        add(nameFilterField);
        showOnlyButton = new Button("Show selected orders");
        showOnlyButton.addActionListener(this);
        add(showOnlyButton);

        outputArea = new TextArea(20, 50);
        add(outputArea);

    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == addButton)
        {
            // Get the values from the text fields
            String name = nameField.getText();
            String order = orderField.getText();
            double value = Double.parseDouble(valueField.getText());
            // Create an Order object for these three items
            Order o = new Order(name, order, value);
            // Add the value to the list of orders
            // NEW: Add o to the list.
            orderList.add(o);
            showAllOrders();
        }
        else if (e.getSource() == removeButton)
        {
            int index = Integer.parseInt(indexField.getText());
            // NEW: Remove the object at the specified position.
            orderList.remove(index);
            showAllOrders();
        }
        else if (e.getSource() == showAllButton)
        {
            showAllOrders();
        }
        else if (e.getSource() == showOnlyButton)
        {
            showOrders(nameFilterField.getText());
        }
    }

    // TODO: Add a total
    public void showAllOrders()
    {
        // FIXME: Declare a temporary sum variable and set it to 0.0.

        // Update the order display no matter what button is clicked.
        outputArea.setText("");
        // NEW: Getting the size with the size() method.
        for (int i = 0; i < orderList.size(); i++)
        {
            // An ArrayList stores generic Objects.
            // All objects in Java are of the Object class.
            // If we want to use special methods of the Order
            // class, we have to tell Java it's an Order object.
            // (Order) before orderList.get(i) converts the
            // result into an Order object.

            // NEW: Casting (converting one object to another), .get(index)
            Order order = (Order) orderList.get(i);
            // What happens if you remove (Order) from the line above?

            outputArea.append("[" + i + "]: "  // index
                              + order.getName() + ": "
                              + order.getOrder() + ": "
                              + order.getValue() + "\n");
            // FIXME: Add the order value to the sum
        }
        // FIXME: Display the sum
    }

    // TODO: Add a total
    public void showOrders(String name)
    {
        // FIXME: Declare a temporary sum variable and set it to 0.0.

        // Show only the orders by a certain person
        outputArea.setText("");
        for (int i = 0; i < orderList.size(); i++)
        {
            Order order = (Order) orderList.get(i);
            // What happens if you remove (Order) from the line above?
            if (order.getName().equals(name))
            {
                outputArea.append("[" + i + "]: "  // index
                                  + order.getName() + ": "
                                  + order.getOrder() + ": "
                                  + order.getValue() + "\n");
                // FIXME: Add the order value to the sum
            }
        }
        // FIXME: Display the sum
    }
}

class Order
{
    private String name;
    private String order;
    private double value;

    public Order(String name,
                 String order,
                 double value)
    {
        // "this.name" refers to the name attribute,
        // but "name" by itself refers to the parameter.
        this.name = name;
        this.order = order;
        this.value = value;
    }

    public String getName()
    {
        // The "this." in this.name here is optional, but
        // we use it anyway: it's good practice
        return this.name;
    }

    public String getOrder()
    {
        return this.order;
    }

    public double getValue()
    {
        return this.value;
    }

}

Common networking errors

February 23, 2004 - Categories: teaching

Due 2004.02.23 11:59:59 PM: Source code and detailed notes on

– changes made
– problems encountered
– solutions tried/found
– outstanding problems
– plans for next step

I don’t expect everyone to have a fully-working game by tomorrow, so
most of your partial points will come from the notes. “It doesn’t
work.” isn’t enough; I need to know why it doesn’t work, if it used to
work before, what you’ve tried doing to get it to work, why you think
it doesn’t work, etc.

Along the way to your first milestone, you may have encountered the
following problems:

ObjectInputStream seems to hang when you create it.

That happens when both sides of the connection try to create object
input streams at the same time, but the other side hasn’t opened an
object output stream yet. Fix: create the object output stream first
before you create the input stream.

ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());

Your program lags terribly.

How are you doing your networking and repainting code? If you’re doing
animation, repaint() should be in one thread and your networking code
should be in another. You shouldn’t do them in the same thread because
then repaint() will only happen whenever something is received from
the socket connection. Also, make sure you have delays somewhere!
while (true) { repaint(); } means your CPU will spend
most of its time repainting. Add a Thread.sleep in that loop so that
your computer has time to do other things.

You can’t write certain objects over the stream.

Make sure the object is serializable and all of its attributes are
either transient or serializable as well. You really shouldn’t be
sending your entire application over the network – what is the other
side going to do with all those textfields? Mark many of your
attributes transient or create a small, simple object that
encapsulates the data you need to send.

You’ve sent an object over the network connection and you’re calling methods on it on the other side, but the one on the first computer isn’t changing!

That’s the way it works. If you send an object from computer A to
computer B, computer B isn’t working on the original object but on a
copy of it. Any changes on A won’t be automatically sent to B and vice
versa. The correct thing to do is examine the object and perform
different actions locally.

If you really need to get something like this working and you have
plenty of spare time, read up on RMI (Remote Method Invocation). It’s
out of the scope of CS21B, though.

For tonight, I want lots and lots of notes.

TOMORROW: Data structures (stacks, queues and linked lists).

Social network analysis

February 23, 2004 - Categories: -Uncategorized

http://www.jibble.org/piespy/

I want to run something like this on the PLUG mailing lists. I can
reuse their spring model and then build the network based on the
References: header.

SocialNetworkBot

February 23, 2004 - Categories: -Uncategorized

This is where all the magic happens. Starting up the app for every
arriving message is probably a bad idea. Better – Java server, then
pass it the message.

channel – mailing list

Mailing lists are simpler to track than chat channels. I can work on
the References header (and the attribution if necessary).

onMessage: Extract the References header. Find the latest one and root
the thread there.

I need a registry of message IDs and authors, then.

Question:

- What about digest users? Should infer based on attribution as well.

../../tmp/piespy/org/jibble/socnet/SocialNetworkBot.java

SocialNetworkBot

February 23, 2004 - Categories: -Uncategorized

This is where all the magic happens. Starting up the app for every
arriving message is probably a bad idea. Better – Java server, then
pass it the message.

channel – mailing list

Mailing lists are simpler to track than chat channels. I can work on
the References header (and the attribution if necessary).

onMessage: Extract the References header. Find the latest one and root
the thread there.

I need a registry of message IDs and authors, then.

Question:

- What about digest users? Should infer based on attribution as well?

../../tmp/piespy/org/jibble/socnet/SocialNetworkBot.java

Apache James

February 23, 2004 - Categories: -Uncategorized

JM Ibanez suggested looking at Apache James and writing a mailet.
Nifty idea, if I can get my mind around it!

(I just need something simple. If I get desperate, I’ll tokenize the
darn thing myself.)