Friday, December 10, 2010

Sorting and Searching Algorithms and Project Euler


I've some extra time recently (well, not really), so I've decided to increase my understanding of sorting and searching algorithms.


The project hosting site above is where I'll be doing my work.

I'm also using this to get familiar with Java, and in particular: polymorphism, interfaces, exceptions, encapsulation, inheritance, and modularization.

I've also started doing some problems from the Project Euler site, an algorithm problem website. Here's some of my solutions:

Wednesday, December 8, 2010

33. Decathlon Design 3

This is the final phase of our solar decathlon home management system mockup for the semester. We've been tasked with taking our Balsamiq mockups and converting it to an HTML-Wicket Framework model.




What I learned from this:
I learned a lot about Wicket, and got some very helpful hints on web design as well. I also can see the advantages of a framework like Wicket; it allows the developer to bundle everything into a neat little archive file that can be run from any computer. And in the webpage sector, this involves bundling a webserver (we used Jetty) so that any prospective client can view dynamic web content as long as they have the Java JVM installed. This avoids the difficulty of having to set up a web server or the need to have internet access in order to view a dynamic web page.

What we did well:
I've been lucky enough to be part of a group that has two exceptional web designers and programmers, which makes it incredibly easy and efficient to get things accomplished. I thought that we did a good job on focusing on the development of a template. This really allowed us to push forward quickly with the knowledge that the framework that we were working on was sound and well-developed.

Some Difficulties Encountered:
There was a lot of time spent just figuring out how to get Wicket to do what we wanted to in the HTML markup. There was also some Javascript that we used for some of the interactive portions of the system, and importing different libraries and getting them to sync with the CSS files was challenging to say the least.

What I wish we had done differently:
I would've liked to have created my own CSS file for custom classes. I had to add a few CSS classes and during one instance, I updated the CSS and found that another team member had committed the same CSS file prior to me, resulting in a conflict.

Other than that, we had pretty good communication and met a number of times in-person as well as over the phone to ensure everyone was on the same page.

How did we satisfy the three prime directives?
The three prime directives of open source software engineering are:
  1. The system successfully accomplishes a useful task.
  2. An external user can successfully install and use the system.
  3. An external developer can successfully understand and enhance the system
Directive 1:
This system provides home users with a portal that allows them to view the current status of the major systems within the home. It also allows the user to change settings such as temperature, lighting, and security to name a few.

Directive 2:
Due to the use of the Ant build system, installing and running the embedded jetty server takes a single command: java -jar filename.jar

Directive 3:
Developers can edit the server-side source code via eclipse (distribution file has been included in downloads section).

Monday, December 6, 2010

LISP and Finding an Interpreter/Compiler

After hearing of the 'light switch' effect and nirvana that LISP brings about, and reading the following article:


I've decided to start learning LISP during Christmas break. I had about a 3-week crash course on it during my Computer Programming Concepts class, but I didn't really think much more of it other than 'okay that was cool, but I'll never use this again.'



The Search for An Interpreter/IDE

I started by going through a couple of the available LISP interpreters: GNU CLISP, Ufasoft LISP, and LispWorks.

I'd used LispWorks before but decided that I ought to try some other IDE to get a sense for what's out there.

After trying to install Ufasoft, I found that a Microsoft Visual Studio component needed to be installed first. Cancel -- I wanted something that could work on both my MacBook and Windows machines. GNU CLISP installed fine, but this gave a command-line only interface and a quick look through things did not uncover any extensive help information.

So back to LispWorks. Here we go!






Saturday, December 4, 2010

Network to Host Long Long

Since I'm applying for summer internships and employment now, I've been trying to hone my coding skills. I decided to implement my own version of network-to-host-long-long (ntohll) for 8-byte integers using bitwise operators in C. Operates similar to ntohs(short s).


This was for a group networking protocol assignment in my data networks class.


It was challenging, although time consuming, and later I found a much more elegant solution on the internet. But this my ugly bastard child and I'm keeping it.


Network to Host Long Long (Source Code)

/**
* Determines the host machine's endianness.
*
* @return 1 if Little Endian, 0 if Big Endian
*/

int checkEndian () {

void * p;
unsigned short * shortP;

unsigned char buffer[2];
p = (void * ) buffer;
shortP = (unsigned short * ) p;

* shortP = 0x01;

if (buffer[0] == 0x00){
if (debug) {
printf("Big Endian\n");
}
return false;
}

else {
if (debug) {
printf("Little Endian\n");
}
return true;
}

}

