Clean Code That Works
Header
Clean Code That Works
Header
Clean Code That Works
Header
Clean Code That Works
Header
Clean Code That Works
Header
Clean Code That Works
Header
Clean Code That Works
Header

To import a Leiningen project into Eclipse, so that you can use CounterClockwise with all its nice features, such as syntax highlighting, there is a handy plugin called lein-eclipse.

To get started, all you have to do is to add this plugin as a dev-dependency in your project’s project.clj.

1
2
3
4
5
6
7
8
9
10
11
(defproject my-project "1.0.0-SNAPSHOT"
  :description "My Clojure Leiningen Project"
  :dependencies [
        [org.clojure/clojure "1.2.0"]
        [org.clojure/clojure-contrib "1.2.0"]
	[ring/ring-jetty-adapter "0.2.5"]
  ]
  :dev-dependencies [
        [lein-eclipse "1.0.0"]
  ]
)

Then, you need to download the project dependencies via

prompt> lein deps

This will automatically install lein-eclipse and add a new task called eclipse to leiningen. Invoking

prompt> lein eclipse

runs this task and creates the Eclipse projects files .project and .classpath. Now you can simply import the project into Eclipse via “File->Import->Existing Project into Workspace”.

When I implemented a MapView with an ItemizedOverlay (the implementation steps are described in the Android developer documentation), I encountered a flaw in the API, or at least in the corresponding documentation. If you add an ItemizedOverlay to your MapView, but do not add any OverlayItems (which may be the default for your application, with OverlayItems being added during runtime), scrolling through the MapView causes the following NullPointerException:

ERROR/AndroidRuntime(232): java.lang.NullPointerException
  at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
  at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
  at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
  at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
  at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
  at com.google.android.maps.MapView.onTouchEvent(MapView.java:625)
  at android.view.View.dispatchTouchEvent(View.java:3709)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4363)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  at dalvik.system.NativeStart.main(Native Method)

After long hours of debugging, I was able to find help in the Android Bug Tracking system. An easy workaround for this problem (which should really be addressed in the API and/or the corresponding documentation) is to add a call to the “populate()” function in the constructor of the class that extends ItemizedOverlay. Then, your subclass constructor should look like this:

super(boundCenterBottom(defaultMarker));
populate();

This solves the problem and scrolling, even without any OverlayItems, works like a charm.

Reverse Engineering a PostgreSQL Database

November 10th, 2010 | Posted by Jay in Computing - (1 Comments)

When working with legacy (relational) databases it might come in handy to visualize an existing schema. Microsoft Visio supports such a reverse engineering of most databases in a remarkably easy way. This little tutorial assumes that the database to be reverse engineered is a PostgreSQL installation.

Therefore, the first thing you need to do is to install the PostgreSQL ODBC driver.

Second, you can start Visio and create a new “Database Model Diagram”. Select the “Database” tap, and your window should look like this:

RevEng 1 Reverse Engineering a PostgreSQL Database

Visio Reverse Engineering

Now, select ‘Reverse Engineer’ and create a new data source. Choose “User Data Source” and “PostgreSQL Unicode”, as seen in the following screenshots. Enter your database connection credentials and test it.

RevEng 2 Reverse Engineering a PostgreSQL Database

Creating a PostgreSQL User DSN

RevEng 3 Reverse Engineering a PostgreSQL Database

Creating a PostgreSQL User DSN

If the User Data Source was successfully added, you should be able to select the “Generic ODBC Driver” and the specified PostgreSQL data source.

RevEng 4 Reverse Engineering a PostgreSQL Database

Visio Generic ODBC Driver

After filling in the correct username and password, you can for instance specify which object types you’d like to reverse engineer.

RevEng 5 Reverse Engineering a PostgreSQL Database

Visio ODBC Setup

The result of this process is a nicely layouted diagram of the corresponding database.

RevEng 6 Reverse Engineering a PostgreSQL Database

Example Reverse Engineered Diagram

Surprisingly, Java Servlets and JSP do not have build-in support for handling form-based file uploads. However, there are several open source libraries available for this purpose, among which the Apache Commons FileUpload is one of the most stable. This post will demonstrate how to use this library to handle form-based file uploads using JSP technology.

Two files will be required for this to work: the Apache Commons FileUpload library, as well as the Apache Commons IO library.

In order to install them correctly, one needs to extract the downloaded archives and copy the commons-fileupload-<version>.jar and commons-io-<version>.jar to the WEB-INF/lib directory of the web app that is to be developed. If these libraries rather be available to all web applications on the server, the jar files should be copied to $CATALINA_HOME/shared/lib/, where $CATALINE_HOME is the root directory of the Tomcat installation.

The following assumes that two files have been set up: first, a simple HTML file with a form that allows the user to select the file to be uploaded. Note that enctype=”multipart/form-data” is essential here.

<form method="POST" action="action.jsp" enctype="multipart/form-data">
  <input type="file" name="file"/>
  <input type="submit"/>
</form>

Second, a file action.jsp that receives the HTML file’s HTTP request and processes it. To do so, it will need to import several packages:

< %@page import="org.apache.commons.fileupload.servlet.*"%>
< %@page import="org.apache.commons.fileupload.disk.*"%>
< %@page import="org.apache.commons.fileupload.*"%>
< %@page import="java.io.InputStream"%>

The next thing to do is to check if the HTTP request is correctly encoded in the multipart format.

if (ServletFileUpload.isMultipartContent(request)){
  // Process the request
}

The actual parsing of the request is done via the ServletFileUpload class and the DiskFileItemFactory class. Here, the uploaded file is stored as a byte array in the session.

ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
 
try {
  @SuppressWarnings("unchecked")
  List< fileitem> fileItemsList = servletFileUpload.parseRequest(request);
  for (FileItem fileItem : fileItemsList) {
    if (fileItem.isFormField()) {
      /* The fileItem is not a file, but rather a name-value pair. */
      String name = fileItem.getFieldName();
      String value = fileItem.getString();
      // business logic here
    } else {
      /* The fileItem is an uploaded file. */
      byte[] fileData = fileItem.get();
      session.setAttribute("file", fileData);
    }
  }
} catch (Exception ex) {
  /* Possible exceptions include the file exceeding the upload size limit. */
}

This is only a very basic example, of course, and may not perform well with large files for example. Moreover, you might want to change the default settings for parsing the HTTP request, using the methods setSizeThreshold() and setRespository() of the DiskFileItemFactory class and the setSizeMax() method of the ServletFileUpload class.

NB logo single NetBeans Platform Certified Training I am spending the next two days doing the NetBeans Platform Certified Training at the TU Braunschweig in Germany with Sun’s Geertjan Wielenga and NetBeans Dream Team member Aljoscha Rittner.

If you would also like to have a training on the NetBeans Platform at your university or company, just drop Geertjan an email or leave a comment at his blog.

For more information about the Certified Training, visit the official course website.

Today, I took the ISTQB certification exam for the foundation level and some things struck me that might be of some interest for future examinees. As one has to sign a formal obligation saying that you’re not allowed to give information about exam questions, I cannot be very specific. However, here are some hints:

  • The standard textbook for the exam, “Software Testing Foundations – A Study Guide for the Certified Tester Exam” written by Spillner and Linz, is suitable for giving a survey and it prepares you very well for the chapters “Tool support for testing”, “Fundamentals of testing” and some other. Learn them by heart!
  • Still, even if you know the whole book literally by heart, there is only a not-so-good chance to pass! In order to be really good prepared, you should also learn the Syllabus, which can be downloaded from the ISTQB website. You should learn the Syllabus really good, otherwise a lot of questions are unanswerable, because they do not depend on understanding but the wording of the Syllabus.
  • Some questions are really incomprehensible, even if you are well prepared. At least one question in my exam didn’t make any sense, so you better anticipate that some questions are like gambling.
  • The word is that some people offer sample papers / sample exams / sample solutions on the web. If you like, use them to a impression of how questions are asked, but better be careful with the solutions–they often are wrong! So, don’t rely on things on the web, but on the Syllabus.

The examination results are send via email one week after the exam, at the latest. Of course, I’m gonna post my results as soon as I get them.

Update:
Just got my results: PASSED with 85%! icon wink ISTQB Certified Tester   Foundation Level

3DScanner completed

February 8th, 2009 | Posted by Jay in Computing - (1 Comments)

gauss 2 300x274 3DScanner completedToday, after 4 months’ work, we completed our team project software 3DScanner. The project’s goal was to capture real-world objects of any size and recreate them as 3D models in a virtual environment.

3DScanner has a lot of advantages compared to other (even commercial) products. Firstly, only one camera is needed. Any off-the-shelf digital camera can be used. It does not have to be stabilized in any way (i.e. no tripod necessary), neither does it have to be calibrated. Camera calibration takes place automatically after downloading the images to a computer.

The process is fully automatic, only silhouette images have to be created manually. We propose using GIMP to cut out the objects and and fill the background with black. Then, 3DScanner is able to create a mesh in the obj file format.

For further information, please visit the project website.

OpenGL with GLUT

August 2nd, 2008 | Posted by Jay in Computing - (0 Comments)

For I have only found few explanations about how to use the GLUT library for OpenGL programming with Visual Studio 2008, I’ll give it a try myself:

  1. Download the GLUT library from
  2. Unzip it
  3. glut.h – needs to be copied to the include/gl directory within the Microsoft SDK installation dir.
  4. glut32.lib – at the same place, but in the lib subdir
  5. glut32.dll – put this in the System32 dir.

Now, in Visual Studio create a new project as console application. Then, open the project properties, go to the Linker tab. Under Object/Library modules add

opengl32.lib glut32.lib glu32.lib

Finally, include <gl\glut.h></gl> in your source and you’re ready to go!

Computer Graphics with L-Systems

July 14th, 2007 | Posted by Jay in Computing - (0 Comments)

lindsystems 300x170 Computer Graphics with L SystemsLindsystems creates computer graphics, especially fractals based on Lindenmayer formal grammars. It can also model quite realistic plant growth.