Some of My Code from the Late 1990s

created Jul 4, 2019

In the late 1990s, I posted some of my code and demos to my website that was hosted for free at hypermart.net

From the Wayback Machine.

https://web.archive.org/web/20020126090916/http://jsawvel.hypermart.net/

https://web.archive.org/web/20010418170958/http://jsawvel.hypermart.net/



!/usr/bin/perl

#  this program can be used and abused however you like. no license crapola. 
#
#
#  program: impint.pl
#  by: jrsawvel with help from C&B; Technologies (comet and beanie my two cats) 
#  email abuse to: jrkermit@primenet.com
#  date: 8-16-98
#  weather: partly cloudy at 3pm with temps in low 80's at most. darn nice out.
#           was at the 577 Foundation in P-burg this afternoon. neat place.
#  
#  description: program is "impression interval". a banner gif is diplayed at
#     regular intervals as specified in one of the args to the cgi program.
#     at little file on the web server hard drive contains the hit count and 
#     when the count divides evenly by the interval count then the gif
#     file is read and displayed to the user.
#
#  things to do:
#      1. add support to display an alternate gif file when not the interval
#          person to the page.
#
#      2. add support for keeping track of the total number of impressions or
#          hit count. this would be a number kept in a file like the total
#          count file. this would be for stat purposes to see how many times
#          the banner gif for the interval count was displayed.
#
#
#
#  usage in the html page:
#
#
#
#        cgi name=value pairs accepted
#
#    name1=   first part of counter file name 
#    name2=   second part of counter file name 
# interval=   number will mean every nth person
#      gif=   gif file to display for the nth person
# dotcolor=   if not a hit display 1 pixel with this color. don't use pound sign
#   altgif=   gif to display if NOT the nth person (not yet in place)
#

#
# build an associative array from the values contained in the url's query
# string
@cgiQueryPairs = split( "&", $ENV{ 'QUERY_STRING' } );
foreach $p ( @cgiQueryPairs ) {
    ( $var, $val ) = split( "=", $p );
    $val =~ s/\+/ /g;      # translate '+' to space
    $val =~ s/%(..)/pack("c",hex($1))/ge;    # undo '%HH' url encoding
    $cgiValues{ "$var" } = "$val";
}

$dot_array_elms=35;
$mod_op=5;
$prog_name="impint";
$dotcolor_len=6;

$home_dir="/data1/hypermart.net/jsawvel/ii";
$default_gif="survey.gif";

# default dotcolor is white */
# colors controlled by elements 13-15. first element starts with number 0
@blank=(0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x1, 0x0, 0x1, 0x0, 0x80, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x2C, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x2, 0x2, 0x44, 0x1, 0x0, 0x3B);

    $i=0;
    $hitcount=0;
    $inthit=0;
    $wait_count = 0; 
    $interval_value = $mod_op; 
    $tmpnum = 0;
    $num=0;
    $MultiNumber = 0;
    $x=0;
    $len=0;
    $displaying_alt_gif_file=0;
    $bginc=0;

$td="[".localtime(time)."]";

print("Content-type: image/gif\n\n");

# pull out required form variables
$name1= $cgiValues{"name1"};
if ( $name1 eq "" ) 
{
    print STDERR "$td $prog_name: fatal - no name1 given as an arg!\n";
    exit(1);   
}

$name2= $cgiValues{"name2"};
if ( $name2 eq "" ) 
{
    print STDERR "$td $prog_name: fatal - no name2 given as an arg!\n";
    exit(1);   
}

$interval = $cgiValues{"interval"};
if ( $interval eq "" ) 
{
    print STDERR "$td $prog_name: fatal - no interval given as an arg!\n";
    exit(1);   
}

if ( $interval > 0 )
{
    $interval_value = $interval;
}

$giffile = $cgiValues{"gif"};
if ( $giffile eq "" ) 
{
    $gif_file_to_use = $default_gif;
}
else
{
    $gif_file_to_use = $giffile;
}

# if no dotcolor then will use white by default as above
$dotcolor = $cgiValues{"dotcolor"};
if ( $dotcolor ne "" ) 
{
    # check the strlen of dotcolor and if != dotcolor_len then use white

    $hex1 = substr($dotcolor, 0, 2);
    $hex2 = substr($dotcolor, 2, 2);
    $hex3 = substr($dotcolor, 4, 2);

    $blank[13] = hex("0x".$hex1);
    $blank[14] = hex("0x".$hex2);
    $blank[15] = hex("0x".$hex3);
}