/**
* Given a long long number reverse the order of the bytes
* if the machine is Little Endian. Otherwise do nothing and
* return the number.
*
* @param input - network value to be converted to host order
*/
unsigned long long ntohll (unsigned long long input) {
if (checkEndian()){
unsigned long long result = 0;
unsigned long long mask = 0xFF;

if (debug){
// Print INPUT
void * p;
unsigned char * buffer;
p = (void *) &input;
buffer = (unsigned char * ) p;
int j;
for (j = 7; j >= 0; j--) {
printf("%x ", buffer[j]);
}
printf("\n");
}

// Input will be reversed
// Need to reverse all 8 bytes
int i;
for ( i = 0; i < 8 ; i ++){

if (i < 4) {
result = result | ((input & ( mask << (i * 8) )) << (8 * (7 - 2 * i) ));
}
else {
result = result | ((input & ( mask << (i * 8) )) >> (8 * ( 2 * (i - 4) + 1) ));
}
}
// Print resulting value
if (debug) {
void * p;
unsigned char * bufferResult;
p = (void *) &result;
bufferResult = (unsigned char * ) p;
int j;

for (j = 7; j >= 0; j--) {
printf("%x ", bufferResult[j]);
}
printf("\n");
}
return result;
}

// If Big Endian, we can just return value without swapping bytes
else {
return input;
}
}


Thursday, December 2, 2010

Google Visualizations for Final Project (ICS413)

NOTE:
chart size: Width x Height: 410 x 350 (&chs=410x350)
Title Font Size: 16.5 (&chts)
Axis Font Size: 11.5 (default)
Tick marks (y-axis, x-axis): 1,15 (&chxtc=1,15)

Energy Page:
(by Day)

(by Month)

Energy Breakout:
(by Day)

Temperature:
Aquaponics Statistics:
(pH by Day)

Aquaponics:
(Water Quality - Current Quick Look)

Aquaponics Water Reserves
(Current Levels)





Tuesday, November 23, 2010

31. Wicket Katas


We've been tasked with modifying a few example Wicket framework projects as "katas".

Wicket expertise prior to the Katas:
I've been slowly reading through the Wicket book. I think I a vague (albeit better) understanding of the difference between the static and dynamic model system. I would say that my understanding of Wicket as of now is still pretty elementary; I am still a little unsure about the whole component/model relationship and when a component gets re-rendered. Little by little, however, and as I continue to read the book, I've acquired a better understanding of the functions and underpinnings of the framework.

Here's a link to a description of the Katas: ICS413 Wicket Katas

Kata 1A: Duration - 30 min
Kata 1B: Duration - 10 min
Kata 1C: Duration - 2 min
Kata 2A: Duration - 1 hr 15 min
Kata 2B: Duration - 4 hours
Kata 3A: Duration - 30 min
Kata 4A: Duration - 5 min
Kata 4B: Duration - 20 min
Kata 6A: Duration - 2 min
Kata 6B: Duration - 2 min
Kata 6C: Duration - 2 hrs

Total Duration: 8 hrs 16 min
ALL Katas Completed.

Distribution Versions:

For the most part, a lot of these Katas were adapting already existing code to meet the specifications and weren't all that difficult. 2B, however, took a lot more time to figure out. Here's what we were tasked to do:

Kata 2B: Add a button on the home page with the label, "Make font bold". After the user pushes it, all the text on the page should become bold, and the button label should change to "Make font italic". When the user pushes that button, all of the text should change to italic and the button label should change to "Make font normal". Pushing that button changes the text back to its original state and the button label should now say "Make font bold".



This kata really forced me to examine the interaction between what's presented on the page versus what lives in the java code. I also had to attach a CSS style attribute to the body of the page, which had nested tags, so Wicket's hierarchical structure initially caused errors in the page. After matching the hierarchy with the Java code, I was able to use the attribute modifier function to toggle between font-weight: bold/normal and font-style: italic.

Another problem that I ran into was the toggling of the styles with a submit button. This meant saving a state of some sort, which I solved through use of a session. Prior to this, the flag I used to toggle between styles would not save it's state between page refreshes.

Finally, I had to implement a child class to the Link class. For some reason or another, the button and submit classes did not refresh the page as needed. In order to change the label on the button with each click, I had to create a child class to the link class and implement this toggling of the label within the constructor.

This was by far the most difficult of the 11 assignments.

Probably the second most interesting kata was the following:

Kata 6C: It is often convenient for web applications to consult a properties file when starting up in order to get configuration values. An easy way to do this is with the standard Java Properties mechanism. (See Java in a Nutshell for details on properties file manipulation.) For this Kata, modify your Example06 system to read in a file (if present) located in ~/.example06/configuration.properties. (Note that ~ means "the user's home directory", and that there is a System property in Java that provides this value.) This property file should contain a line like the following: deployment=true

Although not really enlightening in regards to improving my familiarity with Wicket, I did learn about Properties files in Java and how they're used to configure applications. This exercise also helped me brush up on catching exceptions and opening files and streams.

Conclusion
I liked these exercises. I thought they were very do-able and the combination of having templates to work from in addition to other resources (book and Google) really helped to lessen the frustration factor.

I'm starting to appreciate the framework and it's workings. Although by no means have I mastered models, I do have a basic understanding of them as well some of the limitations that the framework presents. E.g., the need to store variables in a session in order to preserve their current values.

The Cheeser example is starting to grow on me too the more I look at it and examine what it can do.