Mobile earthquake screensaver for your Sony-Ericsson

June 2nd, 2008

Inspired by the recent earthquake on Iceland measuring 6.1 on Richters Scale (and possibly the 7.9′er in Kina) I decided to create my own earthquake screensaver for my Sony Ericsson 810i.

For those of you interessted in seismic activity in and around Norway feel free to download the source or binaries here.

Binaries:
http://www.labraaten.com/wpblog/wp-content/2008/06/EarthQuake.jad

Source:
EarthQuake.java
EarthQuakeCanvas.java

- Petter

Avoid those unnecessary for-loops…

April 4th, 2008

One thing that makes my - and others - code look ugly are all those for-loops repeatedly embedded into the code.

A typical example ias converting a string of comma seperated numbers into an array of integers. Here’s how to do it in one statement, without any loop:

Dim str As String = "1,2,3,4,5"
Dim ints As Integer() = Array.ConvertAll(Of String, Integer)(str.Split(","), _
    AddressOf Convert.ToInt32)
- petter


How can I access a protected member from a derived class?

April 1st, 2008

First I encountered the error message:

Compiler Error CS1540: Cannot access protected member 'member' via a qualifier
of type 'type1'; the qualifier must be of type 'type2' (or derived from it).

Then I encountered Eric Lipperts explanation of Why Can’t I Access A Protected Member From A Derived Class?

Then I got angry. Read the rest of this entry »

Canine anti-piracy… anti-bug unit…

March 4th, 2008

If they can find pirated DVDs, then it’s just a matter of time before they can sniff up buggy, copy&paste code…

http://news.bbc.co.uk/1/hi/northern_ireland/7275060.stm

- petter

Software development

March 1st, 2008

Here’s a beatuful illustration of how software development works. It may seem like a joke, but it’s actually quite accurate.

software-development.jpg

- petter

A Generic C# 3.0 Collection Initialization Adapter

February 29th, 2008

C# 3.0 comes with this new language feature called Collection Initializaton. It’s more or less syntactical sugar that simplifies the way you initialize collections.

Where you pre 3.0 would initialize a list of integers like this:

List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);

You now can do this:

List<int> list = new List<int>() {1, 2, 3};

Now, this is somewhat beautified, but it does exactly the same as in the first example. The compiler parses the code and calls the Add method, implemented by List<int>, once for every integer in the initialization list.

Now, wouldn’t this be nice to do on your own proprietary collections? Read the rest of this entry »

Mimic the C# yield instruction in VC++

November 29th, 2007

Recently mickey0 posted a question on the CodeGuru forum, asking whether VC++ had any syntax similar to the C# yield instruction. Although I knew the answer was ‘no’, I was still intrigued to figure out if it was possible to implement something similar.

I started with a web search and found a couple of existing implementations, all of which were using Win32 Fibers, so I realized that fibers was the way to go. Even though the examples I found was good tutorials on fibers, they did not meet my requirements on a proper yield implementation. So I had to get dirty. Read the rest of this entry »

Static predicates, delegate inference and performance

November 24th, 2007

C# 2.0 introduced a feature called delegate inference. Delegate inference is an simplification of how you initialize delegates.

Where you prior to C# 2.0 would have to write:

MyDelegate d = new MyDelegate(MyFunction);

You can now simply write:

MyDelegate d = MyFunction;

The two lines of code behaves exactly the same. They construct a new instance of MyDelegate passing MyFunction as argument to the constructor, and then assign the instance to the variable d.

As the name ‘delegate inference’ suggests, the compiler fills in the ‘missing parts’ using inference, leaving the developer with less keystrokes and more readable code. Which is a good thing. Read the rest of this entry »

The bad thing about String.IsNullOrEmpty…

November 8th, 2007

…is that it makes me wonder why they didn’t throw in Array.IsNullOrEmpty as well.

-petter

’Almost real’ functor objects in C#

October 27th, 2007

In these days of delegates, anonymous methods and lambda expressions, I’ve found it necessary to talk about good old functor objects. A functor is an object, that in some fashion you can treat as a function. Put another way, a functor is an object that you can call. Read the rest of this entry »

Powered by WordPress. Entries (RSS) and Comments (RSS).