Blog

Why does … (or the problem of predictive search)

found this when I started typing ‘why does…’

I think most search engines would rank the results according to popularity, rather than results or relevancy. So it’s shocking to know what people really want to know about themselves and their dogs. Funny though

(Google Predictive Search)
FYI: I wanted to search for ‘Why does it hurt when I pee’ (not for myself, but the popular Frank Zappa song. I assure you, everything is fine!)

Java & MySQL select query to return a two dimensional array of results

(vector of arrays actually)

When I started to do some Java again, I noticed that Java doesn’t really have an easy way of getting an array from a query, if you don’t always want to declare how many columns and rows you expect. To circumvent this problem I have a class in my toolkit that contains a method that returns a vector of result lines and each element contains an array of results…

This makes it really easy then to just write a query, like

Vector  myResultVector = selectQuery("select * from customerdetails");

, and get the Vector of arrays back.

To illustrate, here is the method:

public Vector selectQuery(String query) throws SQLException {
Statement st = connection.createStatement();
ResultSet res = stat.executeQuery(query);

ResultSetMetaData rsmd = result.getMetaData();
numCols = rsmd.getColumnCount();

               // Optional print out:
//System.out.println("The query was executed. The number of columns returned is: " + numCols);

        //We don't return this here in the same method, but this variable is declared earlier and can be returned through a different method.
for (int i=1; i<=numCols; i++) {
            columnNames.add(i-1, rsmd.getColumnName(i));
           // System.out.println(columnNames.elementAt(i-1));
}

while (result.next()) {
String[] arr1 = new String[numCols];
for (int t=1; t <=numCols; t++) {
arr1[t-1] = result.getString(t);
//System.out.println(arr1[t-1]);
}
results.add(arr1);
}
return results;
}

In the constructor of the actual class, I have the database connection, looking something like this:

 public mysqlConnector() {

try {
String userName = "YOURUSER";
String passWord = "YOURPASSWORD";
String url = "jdbc:mysql://YOURSERVER/YOURSCHEMA";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            connection = DriverManager.getConnection (url, userName, passWord);
            System.out.println ("Database connection established!");
}
catch (Exception err1) {
System.err.println ("Cannot connect to database server!");
err1.printStackTrace();
}
}

Maybe worth mentioning the global variables that I declare in this class:

 public Vector results = new Vector ();
public Vector columnNames = new Vector ();
public int numCols  = 0;

The results, because there are other methods that are using the same Vector, the columnNames and the numCols, because there is a method that returns them when I need them:

public Vector  getColumnHeaders(){
return columnNames;
}

public int getColumnNumber(){
return numCols;
}

It might also be good to close the database connection when you don’t need it anymore:

 public void disconnectionNotice() {
if (connection != null) {
try {
connection.close ();
System.out.println("Connection to DB closed!");
}
catch (Exception err2) {
//err2.printStackTrace();
}
}
}

Hope this helps some of you that might have struggled with the same problem. Email me if this isn’t all clear to you… Happy to help.

Installing the Google debian / ubuntu repository (chrome / picasa)

I have found it difficult to find the line what exactly the line is that I need add to my /etc/apt/sources.list ... I finally found it on the Google site here.

But to spell it out:

# Google software repository
deb http://dl.google.com/linux/deb/ stable non-free main

If you are using the GUI, you can simply go to

Software Sources > Other Software > Add

and add the repositories this way. This should then also automatically provoke an update of the software sources…

There might get a warning saying that the package is unsigned. I haven’t tried, but from what I can see, there is a link on the Google page.

Google Wave – Testing the preview

What can I say? Not much, except it’s a cool tool.

I have yet to find reasonable use for it, but having access to it is quite nice. I also still don’t have enough people that I can communicate with, so it’s a bit of challenge using it.
I still have a few invites left, so if you are reading this and are interested, send me a message or leave a comment to get access…

One plugin that I think would be very desirable is a calendar feature: link items straight to your Google or Office calendar would be awesome.

We will see what the future holds…

Here is an early screenshot:

Removing the Koobface Worm (WORM/Koobface.bgn)

I came across this facebook worm for the first time today… It’s seems that more and more facebook users get their account hacked and then somebody posts links to malicious sites on the walls of their friends.

Unsuspecting friends then install updates to the ‘Flash Player’ or what-have-you and BANG!

In this instance the removal seems easy enough:

  1. Get a list of suspicious processes (HiJackThis can help). In this instance we have:
    C:windowsld15.exe
    C:windowspp12.exe
    And lots of files in:
    C:Documents and Settings[USER]Local SettingsTemp
  2. I got myself a Linux Live CD (ubuntu) and booted into this live version
  3. I started deleting the files above
  4. I rebooted into save mode (press f8 just after BIOS message)
  5. When Windoze started, I went into the registry (press WinKey + r and enter ‘regedit’) and deleted the referring keys in:
    HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrent VersionRun

Restarted and prayed 🙂

But it seems to have worked, cause I don’t see any suspicious process in HiJackThis anymore.

Video splitting with MEncoder

So now the question is how can you use MPlayer’s Mencoder to split a video file into chunks, or how can you just cut a scene out?

I haven’t really found an option to just cut it out in one go, but MEncoder is so fast, it’s easy to just cut twice, first the beginning:

mencoder -ss 00:13:11 -oac copy -ovc copy original.avi -o new.avi

Simply exchange the time (HH:MM:SS) with the ‘begin’ point of the new video. That copies all the rest of the file into a new one.
Now you need to trim the file to get the new end:

mencoder -endpos 00:01:11 -ovc copy -oac copy in.avi -o out.avi

This makes the file exactly 1 minute 11 seconds long.

With this method you can split any video in any number of smaller chunks.
Happy video sharing!

PS: I think I already showed how you can combine to videos, in case you wanna reverse the process, if not, I will post this soon.

Uploaded my first YoutTube Video

I have uploaded my first YouTube video today. Unfortunately it was blocked, because the content is owned by NBC (those b***ards). I clipped a little episode out of 30 Rock, episode 10 of the first season (The Rural Juror).

It’s the clip where Tracy Jordan markets his meat machine on a infomercial type show. It’s one of the best episodes, in my opinion.

If you want to see if you can watch this clip (it’s restricted in some countries), you can check it here: http://www.youtube.com/watch?v=JWcKgSj66TM

I wish I could embed this clip on here: