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.

Will Microsoft's Bing become Google's biggest threat?

Microsoft Live Search release wasn't a big success to compete Google on the search engine market. Now they're about to release Bing which is isn't thought to be another "search" engine, but a "decision" engine, as they call it.
Till now there is just a preview video explaining Bing's features, but on June 3 it will apparently replace Live search as Microsoft's new default engine. Google's success is mainly their extremely fast and mainly accurate search. Another point is the simplicity and clean layout. You just have this small search box and then the list of results without a lot of noise around, even the advertisement isn't that disturbing. This makes it much more usable.

It will be interesting to see the competition between this two engines. Google's share is impressing, if you just take the searches that reach my site which is mainly or just visited by developers. Obviously I have only a small share, but still, having an average visitor number of about 100 per day and if I take all the visits from search engines between 01/01/2007 to now I get the following distribution of search engines:


Let's see whether this will change ;)

HowTo: Keep request parameters on validation errors with Spring's SimpleFormController

I recently had a problem when using Spring's SimpleFormController together with validation. So I posted on StackOverflow, got an answer, that didn't work out so I found a solution and answered to myself :)

Since redundancy is bad, here's the link to my post:

HowTo: Get localized string different from the current culture

Localization is a key part of most applications. For this purpose you usually use resource files (property files in Java, actually they are the same) with the according culture extension, like "MyResources.resx" for the default language, "MyResources.de.resx" for German etc...
You can then access your resources by using "GetLocalResourceObject(...)" for resources related to your current UserControl or Webpage/Form or "GetGlobalResourceObject(...)" for resources that are global to your application (App_GobalResources folder) and you'll automatically get the localized object in the current thread culture.

Often however you may have the case where you want to retrieve a resource object in a different culture than the current one. This can be achieve as follows (example for the german culture):

CultureInfo info = CultureInfo.CreateSpecificCulture("de-De");
string localizedString = Properties.Resources.ResourceManager.GetString("BackText", info);

What happens if you think in Java and program C#

I'm quite jumping between the two languages. In the morning at the university I'm usually programming Java and then in the afternoon at work I'm programming in C#.net. This can be quite interesting and also be an advantage to have this kind of view to both of the languages (and also the according expertise). My personal opinion is that usually good programmers emerge from the Java world since I find it highly educational.
Anyway, having this kind of view however, you often then come across funny things you coded such as the following :)

I just needed a way for reading in an image as a byte[]. As a Java programmer, hearing byte[], you would immediately think of some stream etc...and so the following came out:

private byte[] ConvertImageToByte(Image toConvert, ImageFormat format)
{
    byte[] result;

    using (MemoryStream ms = new MemoryStream())
    {
        toConvert.Save(ms, format);
        result = ms.ToArray();
    }

    if (result.Length == 0)
        result = null;

    return result;
}
Well encapsulated and it worked perfectly but the solution could have been so simple ;)
byte[] imageData = File.ReadAllBytes(tifFilePath);

Use Google Scholar and Latex for correctly citing papers

Citing papers is somewhat critical. There are predefined styles that have/should be respected. But it can be really easy. With Latex you can define a kind of "references file" having the ".bib" extension. Then you define your citations in it, like

@article{talby2006ast,
  title={{Agile software testing in a large-scale project}},
  author={Talby, D. and Keren, A. and Hazzan, O. and Dubinsky, Y.},
  journal={IEEE software},
  volume={23},
  number={4},
  pages={30--37},
  year={2006},
  publisher={Institute of Electrical and Electronics Engineers, Inc, 445 Hoes Ln, Piscataway, NJ, 08854-1331, USA,}
}
In your main document Latex file, where you want your references to appear (usually at the end of the document), you put the following
\bibliographystyle{plain}
\bibliography{references}
where "references" is the name of your .bib file. When you then place a cite in your document like \cite{talby2006ast}the corresponding citation will automatically appear in your references section.
 
But the cool stuff is that you don't have to necessarily write the bib file yourself. You can go to Google Scholar and get the BibTex entry from there. First however you have to activate the according option in the preferences
 
Then you will see an entry called "Import into BibTex"
This is really comfortable and saves you some work :) and moreover you don't have to worry about correct citing.

JsTestDriver - Easy unit testing for JavaScript code

Today this video got my attention which is basically a short demo of JsTestDriver, a nice implementation of easy unit testing for JavaScript code. This allows to easily create automated test for multiple browsers. Really nice implementation, I have to try it out once I've time.