$count_file = $home_dir . "/" . $name1 . "-" . name2 . ".cnt";
$hit_file   = $home_dir . "/" . $name1 . "-" . name2 . ".hit";
$gif_file   = $home_dir . "/" . $gif_file_to_use;

# open and read total count file. of course file locking should be used since
# unpredictable behavior could result when two users try to access the file
# at the same time. 

if ( ! -r $count_file )
{
    print STDERR "$td $prog_name: warning - missing count file for $name1 $name2! will create one.\n";

    $hitcount = 0;
}
else
{
    open(FPCNT, $count_file) || die "$td $prog_name: fatal - cannot read count file for $name1 $name2: $!";

    $hitcount = ;
    close(FPCNT);
}

open(FPCNT, ">$count_file") || die "$td $prog_name: fatal - cannot open count file for write for $name1 $name2: $!";

$hitcount++;
print FPCNT "$hitcount\n";
close(FPCNT);

# add the code to keep track of the number of impressions here...

# end impression count tracking code ...

# if a hit then display gif otherwise display single pixel

if ( ($hitcount % $interval_value) == 0 )
{
    open (GIFFILE, $gif_file) || die "can't open gif file for read: $!";
    while ( defined  ($record = ) )
    {
        print "$record";
    }
    close (GIFFILE) || die   "couldn't close gif file: $!";
}
else
{
    $i=0;
    foreach (@blank)
    {
        printf("%c", $blank[$i]);
        $i+=1;
    }
    print "\n";
}



// program: jrprotek.java
// by: c&b; tech with a little help from O'Reilly's Java in a Nushell book.
// date: 10-3-98
// desc: proteck images - instead of img src html tags use this applet
//

import java.applet.*;
import java.awt.*;
import java.net.*;
import java.util.*;
import java.io.*;
import java.lang.*;

public class jrprotek extends Applet {
    protected Image image;      // image to display.
    protected Vector rects;     // list of rectangles in it.

    public void init() {
        // load the image to be displayed.
        image = this.getImage(this.getDocumentBase(), 
                      this.getParameter("image"));

    }

    // Called when the applet is being unloaded from the system.
    // We use it here to "flush" the image. This may result in memory 
    // and other resources being freed quicker than they otherwise would.
    public void destroy() { image.flush(); }

    // Display the image.
    public void paint(Graphics g) {
        g.drawImage(image, 0, 0, this);
    }

    // We override this method so that it doesn't clear the background
    // before calling paint().  Makes for less flickering in some situations.
    public void update(Graphics g) { paint(g); }

    private nthJavaDialog nthDialog;

    public boolean mouseDown(Event e, int x, int y)
    {
        this.showStatus("bastard trying to click on image!!!");
        Frame f = new Frame("DEBRIS");
        nthDialog = new nthJavaDialog(f, "jrprotek", "BITE ME PAL! you ain't getting the image!");
        nthDialog.show();
        return true;
    }

}

class nthJavaDialog extends Dialog
{
    Button NoThanksButton;

    public nthJavaDialog(Frame parent, String title, String message)
    {
        super(parent, title, true);

        Panel p1 = new Panel();
        p1.setLayout(new FlowLayout(FlowLayout.CENTER, 35, 35));
        Label label = new Label(message);
        p1.add(label);
        add("Center", p1);

        Panel p = new Panel();
        p.setLayout(new FlowLayout(FlowLayout.CENTER, 35, 35));
        NoThanksButton = new Button("Close");
        p.add(NoThanksButton);

        this.add("South", p);

        this.pack();
    }

    public boolean action(Event evt, Object arg)
    {
        if ( evt.target == NoThanksButton )
        {
            this.hide();
            return true;
        }

        return false;
    }

}


// program: cbslideshow.java
// guy    : c&b; tech
// date   : Oct 29, 1998
// purpose: to display a pop-up window that contains a picture of a concept
//          using an applet prevents someone from saving the gif or jpeg to
//          their hard disk and prevents them printing the picture
//          code for ProtekConcept.java adapted from nthJava.java and
//          and a java in a nutshell book example

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.util.*;
import java.io.*;
import java.lang.*;

public class cbslideshow extends Applet 
{
    Button prev;
    Button next;                                               
    private Frame conceptFrame;

