Pseudocode Interpreter

This program was an assignment for my Programming Languages course. The idea is to implement a simple pseudocode interpreter which has very basic functionality as well as a contiguous memory store. Here is how it works:

  1. You feed the program a CRLF seperated list of valid syntax. In this case, the file “pseudocode.txt” which should be in the same directory as the program (no file picker implemented).
  2. The program reads, parses, and executes the given instructions
  3. Any errors that are found are reported, else the program runs until STOP instruction or EOF.

Continue reading

Galaguh Lua / LOVE2d Space Shooter

galaguh

This game was actually my final project for my Programming Languages class at Marshall University. It is a space-style shooter in the spirit of the classic Galaga. The game was built on top of the LOVE2D game engine and is mostly coded in Lua.

Above, you will find links to download it. The *.exe file has LOVE2d packaged with it so you should be able to run it without installing the LOVE2d back-end. The *.love file is a compressed archive of the complete source code for the program.

If you are interested in how it works, use 7-zip or a similar program to extract and view the lua files from the *.love file or check out the in depth powerpoint presentation above.

This program currently only works in LOVE2D 0.7.0. The recent release of LOVE2D 0.8.0 broke the collision detection! I will update it eventually to work with the new version.

Downloads:

Simple Java *nix shell (Proof of Concept)

This is a very simple shell interface with a built-in history feature for use in your favorite *nix environment. This small project comes from a project in my Operating Systems class at Marshall University in which we were studying message passing models in modern OSs.

It should work fine with any program that is defined in your system $PATH variable (usually /usr/bin, etc). If you type !!, it will re-run the previous command. Or n!, where n is the number of the previous command. To get a list of these previous commands and their corresponding numbers, use the ‘history’ command which will show you all of your previous entries.

/*
 * Simple java shell with history feature
 * @author bradley carey
 * @date September 26, 2011
 */

 
import java.io.*;
import java.util.*;
import java.lang.ProcessBuilder;
 
public class SimpleShell {
    public static void main(String[] args) throws java.io.IOException
    {
        String commandLine, delims = "[ ]+", pwd;
        ArrayList<String> history = new ArrayList<String>();
 
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
 
        pwd = System.getProperty("user.home");
 
        while (true)
        {
            System.out.print("jsh@" + pwd + ">");
            commandLine = console.readLine();
 
            if(commandLine.equals(""))
                continue;
 
            if(commandLine.equals("exit"))
                System.exit(0);
 
            String[] tokens = commandLine.split(delims);
            for (String s: tokens)
            {
                //currentCommand.add(s);
                System.out.println("tokens:" + s);
            }
            history.add(commandLine);
            if(commandLine.equals("history"))
            {
                for(int i=0; i < history.size()-1; i++)
                    System.out.println("[" + i + "] " + history.get(i));
                continue;
            }
 
            if(commandLine.charAt(0) == '!')
            {
                char which = commandLine.charAt(1);
                if(which=='!') // !! entered, print previous command
                {
                    if(history.size() > 2)
                    {
                        String toRun = history.get(history.size()-2);
                        tokens = toRun.split(delims);
                        for (String s: tokens)
                            System.out.println(s);
 
                    } else {
                        System.out.println("Error: unable to run previous command!");
                        continue;
                    }
                } else { // !n, run nth command
                    int whichNum = Integer.parseInt(Character.toString(which));
                    if(history.size() > whichNum)
                    {
                        String toRun = history.get(whichNum);
                        tokens = toRun.split(delims);
                        System.out.println(toRun);
                    } else {
                        System.out.println("Error: unable to run history command. Out of bounds error?");
                        continue;
                    }
                }
            }
 
            if(commandLine.equals("cd"))
            {
                pwd = System.getProperty("user.home");
                continue;
            }
 
            if(tokens[0].equals("cd"))
            {
                String changeTo = tokens[1];
                if(changeTo.contains("/")) // absolute path
                {
                    File tempFile = new File(tokens[1]);
                    if(!tempFile.exists()) // file doesnt exist, abort
                    {
                        System.out.println("Error: invalid directory specified");
                        continue;
                    } else { // file exists, change dir
                        pwd = tokens[1];
                    }
                } else { // relative path
                    System.out.println(pwd + "/" + tokens[1]);
                    File tempFile = new File(pwd + "/" + tokens[1]);
                    if(!tempFile.exists())
                    {
                        System.out.println("Error: invalid directory specified");
                        continue;
                    } else {
                        pwd = pwd + "/" + tokens[1];
                    }
                }
                continue;
            }
 
            try
            {
                ProcessBuilder newProcess = new ProcessBuilder(tokens);
                newProcess.directory(new File(pwd));
                Process current = newProcess.start();
                current.waitFor(); // create new process and wait for execution to finish
 
                // print output
                BufferedReader is = new BufferedReader(new InputStreamReader(current.getInputStream()));
                String line;
                while ((line = is.readLine()) != null)
                    System.out.println(line);
 
                // print errors
                is = new BufferedReader(new InputStreamReader(current.getErrorStream()));
                while ((line = is.readLine()) != null)
                    System.out.println(line);
            } catch(IOException e) {
                System.out.println("Error: IOException has occurred. Command invalid?");
            } catch(InterruptedException e2) {
                System.out.println("Error: InterruptedException has occurred");
            }
        } // end while loop
    }
}

Simple PHP Image Gallery

This script is a very simplified version of the imagery section of my old website. To use it on your own site, follow these steps:

  1. You need to create a folder containing only the images that you want to display. You need to set the path to the this folder on line #2.
  2. The thumbnails should be stored in a separate folder, which you must specify the path to on line #6. In the code, the tumbnails are stored in a subfolder called “thumbs” and the filename of each thumbnail is “thumb_originalFileName.jpg”.
  3. On line #6 you need to specify the path to the full images, which is probably the same path that you used on step #1.
  4. If you notice on line #7, each image is displayed inside of a html DIV container that uses the CSS class titled “gallery”. I included the CSS that I used in my imagery section in the second code box below. Feel free to customize this CSS to go along with your website’s layout.
1
2
3
4
5
6
7
8
9
10
11
<?php
foreach(new DirectoryIterator('/path/to/images') as $iterator)
{
    if($iterator->isFile())
    {
        $thumbPath = "./path/to/thumbs/thumb_" . $iterator->getFilename();
        echo '<a href="./pathto/fullsize/images/' . $iterator->getFilename() . '\ ><div class="gallery"><img src=';
        echo $thumbPath . "" />\n<p>" . $iterator->getFilename() . "</p></div></a>\n";
    }
}
?>

Here is the CSS code for the gallery class that I used:

<style type="text/css">
    div.gallery {
      float: left;
      width: 104px;
      padding: 5px;
      margin: 5px;
      padding-top: 5px;
      border: 1px dashed #000000;
      height: 120px;
    }
</style>