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

Author Archives: Jay

NetBeans on Windows 7 x64

August 18th, 2011 | Posted by Jay in Software - (2 Comments)

NetBeans 7 has a problem under Windows 7 x64. When trying to start it, it only says:

JVM creation failed.

Just adding “-J-Xmx256m” to the netbeans_default_options, and thus not relying on the default value, solves the problem.

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

Java Servlet & JSP Form-based File Upload

October 30th, 2010 | Posted by Jay in Computing - (0 Comments)

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.

NetBeans Platform Certified Training

May 19th, 2010 | Posted by Jay in Computing - (0 Comments)

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.

GRE® POWERPREP with Windows 7 Pro

October 11th, 2009 | Posted by Jay in Software - (4 Comments)

Everybody who finds himself in the situation that he or she has to take the GRE General Test will receive a CD with the GRE® POWERPREP software from ETS a few days after registering for the test. Alternatively, the software can be downloaded from the ETS website.

However, it only works with Windows OS up to XP. With Vista users experienced a lot of trouble trying to install POWERPREP, but using the compatibility mode they were able to start and use the test prep material. Nevertheless, using Windows 7 I could not accomplish to get it startet, even with the compatibility mode: the window just flickered and nothing else happened.

A possible solution for those, who do not want to install Windows XP on a separate partition, is the new Windows 7 XP mode. The XP mode offers the capability to run a Windows XP environment from your Windows 7 desktop. It therefore requires a processor with the Intel® Virtualization Technology or AMD-V™ turned on and Windows 7 Professional or higher. The Intel® Processor Spec Finder helps to find out whether your (Intel) CPU meets these requirement.

If so, you can download Virtual PC and the XP mode installer. After the installation a reboot is required. Within the XP mode POWERPREP installs and runs smoothly.

GRE® POWERPREP and GRE® General Test are registered trademarks of Educational Testing Service (ETS). This website is not endorsed or approved by ETS.

WordPress, and Server Error 500

March 30th, 2009 | Posted by Jay in Software - (12 Comments)

blue m WordPress, and Server Error 500Like others, whose webhoster is 1and1 and who use WordPress, I experienced a lot of problems with some very popular plugins, such as qTranslate or NextGen.
After activating the plugin, an

Internal server error 500

occured whilst using the admin panel, even preventing me from deactivating the plugin. In this case, there’s only one option left: connect via FTP to your webserver, change directory to your WordPress root, and in wp-conten/plugins rename the plugin directory. This way, WordPress won’t find it anymore and will deactivate the plugin automatically.

But, of course, there has to be a workaround, instead of simply not using certain plugins. The following activates PHP5 on your webspace and worked out perfectly for me:

  1. Open (or create) a .htaccess file in your WordPress root.
  2. Add these lines:
    Options All -Indexes
    AddType x-mapp-php5 .php
    AddHandler x-mapp-php5 .php

ISTQB Certified Tester – Foundation Level

February 23rd, 2009 | Posted by Jay in Computing - (56 Comments)

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.