    public void init()
    {
        Image image=null;      // image to display.
        Vector theImages = new Vector();
        Vector theMessages = new Vector();
        String valuestr=null;
        String msgstr=null;
        int  i=0;
        boolean showmsgarea=false;
        boolean showbuttons=false;
        TextArea textarea=null;

        String msgarea = getParameter("MsgArea");
        if ( msgarea != null && msgarea.equals("Yes") )
            showmsgarea = true;

        String buttonstr = getParameter("Buttons");
        if ( buttonstr != null && buttonstr.equals("Yes") )
            showbuttons = true;

        while ( (valuestr = getParameter("image" + i)) != null ) 
        {
            // load the image to be displayed.
            image = this.getImage(this.getDocumentBase(), valuestr);
            theImages.addElement(image);
            if ( showmsgarea )
            {
                msgstr = getParameter("msg" + i);
                if ( msgstr != null )
                {
                    msgstr = msgstr.replace('|', '\n');
                    theMessages.addElement(msgstr);
                }
                else
                    theMessages.addElement("this\n is\n a\n test\n ");
            }

            i++;
            image=null;
        }

        String widthstr = getParameter("WindowWidth");
        String heightstr = getParameter("WindowHeight");

        setLayout(new BorderLayout());
        Panel topP = new Panel();
        topP.setLayout(new FlowLayout(FlowLayout.CENTER));
        if ( showbuttons )
        {
            prev = new Button(" <-- Previous ");
            next = new Button("   Next -->   ");
            topP.add(prev);
            topP.add(next);
        }

        if ( showmsgarea )
        {
            textarea = new TextArea(4, 40);
            textarea.setEditable(false);
            topP.add(textarea);
            textarea.setText((String)theMessages.elementAt(0));
        }

        conceptFrame = new ConceptFrame(this, theImages, widthstr, heightstr, next, prev, showmsgarea, textarea, theMessages, showbuttons);
        conceptFrame.setBackground(Color.white);

        conceptFrame.add("North", topP);

        // display pop-up window
        conceptFrame.show();

    }

    public boolean action(Event event, Object arg)
    {
        return super.handleEvent(event);
    }

}

/********************************************************************/

class ConceptFrame extends Frame
{
    Vector Imgs;
    Vector Msgs;
    int wd, ht;
    cbslideshow parent;
    int count=0;
    Button nextbutton;
    Button prevbutton;
    TextArea ta;
    boolean showmsg=false;
    boolean buttons=false;
    int xxx,yyy;

    public ConceptFrame(Applet aw, Vector theImages, String w, String h, Button next, Button prev, boolean showmsgarea, TextArea textarea, Vector theMessages, boolean showbuttons) 
    {
        super();
        parent = (cbslideshow)aw;  

        Imgs = theImages;
        try { wd = Integer.parseInt(w); }
        catch (NumberFormatException e) {wd = 300;}
        try { ht = Integer.parseInt(h); }
        catch (NumberFormatException e) {ht = 200;}

        nextbutton = next;
        prevbutton = prev;
        ta = textarea;
        showmsg=showmsgarea;
        buttons=showbuttons;
        Msgs = theMessages;

        if ( showmsg && buttons )
        {
            xxx=50;
            yyy=140;
        }
        else if ( showmsg && !buttons )
        {
            xxx=50;
            yyy=100;
        }
        else if ( buttons && !showmsg )
        {
            xxx=50;
            yyy=75;
        }
        else
        {
            xxx=50;
            yyy=25;
        }
        setTitle("O'Reilly Java Books");
        resize(wd,ht);

    }

    public void run()
    {
        paint(this.getGraphics());
    }

    // We override this method so that it doesn't clear the background
    // before calling paint().  Makes for less flickering in some situations.
    public void myupdate() 
    { 
        Graphics g = this.getGraphics(); 
        g.clearRect(0,0,wd,ht);
        paint(g);
    }

    public void paint(Graphics g)
    {
        Image img=null;
        img = (Image)Imgs.elementAt(count); 
        g.drawImage(img, xxx, yyy, this);
    }

    public boolean handleEvent(Event event)
    {
        switch(event.id)
        {
            case Event.WINDOW_DESTROY:
                this.hide();
                break;
            case Event.ACTION_EVENT:
              if ( buttons )
              {
                if ( event.target == nextbutton )
                {
                    count++;
                    if ( count >= Imgs.size() )
                        count=0;
                    if ( showmsg )
                        ta.setText((String)Msgs.elementAt(count));
                    myupdate();
                    return false;           
                }
                else if ( event.target == prevbutton )
                {
                    count--;
                    if ( count < 0 ) 
                        count=Imgs.size()-1;
                    if ( showmsg )
                        ta.setText((String)Msgs.elementAt(count));
                    myupdate();
                    return false;           
                }
              }
              break;
        }
        return true; 
    }
}


web browser-based data entry via java applet.


import java.applet.Applet;
import java.awt.*;

