20 March 2009

Flying lesson, practiced stalls, slow flight and landings. Flew at 8500 MSL around SW of JST for about 1.6 today. First time practicing stalls and first time above the cloud cover.

Posted by Picasa

25 February 2009

These are a few pictures of my first ever flying lesson. This was an introductory flight and I hope to post my progress here as I continue throughout the process. The lessons are at Johnstown airport and the instructors are knowledgeable and friendly. It is too bad the weather in this area is so random but I guess that will be good practice.

This is Johnstown PA.
 


This is my hand actually flying this plane. (Esoteric note for LOSTies, the plane's call numbers are 581, almost just right.)



The awesome Piper Cherokee I'm learning in.
 

more to follow...
Posted by Picasa

10 November 2008

Bubblesort Multidimensional Array in Java

This quick work around will allow for an easy an "efficient" sort of a multidimensional array in Java. Simply pass your array in and the index you'd like to sort on. 
Although there are other solutions to this, using java's builtin Arrays.sort method won't cut it. I put together this code to be called as a private method within your application. Enjoy!

This works great when using a String[][] compare. If you are trying to sort integers, simply change your array and take out the if (...compareTo...) business and just check which is greater.
private String[][] bubbleSortMulti(String[][] MultiIn, int compIdx) {

String[][] temp = new String[MultiIn.length][MultiIn[0].length];
boolean finished = false;

while (!finished) {
finished = true;
for (int i = 0; i < MultiIn.length - 1; i++) {

if (MultiIn[i][compIdx].compareToIgnoreCase(MultiIn[i + 1][compIdx]) > 0) {

for (int j = 0; j < MultiIn[i].length; j++) {

temp[i][j] = MultiIn[i][j];
MultiIn[i][j] = MultiIn[i + 1][j];
MultiIn[i + 1][j] = temp[i][j];
}

finished = false;

}

}

}
return MultiIn;
}

28 August 2008

Corporate do-gooder


A very talented team of coworkers (Kevin, Diane and Adam) along with my constant meticulous badgering launched a new website for the United Way of the Laurel Highlands. The site was a voluntary project outside of our normal day to day.

Technologically, the site is PHP with mySQL using mod_rewrite to clean the URLs and mod_cache for, well, caching. I'll follow with a mod_rewrite tutorial someday. For now check out uwlaurel.org.

31 July 2008

Building a Web Service with Java, Jena and mySQL [Part 4.1] - SPARQL Update

Now that Jena 2.5.6 supports updates directly through SPARQL, Part 4 of this tutorial is deprecated. We no longer need to use multiple methods to run the insert, update and delete utilities. Instead you can use some of the new SPARQL awesomeness to do that work.

You may want to determine which route you're going to take. If you use the methods from Part 4 you have more control of what is being passed to Jena. Additionally, you're controlling the triple store and models directly instead of letting SPARQL do the work. It's your call.

import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.update.UpdateAction;
...
public static boolean sparqlUpdater(String query, String modelName) throws Exception {
IDBConnection dbcon = initDBStore(M_DB_URL, M_DB_USER, M_DB_PASSWD, M_DB_TYPE,
CLEAN_DB);
ModelMaker maker = initModel(dbcon);
Model model = maker.openModel(modelName);

// the UpdateAction obj does all the hard work now.
// there is a slight bug in this version of Jena that requires the new
// QuerySolutionMap obj created. I believe this is fixed in the SVN.
UpdateAction.parseExecute(query, model, new QuerySolutionMap());
model.close();
maker.close();
dbcon.close();
return true;
}

Obviously, surround that in some try/catch business and remember this requires Jena 2.5.6 (newest version at the time of this writing.) So get that in your -classpath and get rid of the old stuff. This should greatly simplify CRUD activities with Jena persistent store. One other thing to note, although you can use a SPARQL select through this method, I wouldn't. This only returns a boolean whereas our sparqlSelect() method returned a String[][].

28 July 2008

Scala: Fibonacci Revisited and Recursed

Building on the previous Fibonacci number function, we have some more Scala specific tools available at our disposal. In the previous example, I basically did a verbatim duplication of Java to Scala.
This post builds on the same Fibonacci function using the Scala match. match is a Scala implementation of the Java switch statement. Additionally, match is available for all objects instead of just an int, char, byte and short.
Tree Recursion

def fibonacci(num: Int): Int= {
num match {
case 0 => 0
case 1 => 1
case _ => fibonacci(num-1) + fibonacci(num-2)
}
}

This should be relatively straightforward right? One new token that appears in this example is the use of _. The underscore in Scala is a wildcard character and in this case example gives us an 'all others' or 'default' to match. The underscore can also be used in your imports.
Java
import java.io.*;

Scala
import java.io._

Functional languages lend themselves toward recursion rather than looping. Our Fibonacci number method is a recursive function but could make better use of the Scala compiler as tail recursion. Tail recursion will optimize the threads needed for each iteration of our method.
Tail Recursion

def fibonacci(num: Int) = fibonacciTR(num, 1, 0)

def fibonacciTR(num: Int, nxt: Int, res: Int): Int= {
num match {
case 0 => res
case _ => fibonacciTR(num-1, nxt+res, nxt)
}
}

The tail recursion is a good deal more gentle than the tree recursion method. In your journeys toward functional programming put aside what you know about iteration and looping and look at how recursion can do the work for you.

18 July 2008

Java to Scala: We'll do it live!

Today begins a disjointed tutorial on Scala. For those of you out there that think functional programming is just plain awful, I don't blame you. I am no advocate of Ruby or it's ilk but Scala feels and looks different, especially for a Java programmer.

It's different because it natively inherits all of Java's classes and has interoperability without all the garbage. There are plenty of discussions about this available so it's not necessary to duplicate one here. Lets just say that inferred typed variables feels nice for a change. I thought that PHP was messy because variables did not need typed and this was one of the strict things about Java that I liked. Each day I like it less and less. Why for instance does one need to define the primitive types like String var = " "; when it is quite obvious that it is a string there in those quotes? Scala can just infer this is a string without the hand-holding var = " ".

Oh and no trailing semi-colon; that was no typo. It is not necessary when the line ending is obvious.

I'm going to go against the grain of the computer overlords and not demonstrate 'Hello, World!' application. Instead lets do something fun, that everyone loves, recursion. Well not just any recursion, Fibonacci numbers.
Java

public int fibonacci(int num) {
return num <=1 ? num : fibonacci(num-1) + fibonacci(num-2);
}

Now we're going to do a direct conversion to Scala. If you read the language ref, there is no ternary condition so we have to go with if-else. There is a really cool reason for this, however. In Scala we can use one expression and use the if-else to compare it. More on this if necessary.
Scala

def fibonacci(num: int): int= {
if (num<=1) return num
else
return fibonacci(num-1) + fibonacci(num-2)
}

Those of us with a C background may have thrown up a little bit in your throat looking at that. Relax, it's easy to follow. def defines our method, num: int says we're accepting an integer param and int= { } says we're returning an int type. Simple right? We'll move on in future discussions to web frameworks for Scala.

This is just a !HelloWorld Scala intro example. I hope this gives a brief introduction. More will follow sporadically.

Semantic Web

Loading...