My name is Juri Strumpflohner and this is my technical blog. I'm a software architect, .Net, Android, Web and Java dev, TDD and best practices promoter and martial arts practitioner.

Recent Posts Subscribe

Dear reader of Juri's TechBlog,
I moved my blog to a new domain and a new hosting solution as well. I'm now blogging on juristr.com.

Webclip: jQuery Intellisense in VS 2008 - ScottGu's Blog

I came across jQuery on the web already several times, but I never took a deep look at it. Now some days ago,  Scott Guthrie posted some steps on his blog that show you how to add Intellisense support jo jQuery inside Visual Studio (and also the Express Editions). So take a look at it, it's quite interesting...

That was the outcome of my try, in just 3 minute it was working:
Here's a related link to Peter's blog where he points out "how to set the focus to the username textbox of asp:LoginView ".

Webclip: Mashups, geocoding with Google Spreadsheets (and Gadgets)

Amazing how people exploit different technologies to achieve their goals and still more amazing how much things you can do combining those freely available services:

C++ linking libraries to build configuration in Eclipse

When programming in C++ you may often have to link at compile time to 3rd-party libraries which you're using.
In Eclipse you can do that on the project properties dialog, as demonstrated in the screenshot below.

C++ experiences

Most of the courses I attended during my Bachelor were Java oriented with some C#, C and Haskell programming. C++ never got really touched, and if, then just to illustrate some theoretical stuff, meaning some C++ code was used to describe a design pattern etc..Well in the Software Engineering Project course we covered C++ pointers, references and how the stack and heap gets managed, but again, just theory. So you always hear about how hard it is to program C++, how awkward pointer management and memory allocation and deallocation is.
Now for the Master course "Data Mining and Data Warehousing" we really have to get in touch with C++. The task of my group is to develop a spectral clustering algorithm and to integrate it into a system called XVDM (developed by the DIS Centre at the Free University of Bolzano). We already presented the first prototype where the different clusters are just printed on the command line. Now after starting with the real integration into the big system (XVDM) we faced quite a lot of difficulties and then you really get a feeling of all this theoretical stuff. So for instance the integration seemed to work well on my collegues Debian installation (running inside a virtual machine on top of windows) but the SAME code produced a segmentation fault on my Ubuntu machine (installed natively).
Using "valgrind" helped to identify the problem (thanks to Prof. Arturas Mazeika for this hint). It allows you to start your program similar as the following

valgrind ./SpectralClustering < ./data.csv
where "data.csv" contains the data to be clustered which is passed via redirection to our program. Valgrind then outputs the memory leaks and what may even be more important, the un-initialized - but used - variables which actually was the problem in our case. It turned out that our module integrated into the XVDM system did not initalize it in the right order meaning we had something like
init glut
create cluster objects
create DBScenery object

DBScenery->addAlgorithm(clustering)

initOpenGL()
(this is just some sort of pseudocode). The problem was that the addAlgorithm(...) method made use of variables which got instantiated inside the initOpenGL() call which then of course produced a segmentation fault. That seems to be clear, but how was the program then able to run on my colleagues machine, making use of a not yet instantiated variable?? I don't know..

Anyway, the clustering integration works now as you can see :)
 
I suppose we have to tune it now, in order to be able to process much larger datasets.

Bought a new iPhone

Yes I got also caught by the iPhone fever :). I'm right now writing this post using the iPhone:)
It will need some time till i get accustomed to it but its functionalities are really amazing and browsing the web is really great, nearly like on a normal browser (well actually it uses a Safari implementation)
Cool...lets see how it's going on, till now I'm convinced :D

JFace Table API with Eclipse RCP

Today I had to create a new view inside on an Eclipse RCP application representing data inside a table. I found the following article

which you may be interested in. It perfectly illustrates everything you need for creating a table with clear code examples.

Haskell type conversions: converting a String to Int

Today I just finished my battle-ship game written completely in functional programming (using Haskell). In order to have the user interact with your game you clearly have to write and read from the command-line. Writing is easy, just do something like

putStrLn "Hello there!"
to print an entire line which would correspond to something like System.out.println("Hello there!") in Java or
putStr "Hello"
to just print the string (in Java: System.out.print("Hello")).
When reading from the keyboard you have functions like getChar for reading a single character or getLine to read the whole line (user has to press the return key to submit). The problem however is that in the first case (getChar) you get a Char datatype and in the second case you get a String. In order to do computations however (as in the case of my battleship game), you need to convert them into a numerical format. Now if you're a Haskell hacker, you'll probably laugh about that, but as a newbie I initially had to search for quite a bit in order to find the appropriate functions.
So my colleague Matthias found a function called digitToInt which basically converts a Char into an Int type.
import Char

