Archive for the ‘Programming and Coding’ Category

494 Project – APE Grader

Finally finished up this class! Thought the day would never end. For my senior project, I was part of a group that implemented a sort of scheduling application for a special type of exam that the CS department at EWU gives to determine who gets to move further on in the degree. Basically it tests your abilities to make linked lists, recursion, and other general programming principles in the Java language.

This application lets you register for an exam if you’re a user, lets you grade exams if you’re a grader, and administer things if you’re an administrator. Pretty simple.

Trac link: http://trac.austrianalex.com/494/

SVN: https://trac.austrianalex.com/svn/494/

Mostly all the good information can be found at the trac site. I won’t go repeating it here. This program, like other good little programs, is released under GPLv3. If this code is useful to you, go ahead and use it

Half a year isn’t so bad…

…you know, for a new blog update. I mean, if I really had more time to type things into my website only to have it be publicly criticized, gosh darn, that’s all the motivation I need! I don’t need time, I don’t need to work on linear algebra homework, I can just write in my blog. Because I haven’t done it in a while. Half a year isn’t so bad.

So what’s new? I’ve began dabbling a bit into open source software in my free time (instead of writing in my blog! the blasphemy) and while the project is nothing too glamorous at this point, it is being maintained and updated…in my free time…blog…

Yeah, so the concept of this project was to simply take the existing (and pretty well built) wTorrent project and turn it into something more advanced…like wTorrent Advancedyes, very original; it took me all of my non-existent free time to come up with that and the logo.

wTorrent Advanced

Ok, so what is this exactly? Simply put, it is a web interface to a shell based torrent client (rtorrent) that communicates via XMLRPC. This project takes wTorrent’s codebase and improves the general user experience by adding in nifty little controls – file management, expanded admin capabilities, torrent management enhancements via categories/tags/whatever I want to put in. More details can be found at my trac site.

Right now, the project is very bleeding-edge and alpha-phasish, meaning if you want to try it, it’s at your own risk.

Now it’s 10PM and I gotta check woot.

Java Pacman™ — Pacmon!

So back in the spring, I was in a GUI class at my university that made me program a simple java based version of Pacman™. After screwing around with it for a bit more, I figured I might as well post it up on my site for others to enjoy or learn from (aka improve on my mistakes).

Technical Highlights

All of this code is made with Swing, which makes the animation on slower computers (and even some faster computers) a bit jaggy. The animations themselves are timed with java.awt.Timer’s, then the panel is repainted every 1/4 of a second at least, making that jagged effect happen. Yeah, I could have optimized the repaint function a little by making some buffers with the terrain and whatnot, but I was lazy.

There are 3 LinkedList objects being repainted: the terrain classes (Wall, Floor), the food classes (currently only “Pill”), and the Creature classes (Player and Monsters).

From PacCanvas.java

   /**
    * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
    */
   public void paintComponent(Graphics gfx)
   {
      //super.paintComponent(gfx) ;
      Graphics2D g = (Graphics2D)gfx;
      int statusFood = 0;
	  ListIterator titerator = tstorage.listIterator();
      while ( titerator.hasNext() ){
    	  Terrain t = titerator.next();
    	  t.draw(g);
      }

      ListIterator fiterator = fstorage.listIterator();
      while ( fiterator.hasNext() ){
    	  Food f = fiterator.next();
    	  statusFood++;
    	  f.draw(g);
      }

      ListIterator citerator = cstorage.listIterator();
	  while ( citerator.hasNext() ){
		  Creature c = citerator.next();
		  c.draw(g);
	  }

      frame.setStatus("Level: "+curLevel+". Current Points: "+statusPoints+". Number of pills left: "+statusFood+". Number of lives left: "+lives);
      if (statusFood == 0 && !end)
    	  newLevel();
   }

Each creature has its own timer that is called for animation and movement purposes.

The levels are basically preset by MazeGrid.java at 20×20 with declarations made in PacCanvas.java. An example is made below. 0 initializes a floor, 1 a wall, 2 the player, and 3 and above are reserved for monsters (these are all viewable from a switch statement made in the initial terrain linked list building function (wherever that is)).

From PacCanvas.java

transient final int lvl[][] = {
   {
			1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
			1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,3,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,0,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,3,0,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,3,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
			1,2,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
			1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
   }, ...
}

Everything was pretty much made public in terms of global variable declaration (actually more like default…), just so I didn’t have to worry about get and set statements and not having proper permissions, etc. If you want to do a better job, go right ahead :P . Oh yeah, I also gave direct access to frames from the canvas and menus below it (or in it, so to say), again for ease of access.

For the final version, I disabled the music from playing at startup, but this can easily be enabled from withing the main “main” function. The music is played with the tritonus_share and zoom libraries. The RelativeLayout library is used for the dialogue boxes (I had to go to awt.dialogue boxes because the swing ones (JDialogue) didn’t work properly once the game was started for some weird reason).

The gameplay specifics can be found in the readme document in the zip file attached to this post. The main program itself is licensed under the GPL v3, with the source code being in the main jar file.