public class de extends Applet
{
    Panel buttons = new Panel();
    TextArea ta;
    TextField af;
    TextField qf;
    Button bBack;
    Button bForward;
    Button bNew;
    Button bHelp;
    Button bProject;
    Button bGoto;
    Button bSubmit;
    String entry=null;
    boolean end_of_survey = false;
    boolean doing_a_goto = false;
    int tmp_num = 0;

    String qu_text[] = {
        "App Number",
        "1. HOH age",
        "2. Gender",
        "3. Marital status",
        "4. Race",
        "5. Income",
        "6. Geographic region",
        "7. Household size",
        "8. Education" 
    };

    String valid_codes[][] = {
        {"1000000", "2999999"},
        {"18", "99"},
        {"1", "2"},
        {"1", "6"},
        {"1", "4"},
        {"01", "12"},
        {"1", "9"},
        {"1", "5"},
        {"01", "10"}
    };

    int start_end_cols[][] = {
        {6, 12},
        {32, 33},
        {34, 34},
        {35, 35},
        {36, 36},
        {37, 38},
        {39, 39},
        {40, 40},
        {41, 42}
    };
    int i=0;
    int qctr=0;
    int max_qus = qu_text.length;
    String answers[] = new String[max_qus];

    public void init()
    {
        bBack = new Button("Back");
        bForward = new Button("Forward");
        bNew = new Button("New");
        bHelp = new Button("Help");
        bProject = new Button("Project");
        bGoto= new Button("GoTo");
        bSubmit= new Button("Submit");

        ta = new TextArea("",15,80);
        ta.setEditable(false);

        qf = new TextField(qu_text[qctr],35);
        qf.setEditable(false);

        af = new TextField(35);

        buttons.add(bBack);
        buttons.add(bForward);
        buttons.add(bNew);
        buttons.add(bHelp);
        buttons.add(bProject);
        buttons.add(bGoto);
        buttons.add(bSubmit);

        this.add("North", buttons);
        this.add("South", ta);
        this.add(qf);
        this.add(af);
    }

    public boolean handleEvent(Event e)
    {
        if (e.id==Event.ACTION_EVENT && e.target==af)
        {
            entry = af.getText();      
            if ( doing_a_goto )
            {
                try {
                    tmp_num = Integer.parseInt(entry); }
                catch (NumberFormatException ee) {
                    return false; }

                if ( tmp_num >=0 && tmp_num < max_qus )
                {
                    qctr = tmp_num;
                    qf.setText(qu_text[qctr]);
                    af.setText(answers[qctr]);
                    doing_a_goto = false;
                }
                return true;
            }

            if ( ValidEntry(entry) )
            {
                answers[qctr] = entry;
                ta.appendText(qu_text[qctr++] + "  :  "  + entry +"\n");
                af.setText("");
                if ( qctr == max_qus )
                {
                    ta.appendText("\n***** END OF SURVEY *****\n");
                    qf.setText("");
                    end_of_survey = true;
                    return false;
                } 
            }
            else
            {
                ta.appendText("*** Error: invalid entry for [" + qu_text[qctr] + "=" + entry + "]  Valid range of codes are: " + valid_codes[qctr][0] + "-" + valid_codes[qctr][1] + "\n");
                af.setText("");
            }  
            qf.setText(qu_text[qctr]);
            return true;
        }
        else if ( e.id==Event.ACTION_EVENT && e.target == bNew && !doing_a_goto )
        {
            qctr=0;
            ta.appendText("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n***** START OF NEW SURVEY *****\n\n");
            for (i=0; i 0 )
                qctr--;
            qf.setText(qu_text[qctr]);
            af.setText(answers[qctr]);
            return true;
        }
        else if ( e.id==Event.ACTION_EVENT && e.target == bForward && !end_of_survey && !doing_a_goto )
        {
            if ( qctr < max_qus-1 )
                qctr++;
            qf.setText(qu_text[qctr]);
            af.setText(answers[qctr]);
            return true;
        }
        else if ( e.id==Event.ACTION_EVENT && e.target == bGoto && !end_of_survey )
        {
            qf.setText("*** Goto what question number?");
            af.setText("");
            doing_a_goto = true;
            return true;
        }

        return false;
    } 

    public boolean ValidEntry (String es)
    {
        if ( es.length() != valid_codes[qctr][0].length() )
            return false;
        else if ( (es.compareTo(valid_codes[qctr][0]) < 0) || (es.compareTo(valid_codes[qctr][1]) > 0) ) 
            return false;
        else
            return true;
    }

}