getInt :: Char -> Int
getInt x = digitToInt x
Loading this into your Haskell interpreter (I'm using ghc, ghci) and calling the function will return the following:
*Main> getInt '3'
3
This works perfectly until you have just a single digit, i.e. numbers from 0 to 9, but what if the user types in 12?? It won't work because it is no more a single char, but would already be a String. So it was not usable for my battleship game since the board of my game may be of variable length (i.e. the internal matrix representation of the board may be of size 15x15). Moreover using getChar for reading from the input turned out to be not that suitable.
So after searching for a bit I found out that you can use the "read" function defined in the Prelude for doing type conversions. The following commands (directly typed in the Haskell interpreter) return for instance these results:
Prelude> read "4"::Int
4
Prelude> read "34"::Int
34
That was perfectly what I've been searching for. It takes a String and converts it into an Int. And you could even do the following
Prelude> read "4"::Int
4
Prelude> read "34"::Int
34

Persisting the current perspective state of an RCP

If you're developing on Eclipse RCP applications it may be interesting to save the perspective layout and open views of the user s.t. when he launches the application the next time, everything looks as before. That may sound difficult but actually it is really simple.
In your ApplicationWorkbenchAdvisor.java, in the initialize(IWorkbenchConfigurer) just write the following:

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
   ...

   @Override
   public void initialize(IWorkbenchConfigurer configurer) {
      super.initialize(configurer);
      configurer.setSaveAndRestore(true);
      ...
   }

   ...
}
This should work fine. In case it doesn't, try to get the WorkbenchConfigurer by calling the method getWorkbenchConfigurer() and invoke the setSaveAndRestore(...) on that.

Creating "soft-links" to folders on Linux

If you're working on Linux, especially on the command line, you'll often have to navigate through a lot of directories. This clearly depends on your directory structure, but it may be the case. That's however really annoying, so creating a link may easy your life:

ln -s <fileonharddisk> <name>

(Thanks to Matthias Braunhofer)

HowTo: execute a file download from Windows command line

Under Linux it is often very comfortable to download files quickly from within the shell by typing wget [some URL], especially if you do that from within a script. Under Windows this is not directly possible since there doesn't exist a wget-like program (at least I didn't find one). I guess if you install cygwin, then it may be possible to use wget again, I'd have to check that. Anyway, if you don't want to install cygwin and you have installed ServicePack2 (Win XP), then there is an application called "BitsAdmin" which allows you do to a similar job. The application usually comes under the Support Tools of the ServicePack 2.
Usage:

<installLocation>\bitsadmin.exe /transfer <jobName> /download /priority normal <url to file to download> <path where downloaded file should be stored>
So an example could look as follows:
C:\SupportTools\bitsadmin.exe /transfer chromiumUpdate /download /priority normal http://build.chromium.org/buildbot/continuous/LATEST/chrome-win32.zip C:\chromium\chomiumLatest.zip
This downloads a zip-file containing the latest Chromium build (What's the difference between Chromium and Chrome?).

References:
http://msdn.microsoft.com/en-us/library/aa362813.aspx
http://msdn.microsoft.com/en-us/library/aa362812(VS.85).aspx

The type X is not accessible due to restriction on the...

For some university course we currently have to modify an Open Source application with LOC > 50,000. So due to our particular interest in Eclipse RCP development, our team has chosen the RSSOwl, a smart Newsfeed reader which is based on Eclipse RCP (you should check it out).
After downloading the latest source from the code repository, the build seemed to be broken since it reported about 18 errors saying something like:

The type [X] is not accessible due to restriction on required library [Y].
...where [X] and [Y] are of course placeholders for the class and jar library :) . After some (actually long) search on the web, one of my collegues found the "solution" for the problem. It was actually a wrong Eclipse configuration of the Java compiler. What has to be done is to set the "Forbidden reference (access rules)" under the "Deprecated and restricted API" from "Error" to "Warning".

In this way Eclipse will treat the problem as a warning instead of an error. I discussed that configuration with the RSSOwl author and he affirmed me that it is fine to have the configuration set to "warning".

Strange focus behavior on Firefox 3+

Apparently it seems as if Firefox has changed the way the focus is set on the page starting with version 3+.
When using the <yourcontrol>.Focus() method on Asp.net the current behavior is that Firefox automatically scrolls the page till the "focused" element is in the very last row of the screen. This is really nerving, especially if you're using Asp.net Ajax UpdatePanels. In that case you have that as soon as the asynchronous postback caused by the UpdatePanel returns, your page starts to jump around (if on the server-side you set the focus on some control).
I used the following piece of code inside some Helper class to solve the problem. The idea is basically to use the ScriptManager to register a JavaScript which is launched as soon as the postback comes back to the client.

public static void SetFocusByJavaScript(Page page, Control targetControl)
{
    SetFocusByJavaScript(page, targetControl.ClientID);
}

public static void SetFocusByJavaScript(Page page, string clientID)
{
    string uniqueScriptId = String.Concat("focusScript", clientID);
    string scriptBody = String.Format("setTimeout(\"$get('{0}').focus();\", 100);", clientID);
    ScriptManager.RegisterStartupScript(page, page.GetType(), uniqueScriptId, scriptBody, true);
}
By the way this would be a nice candidate for writing an extender method on the control class...Should be realizable in an easy way.

Verifying command line parameters on C++ main method

Just a very quick example on how to verify the correct number of command-line parameters on a C++ (or C) main method:

int main(int argc, char **argv) {
    if(argc < 3){
       ...
       //give some useful information to the user, i.e. the number
       //of required parameters and maybe also a short example
       ...
       //stop the execution of the program
       return EXIT_FAILURE;
    }
}
The checking of the correct number of parameters is done with the "argc" parameter of the main method, while the actual reading is done by using the argv parameter, i.e. argv[1] for the 1st parameter.
Hint: the input is given as array of char arrays: char**. char* = array of characters = string, so conversion to a string type is straightforward:
string myString = argv[1]