Pacmon Screenshot

Pacmon Screenshot

In unrelated news, I had to use two alt codes in the title of this post.

PacMon Download

C Me

So, I recently made my first “major” C program. While I did have previous experience with the C syntax and whatnot (C++ being the very first language that I learned on my own), I found C to be just as or even more…how to put it…ancient? I mean, this language is as old as I am practically. Nonetheless, it is still being used and is still pretty high level compared to assembly, so I don’t mind…much.This program basically takes grades inputted from the user, forms a linked list out of them, and calculates the grades, forming a % and gpa. The full specs can be found in the attached PDF. Note, I did not include main.c, because all it does is call the run() function.

func.h

/**
* Created on: February 05, 2008
* @author Alexander Chernikov
* @license GNU Public License v3
*/
#ifndef FUNC_H
#define FUNC_H
#include
#include
#include
//Set any G_* to 0 to have user input on max points
#define G_ASSIGN 0
#define G_QUIZ 25
#define G_TEST 100
#define G_EXAM 200

#define P_ASSIGN .40
#define P_QUIZ .10
#define P_EXAM .25

#define CAT 4

//Linked List FTW - the APE did bad things to me
typedef struct node {
double data;
int max;
struct node* next;
} list;

list* grades = NULL; //global linkedlist for storing a dynamic list of grades

void addNode( double, int); //adds a score and a max score
void clearList(); // obligatory command for memory - no memory leak for YUO!
void printlist(); //for debugging...unfortunately, the problem was never here

void getCatMax(int*); //gets number of items per category
void getScores( char*,int, int);

double calculateGPA(double*, double*); //actually calculates percentage...too lazy to change name
double calculateScores();

void print_results(double*, char**, double);

#endif

Func.c

/**
* Created on: February 05, 2008
* Grade Calculator
* Utilizes ALL extra credit available.
* @author Alexander Chernikov
* @license GNU Public License v3
*/
#include "func.h"
/**
* Sort of another main..err...
*/
void run(){
int catMax[CAT] = {7,3,2,1}, catMaxPoints[CAT] = {G_ASSIGN, G_QUIZ, G_TEST, G_EXAM};
double avg[CAT], catWeight[CAT] = {P_ASSIGN, P_QUIZ, P_EXAM, P_EXAM}, gpa;
char* catName[CAT] = {"Assignment","Quiz","Test","Final Exam"};
//list* grades = NULL;

//send off catMax to a function which asks for catMax values
//but just the first 3! we only have 1 final.
getCatMax(catMax);
//two for loops - outer with 4 for each category, inner doing catMax[x] and passing strings
int i, j;
char* s;
printf("\n");//just because
for ( i=0; i < sizeof(catMax)/sizeof(int); i++){
for (j = 0; j < *(catMax + i); j++)
getScores( *(catName+i), *(catMaxPoints+i), j+1);
avg[i] = calculateScores();
//DEBUG
//printlist();
clearList();
printf("\n");//just because

}
gpa = calculateGPA(avg, catWeight);
//print out results here
print_results(avg, catName, gpa);
}
/**
* The end - printing and quitting
* @param avg - Array of average scores from each category
* @param catName - array of category names
* @param perc - calculated overall percentage
*/
void print_results(double* avg, char** catName, double perc){
printf("--------------------------\n");
printf("Percentage per category.\n");
int i;
double gpa=4;
for (i = 0; i < CAT; i++)
printf("\t%-10s: %2.2f%%\n", *(catName+i), *(avg+i)*100);
printf("\nYour weighted percentage is: %%%3.2f\n", perc);
if (perc < 95)
gpa -= (95-perc)/10;
//and then the "exceptions"
if ( (int)perc == 63 )
gpa = .9;
else if ( (int)perc == 62 || (int)perc == 61 )
gpa = .8;
else if ((int)perc == 60)
gpa = .7;
//fail
if (perc < 60)
gpa = 0;
printf("Your grade point is: %1.1f\n",gpa);
}
/**
* Retrieves scores from user input
* @param name - Name of category
* @param maxPoints - Set number of the highest grade (0 for custom)
* @param num - the number of the item (Test #2 etc)
*/
void getScores( char* name, int points, int num){
double val;

if (points == 0){
printf("Please enter the max points possible for %s #%d: ",name, num);
scanf("%d", &points); //assuming the user is in HSL, otherwise add a while loop.
}

printf("Please enter grade for %s #%d: ",name, num);
scanf("%lf", &val);

while (val < 0 || val > points){
printf("Error: value is below 0 or above max points (%d) please re-enter grade: ",points);
scanf("%lf", &val);
}

addNode(val,points);
}
/**
* Calculates all scores in list and gets a percentage.
* @return double - percent average of category
*/
double calculateScores(){
double score=0, max=0;
list* temp = grades;
while (temp != NULL){
score += temp->data;
max += temp->max;
temp = temp->next;
}
return score/max;
}
/**
* Used to calculate GPA, now calculates overall percentage
* @param avg - Array of average scores from each category
* @param catWeight - Array of category percentage weights
* @return double - overall percentage, not GPA...I was lazy to change title
*/
double calculateGPA(double* avg, double* catWeight){
int i;
double score=0;
for (i=0; i < CAT; i++){
score += *(avg+i)**(catWeight+i);
}
return score * 100;
}
/**
* Gets max items in category from user
* This could have been modularized a bit more, but again, lazy.
* Also built so it won't ask for Final exam...since there is only 1.
* @param catMax - array to initialize
*/
void getCatMax(int* catMax){
int val;
printf("# of assignments (0 or less for default): ");
scanf("%d", &val);
if (val > 0)
*catMax = val;
printf("# of quizzes (0 or less for default): ");
scanf("%d", &val);
if (val > 0)
*(catMax+1) = val;
printf("# of tests (0 or less for default): ");
scanf("%d", &val);
if (val > 0)
*(catMax+2) = val;
}
/**
* Adds nodes to list - last item added to the front of list
* @param item - user inputted score
* @param max - max number of points possible, can be user inputted
*/
void addNode( double item, int max){
list *temp = (list *)malloc(sizeof(list));
if (temp == NULL)
return;
temp->next = grades;
grades = temp;
temp->data = item;
temp->max = max;
//return temp;
}
/**
* Removes contents from list.
*/
void clearList(){
list* p;
while (grades != NULL){
p = grades;
grades = grades->next;
free(p);
}
}
/**
* A debugging method - prints list contents
*/
void printlist(){
list* temp = grades;
while (temp != NULL){
printf("%f %d\n", temp->data, temp->max);
temp = temp->next;
}
}

Assignment #1 – Instructions PDF

WPG2 Installation: A bit of a hassle.

So I was browsing the internet today and checking for latest versions of software (PHP, Apache, etc) and I thought I might as well check on an update for Gallery. I was looking through the page and found that WordPress can be integrated with Gallery through a plugin; how I did not come across this plugin before is beyond me. So of course, the installation of said plugin turned out to be a necessity.

Everything went smoothly, as with any other plugin – it got put into the plugin directory and activated through the WordPress Admin section. Then to editing the options – walking into the first tab under WPG2 presented me with a nice entry about “your Gallery rewrite module has been disabled. Go to the next tab to re-enable.” Alright, I thought to myself, shouldn’t be too hard to get fixed up. The next tab presented me with a mostly white (no CSS) style page that told me that the URL rewrite couldn’t be enabled and to go and re-enable it within Gallery. Odd.

So, I navigated back to the main tab of WPG2 only to find myself staring at an Internal 500 Server error. Great, the plugin broke something on my machine. All of my site (including my Gallery) was filled with Internal 500 Server errors. I couldn’t disable the plugin through the WordPress interface because of this, so I went and tried manually deleting the files from the plugin directory – only to find that something was still locked onto the folder, not letting me delete it. I then proceeded straight to the .htaccess files (since I knew that the error had something to do with rewriting one of these) located in the root directories of my site and found that they hadn’t been touched since the upgrade that I did a few weeks back. Odd, yet again.

Replacing all my files in my site directory with backups didn’t help either; my site was still filled with the 500 error. This plugin couldn’t have messed something up with Apache itself, could it? After all, this wasn’t a malicious plugin of any sort. I went back to my Apache directory and checked folder modification dates to find that the only folders that had been affected recently were those of the logs. Ah, why hadn’t I thought of that yet – check the error log and see what Apache is really complaining about. Sorting through the various data and 404 errors, I came across to the last entries – something about URL rewriting not being able to accept a parameter (edit: specifically “C:\.htaccess: RewriteBase takes one argument, the base URL of the per-directory context”). Interesting. Even more interesting was that Apache was now referring to an .htaccess file that was under C:\. Why in the world would an .htaccess file be written there? Apparently, this was a problem with Gallery itself as the functions that were invoked were from the Gallery coding referenced by the WPG2 plugin (though the plugin could have passed in some bad parameters as well, not really sure here at this point – URL rewriting works perfectly with Gallery, so I assume it’s something with the plugin).

So I deleted the .htaccess file from the “ultimate” root directory and found my site to be back up and running. Well, that’s good, but I still want the plugin to work…so how? Well, if something (either the WPG2 plugin or Gallery) likes writing to C:\.htaccess, let’s make it so it doesn’t. Making a blank .htaccess file and setting the permissions to read-only, I moved it to the C:\ directory and then went back to the WPG2 rewrite tab in the Admin section of WordPress. Needless to say, everything else went quite smoothly from then on. I’m still going to check in on exactly which function call made that .htaccess file in the first place and hopefully fix this need for the blank .htaccess hack.

Edit: (12/12/07) The .htaccess file is only needed the first time you enter into the rewrite tab in the WPG2 options. After initializing the rewrite options through there, I could remove the .htaccess file and have no further problems. So it must be something in the first “set-up” of this plugin that’s causing this problem.