Wednesday 31 December 2008

Blackberry 8800 video encoding - How to

Download this free encoder: http://www.erightsoft.com/SUPER.html
The download link is very hard to find, so its here

Use these settings:
Output container: AVI
Video Codec: DIVX
Audio Codec: mp3
Encoder: MEncoder

Video settings
Size: 320:176
Aspect: 16:9
Frame/sec: 12.5 (pal) 14.985 (NTSC)

Audio settings
Sampling freq: 22050
Channels: 2
Bitrate: 64
Audio stream: default

Enjoy!

Friday 19 December 2008

A generic singleton - Part 2

Here is the critique and why there is a better solution to the article: A generic singleton

Well, it isn't really singleton - since you can't control T, there can be as many T instances as you like.

The code does check for non-public constructors, which is good. However, this is a check which is only performed at execution time - there's no compile-time check, which is a strike against it. It also relies on having enough access to call the non-public constructor, which adds some limitations.

In addition, it doesn't prohibit internal constructors - so you can end up with non-singletons.

There is an excellent article on singletons at http://www.yoda.arachsys.com/csharp/singleton.html

Here are two proper implementations:

public sealed class Singleton
{
    static readonly Singleton instance = new Singleton();
 
    // Explicit static constructor to tell C# compiler
    // not to mark type as beforefieldinit
    static Singleton()
    {
    }
 
    Singleton()
    {
    }
 
    public static Singleton Instance
    {
        get { return instance; }
    }
}

Or simply:

public
class Singleton
{
    private static Singleton _instance = new Singleton();
    private Singleton() {}
    public static Singleton Instance { get { return _instance; }}
}

Both of these classes removes the need for locking, as a static constructor is thread safe.

Surprising SQL speed increase - Part 2

Part 1 is availble below

More generally speaking, you should never use a function on the LEFT side of a WHERE clause in a query. If you do, SQL won't use an index--it has to evaluate the function for every row of the table. The goal is to make sure that your where clause is "Sargable"

Some other examples:


Bad: Select ... WHERE isNull(FullName,'') = 'Ed Jones'

Fixed: Select ... WHERE ((FullName = 'Ed Jones') OR (FullName IS NULL))

Bad: Select ... WHERE SUBSTRING(DealerName,4) = 'Ford'

Fixed: Select ... WHERE DealerName Like 'Ford%'

Bad: Select ... WHERE DateDiff(mm,OrderDate,GetDate()) >= 30

Fixed: Select ... WHERE OrderDate < DateAdd(mm,-30,GetDate())


Bad: Select ... WHERE Year(OrderDate) = 2003

Fixed: Select ... WHERE OrderDate >= '2003-1-1' AND OrderDate < '2004-1-1'