The Google Testing Blog writes more about it.



Update:
Here's a post on the Google Testing blog.

Update (19.11.2009):

Help, my MSTest DeploymentItem doesn't get deployed!

MSTests allow you to define items you'd like to deploy to the deployment directory when executing the test cases. There are different ways for achieving this, either to configure it in your LocalTestRun.testrunconfig or to add attributes to your test case like

[TestMethod]
[DeploymentItem(@"files\somefolder\", "optionalOutputFolder")]
[DeploymentItem(@"files\someOtherFolder\", "againAnOptionalOutputFolder")]
public void MyDummyTest()
{
   ...
}
What may happen though is that despite defining this attribute, your files won't get copied to the deployment. If that's the case you have to make sure that you set the "Copy to Output Folder" setting to "Copy Always". This is kind of strange since by defining the DeploymentItem attribute one would imagine to have it already copied automatically. A bit of a messy implementation...

My new MacBook Pro

It arrived! My new MacBook Pro :)

String enumerations in C#

Enumerations are a very handy programming construct. Especially when you're developing in a larger team, you can prevent a lot of problems and possible bugs by using enum types for properties that can just have certain values. Take for instance a class property "Status". It could have several different values: just "open" and "closed" or "O" and "C" or "M" for modified and "C" for complete etc...If another developer in the team is using your class he always will have to directly go to your class in order to check the specifications (since also useful intellisense comments are missing ;) ). But if you would use enumerations he can just type and will immediately see a list of possible values. Moreover you prevent stupid bugs such as (if "C" and "M" would be the correct values) that he assigns "c" and "m" where you can sure that at some point in your app there will be a wrong comparison.

The problem however in C# is that you cannot have string enumerations although often they would be handy. I recently had the case where a possible DB value for a property is "C" for complete and "M" for modified. Furthermore these values have also to be written to a CSV file. Here a string enumeration would be great, wouldn't it? Of course you could argue to just use constant string fields, but that wouldn't be so elegant. So I decided to create one.
I searched on the web and found this solution which I've taken in part and modified to make it a bit more convenient (at least from my point of view). The strategy in this example is to make use of the System.Attribute to enhance standard enumerations.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Jsdevlib.Base
{
    public class StringValueAttribute : System.Attribute
    {
        public StringValueAttribute(string value)
        {
            _Value = value;
        }

        private string _Value;
        public string Value
        {
            get
            {
                return _Value;
            }
        }
    }
}
Then you can create your string enumeration as needed. For instance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jsdevlib.Base;

namespace SimpleTests
{
    public enum StringEnumeration
    {
        [StringValue("C")]
        COMPLETE = 1,

        [StringValue("M")]
        MODIFIED = 2
    }
}
To now retrieve the defined StringValue, the example on CodeProject used an additional utility class. I preferred to slightly change this implementation and to use the C# extension methods:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace Jsdevlib.Base
{
    public static class StringEnumExtender
    {
        public static string StringValue(this Enum value)
        {
            string output = null;
            Type type = value.GetType();

            FieldInfo fi = type.GetField(value.ToString());
            StringValueAttribute[] attrs =
               fi.GetCustomAttributes(typeof(StringValueAttribute),
                                       false) as StringValueAttribute[];
            if (attrs.Length > 0)
            {
                output = attrs[0].Value;
            }
            else
            {
                throw new InvalidOperationException("The StringValue can just be invoked on String enumerations having the '[StringValue(...)]' attribute.");
            }

            return output;
        }
    }
}
To retrieve the string value you can do now something like
StringEnumeration.COMPLETE.StringValue();
But pay attention that you have to first import the namespace in which you have definde your StringEnumExtender, because otherwise you won't see the StringValue() method. That's the drawback of extension methods.
This kind of mechanism gives you great flexibility since you can add the StringValue attribute to whatever enumeration. Btw, invoking the StringValue() on enumerations that don't define a StringValue attribute an exception will be thrown. I found that the most reasonable behavior.

Intel ProSet Wireless tool causing a lot of trouble

Years ago I installed the Intel ProSet Wireless tool for managing my wireless network connections on my HP Compaq. Initially it worked quite well, but then updating it several times introduced a couple of bugs such as delaying the windows startup time because a related service waited till a certain timeout for proceeding etc...really annoying. But disabling the tool for switching back to the Windows integrated wireless management didn't work, since starting the "Wireless Zero Configuration" service always gave me the following error message:

Could not start the wireless zero configuration service on local computer.
Error1068: The dependency service or group failed to start.
After a long fight I now resolved the issue. In the Windows registry one has to go to \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Ndisuio and change the value of the "Start" setting from 4 to 2. Then reboot Windows and the Wireless Zero Configuration service should start without any problems, allowing to again use the Windows utility for configuring the wireless networks.
(this has been tested on Windows XP Prof. Service Pack 2)

Debugging and Testing the Web with Firebug

Comment
Rob Cambell, member of the Firebug working group gives a talk about Firebug, its history and a short intro to the newest features in the latest version and how to use them.

Duration
39 min

HowTo: Make your custom ASP.net server control validatable

Content validation is a major issue of every application. It is an absolute "must have" to notify the user about invalid data he may have entered. Asp.net provides nice validators which you can drag onto your page and attach to a specific control by defining the ControlToValidate attribute of the validator.

So if you design your custom server control you would like to make it also validatable. Many approaches I've seen on the web is to directly integrate the validators in the custom server control and so to provide predefined validation functions. This can be useful in special cases s.t. the programmer/user of the server control doesn't have to bother about validation (i.e. create a custom control "AutoValidateTextBox").
A much cleaner approach however is to decouple validation from the implementation of the server control. This increases the flexibility for the user of the control in the way that he possibly can specify whatever validator he likes (if not generate and attach validators automatically). But if you just add your control to a page or user control and you add a validator, you'll get an error like:

Control "YourCustomControl" referenced by the ControlToValidate property of "theAddedValidator" cannot be validated.

To avoid this problem and to make your control validatable, you have to tell somehow which property exposed by your control is the one that should be validated. This can be done by specifying the following attribute on your server control's class:
[ValidationProperty("Value")]
public class MyCustomServerControl : WebControl, INamingContainer
{

   ...


   //the property that will be validated
   public String Value
   {
      get
      {
         ...
      }
      set
      {
         ...
      }
   }

   ...

}

Dropbox - Sharing, synching and backup has never been so easy

I wanted to write this post already for a longer time, actually I had it (between my other approx. 30 not yet finished posts) in the draft folder. Anyway :)

What is Dropbox?
With easy words, it is a tool that allows you to synchronize, backup as well as share your files and photos over the internet. And it's really easy. All you have to do is to sign up for an account and download the Dropbox program. It will run in the background, synchronizing a certain folder (which obviously you can specify) from your hard disk to your online account. On another computer (e.g. at home) you repeat this and voila, all of your files will be synched by Dropbox.


You work always on the same computer and so synching with Dropbox is useless?
I don't think so. Dropbox does not just simply synchronize your files, but it does also a great job in backing them up. Every modification on your files which are managed by Dropbox are automatically under version control. What does this mean: You can always revert to a previous version of your file. Take the following: you write on a document, on a report or something, directly in the folder which is synched by Dropbox. After some time you recognize that you've overwritten parts of the text assuming to make it better, but at the end you see that still the old one would have been better. Now, "undo" may not work any more since the modifcations may have been days ago and you obviously don't have any backups :) Your lucky, Dropbox did it for you. What you have to do is to just go to the main Dropbox website, log in and navigate to your file on the web interface. There you click on "Revisions" and you will see all of the versions of your file. you can simply click restore to and you will have the previous version again on your file system.


And the greatest thing, you can even restore deleted files.

This can also be quite interesting for software developers. Most of us use version control systems (SVN, CVS, TFS,...) for tracking the source code versions and for also having a continuous backup. I'm versioning quite all of my code because there are just a number of advantages I don't want to miss. However for small experiments or projects, setting up a repository is often quite tedious. So what I do now is to just put my Visual Studio solution or Eclipse workbench directly into the folder managed by dropbox. In this way my files are automatically versioned and I don't have to set up anything.
But attention, this works great if you work alone on a project, if you're a group, it's still better to set up the normal version control system :)

Why is Dropbox so great?
Because it's so easy to use and it's free! You have just to register for an account and install the application on your computer. Then you can just work normally as you always did on your Windows Explorer, on Linux and even on MacOS X.


Do you want an account?
Dropbox is out of beta and is now open to everyone. But still, if you want to join, I ask you to just leave a comment with your email (don't write it totally, but use some replacements such as [at] for @ in order to not be catched by spammers) below and I'll send you an invitation. We will both have the advantage of getting extra storage space on Dropbox :)