Skip to main content

Posts

Showing posts from October, 2009

Shuffle part of a List

The amazing game the Cornball is about to be ported to C#.NET. A project which is a lot easier than expected. The number of hours I put down so far is barely hitting two digits and still I have reached a playable alpha version. The source will be published in parts or in its entirety when I am finished, but until then there is one small problem I would like to show that required some extra thought. The class structure consists of Card and Deck, which inherits List<Card>. Deck has a Shuffle method which utilizes the Fisher-Yates  algorithm. public void Shuffle() { Random random = new Random(); for(int i = Count - 1; i >= 0; i--) { Swap(random.Next(i), i); } } internal void Swap(int fromIndex, int toIndex) { Card temp = this[fromIndex]; this[fromIndex] = this[toIndex]; this[toIndex] = temp; } In the middle of the game, only a part of the game should be re-shuffled, which renders this method useless. Long story short, I came up with the

SNMP in C#.NET

One of our applications is going to send network status messages using  SNMP . This is nothing we have done before and seems like a fairly extensive project. That is why I was very happy to find  #SNMP Library on  CodePlex . Thank you  Microsoft  for this magnificent open source community, and of course a big thank you to all the contributors! I have not contributed to anything yet, but I feel a sudden urge to do so. Now there are only some specifications and a little development before we can name ourselves SNMP experts. I will post some code as soon as I have something to show. Until then all I can do is to recommend the samples included in  #SNMP .

Nostalgia in Win32 API

I started my programming career by modifying a guestbook written i Perl for one of my first web sites. When I took the step into the Windows platform the natural choice was the Win32 API and C. In my early teens I managed to create a couple of really interesting applications. When Google recently found a  web site  from 1999 for one of these applications I had to take a trip down the memory lane. I have now found two amazing application, written by me in my teens, which even seem to work pretty good on todays operating systems, including a 64-bit Windows 7. The applications are developed and tested for Windows 95/98 so there are no guarantee for the function on other platforms. What I can guarantee is that the applications are 100% free from any malware or other bad stuff. Text  is a revolutionary text editor focused on fancy word proceccing functions instead of unnecessary eye candy. The Cornball  is a solitaire game where the goal is to put the cards in order from 2 to King. E

Elevated Privileges Application Launcher

At a number of times we have had requests to be able to run applications as a normal user even though the application is designed to run as an administrator. This could be handled manually by setting the privileges on each computer for certain paths and registry keys and any other resources the application requires. This easily gets out of hand and there is a much better solution, spelled  EPAL . Sure, it requires some configuration and tweaking, but when set up it works like a charm and is a great tool to compensate for poorly written Windows applications requiring administrative privileges.

GETDATE() and DST in SQL Server Compact

We have had issues when synchronizing date and time in some handheld Windows CE devices. Time always seem to get an hour wrong and we have already confirmed that it has to do with Daylight Savings Time. But we have not figured out what and why until just recently. In some cases we have used the SQL method  GETDATE() , in other cases  DateTime.Now() . The case where the latter is used there are never any issues, but with  GETDATE() we get the one hour difference most of the time. This is simply caused by the settings and configuration in the handheld device and SQL Server Compact. A proper solution would be always to use  UTC -date in the application and the database to get rid of such problems. But since that would be a major change we decided to just go with using DateTime.Now()  instead of GETDATE() .