Tigraine

Daniel Hoelbling-Inzko talks about programming

The deprecated target attribute and jQuery

It's usually not considered polite to open new windows whenever somebody clicks one of your external links. Those back and forward buttons are there for a reason, so I strongly encourage people to avoid opening new windows.

But, we all know customers. They get this "but I want this" look the second they discover that users may leave their web site too early (can't say how much this attitude sucks..).

One popular way to do this is to use jQuery to open all external links on your page in a popup (making code that obviously violates the "don't open new windows" rule still validate).

$(document).ready(function() {
    $("a[rel='external']").click(function(event) {
        window.open($(this).attr("href"));
        event.preventDefault();
    });
});

Now all you have to do is, add a rel="external" attribute to all outgoing links, and this little jQuery function will take care of making them popup.

Still, this is bad. It contradicts the whole idea why they removed the target attribute in the first place, so consider this as a quick'n'dirty hack to satisfy stupid customers.

Anatomy of a pattern: Singleton

Singleton is one of the simplest patterns that does just one thing: Ensure that there is one object to rule them all, one object to bind... (Ok sorry got dragged away).

The idea is simple: Sometimes (especially when writing to disk with open file handles) you need to ensure that there is only ONE instance of a class going on at any time. And that's it. It's so simple, you could turn it into a 1-liner:

public static Singleton _Instance;

But things never are that simple ;). By using only a shared variable you may end up calling the constructor twice, resulting in 2 objects that may get used by two different clients.

To avoid this you'll need to get an exclusive lock of the Singleton to ensure it's really empty before you instance it.
And that's how it's usually done

private static Singleton _Instance;
private static Object __LockObject = new object();

public static Singleton GetInstance() {     if (_Instance == null)     {         lock(__LockObject)         {             if (_Instance == null)                 _Instance = new Singleton();         }     }     return _Instance; }

In the singleton implementation the static Singleton variable holds the reference to the Singleton, and whenever we try to get a reference to this instance we check if it's already set and return the value.

If not, it get's tricky when 2 threads are getting a cache-miss at the exact same time (_Instance == null). If you aren't synchronizing at this point you may end up with two different references of a singleton object being used (and causing problems with resources being consumed twice, causing ). So it's important to perform another check when you have exclusive reign over the shared object (by using a lock object here).


This ensures that no two threads will try to create a new instance to your singleton, while not slowing down your read-performance at all.

Sample code: Singleton.cs

Useful tools: Windows Installer Clean Up

Although we all love the Windows Installer, sometimes it can give you a really hard time when it breaks (it does rarely, but it does).

That's the time when you need the Windows Installer Clean Up tool that will remove all install related information from your database so you can start over with the install.

I strongly advice not to use this tool for software that's properly installed. You'll have to clean registry/filesystem by hand if you delete the installer information. It's only really helpful to remove stuff you may have already deleted on the filesystem or to recover from a broken install.

You can download the Windows Installer Clean Up here, make sure to run it as administrator (Vista won't prompt you, it will just fail).

Filed under tools

What I like about Windows Vista: Sound Mixer

Welcome to my new (almost) infinite series about Windows Vista. The much hated, tiny little operating system Microsoft has released over a year ago and everybody loves to criticize.

So, what's in for a first post? Something not everybody is aware of: The new sound mixer with the new API behind it.

image

In the dark days before Microsoft's new shiny OS, applications output volume was determined by the master volume control in Windows. This has led to almost all applications having some sort of volume control built in to let users fine tune their experience.

Some examples:

Windows Media Player World of Warcraft
image image

Etc.. So everyone is searching for the right knobs to turn inside the application when it comes to sound.

Something, Vista has changed drastically, because now all applications have their own volume slider and you can control all of those (and tune them relative to each other) through the Windows Sound Mixer (available through the normal sound control in your system tray).

So, next time you do something with sound, make sure you don't try to access the master volume settings through the API but instead your settings. Here's a good article on how to do that: Vista Core Audio API Master Volume Control

Filed under windows-vista

AnkhSVN 2.0 Subversion client for Visual Studio

I complained before that Visual Studio has no built in support for Subversion, as SVN is currently one of the most common source control choices for open source projects.

One commenter pointed me towards AnkhSVN as a source control provider, but I wasn't working on anything involving SVN so I didn't install AnkhSVN right away - I should have done!

AnkhSVN 2.0 is exactly what I was looking for!
I installed it and it integrated itself very nicely with Visual Studio. Not acting as a AddIn but as a source control provider similar to Visual Source Safe.

image

So it hooks itself into your solution explorer, showing you the file status within Visual Studio

You can open projects directly from Subversion, and the Pending Changes window helps in keeping track of what changes need to be committed to the SVN (never forget to commit your .csproj file after adding files to your project ;)).

Overall, AnkhSVN works very well and the UI is clean and does what you'd expect from your Subversion client, and it's good integration into Visual Studio helps. No more exception list hacking for file-based clients like Tortoise SVN.

As with most open source software, AnkhSVN is still work in progress, and I've already found some bugs. But if this project continues to evolve I think we have a really powerful tool at our hands!

So, if you want to try it for yourself (strongly suggested), go and grab the latest release (I suggest installing the daily build) from the AnkhSVN project site.
If you find any bugs while using the tool, please make sure to tell the developers. Their issue tracker sucks, you'll need to register and request access to the tracker (but they are pretty fast in granting access).

ID injection can be stopped!

Oh man, I was complaining about it and going nuts on this. But looks like I've found the solution (while having another more annoying problem):

image

See it? That box over there saying: Auto ID elements on paste in Source view? Man, I knew this setting has to be somewhere!

Filed under net, programmierung

My Photography business

Projects

dynamic css for .NET

Archives

more