Posts

Showing posts from 2008

Blackberry 8800 video encoding - How to

Image
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!

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() { } Si...

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'
The 3 Minute Management Course Lesson 1 A man is getting into the shower just as his wife is finishing up her shower, when the doorbell rings. The wife quickly wraps herself in a towel and runs downstairs. When she opens the door, there stands Bob, the next-door neighbour. Before she says a word, Bob says, "I'll give you £800 to drop that towel." After thinking for a moment, the woman drops her towel and stands naked in front of Bob. After a few seconds, Bob hands her £800 and leaves. The woman wraps back up in the towel and goes back upstairs. When she gets to the bathroom, her husband asks, "Who was that?" "It was Bob the next door neighbour," she replies. "Great!" the husband says, "did he say anything about the £800 he owes me?" Moral of the story: If you share critical information pertaining to credit and risk with your shareholders in time, you may be in a position to prevent avoidable exposure Lesson 2 A priest offered a Nun ...

Surprising SQL speed increase

I’ve just found out that the execution plan performance between the following two select statements are massively different: select * from your_large_table where LEFT(some_string_field, 4) = ' 2505 ' select * from your_large_table where some_string_field like ' 2505% ' The execution plans are 98% and 2% respectively. Bit of a difference in speed then. There are lots of places in our SQL where we use LEFT(something, x) = 'string' This should be replaced by the LIKE command for greater speed. I actually found this out by checking the LINQ generated SQL against my hand crafted SQL. I assumed the LIKE command would be slower, but is in fact much much faster.

A generic singleton

Taken from: http://andyclymer.blogspot.com/2008/02/true-generic-singleton.html Changed by Simon Hughes 20th Feb 2008 using System; using System.Reflection; // Use like this /* public class Highlander : Singleton<Highlander> { private Highlander() { Console.WriteLine("There can be only one..."); } } */ public class Singleton <T> where T : class { private static T instance; private static object initLock = new object (); public static T GetInstance() { if (instance == null ) { CreateInstance(); } return instance; } private static void CreateInstance() { lock (initLock) { if (instance == null ) { Type t = typeof (T); // Ensure there are no public constructors... ConstructorInfo [] ctors = t.GetConstructors(); if (ctors.Length > 0 ) ...

BypassProxyOnLocal - a bug in .Net ?

If you have a local proxy server on your computer (127.0.0.1) that you wish to use when doing FTP communications, all you need do is set BypassProxyOnLocal = false right? There may be many important reasons for using a local proxy, such as caching and security etc. Here's an example: WebProxy proxy = new WebProxy("127.0.0.1", 3128); proxy.BypassProxyOnLocal = true; bool a = proxy.IsBypassed(new Uri("ftp://127.0.0.1:3128")); bool b = proxy.IsBypassed(new Uri("ftp://127.0.0.1:21")); // a=true, b=true (ok) proxy.BypassProxyOnLocal = false; bool c = proxy.IsBypassed(new Uri("ftp://127.0.0.1:3128")); bool d = proxy.IsBypassed(new Uri("ftp://127.0.0.1:21")); // c=true, d=true (???) Why is the proxy being bypassed when I told it not to? The local proxy is always bypassed when when the proxy is on a loopback address. Why? Setting BypassProxyOnLocal to false should NOT bypass the proxy for local addresses. So let's see what MSDN Library ...

Design patterns

I've recently been on a training course with http://www.developmentor.com/ it's called Code Smarter with Design Patterns in .NET and can strongly recommend it. I simply love design patterns, and you should to :-)

GRC.COM by Steve Gibson

https://www.grc.com/ is run by Steve Gibson. He has many great utilities and has a Security Now podcast. I can't recommend them strongly enough. GRC "Perfect Passwords" Generator https://www.grc.com/passwords.htm Spinrite hard disc recovery and maintenance http://www.grc.com/spinrite.htm SecurityNow podcast with Leo Laporte http://www.grc.com/securitynow.htm ShieldsUP! https://www.grc.com/x/ne.dll?bh0bkyd2 SecurAble http://www.grc.com/securable.htm

DHCP Client service causing my PC to go slow

Recently I’ve noticed my laptop going quite slow. For example, using Windows explorer and clicking on a folder resulted in a 40 – 60 second wait for the folder to show its contents. Well, I’ve worked out by stopping the ‘DHCP Client’ service my PC goes like lightening again. I'm also using Windows XP. To fix, you need to delete all Printers that are offline, and remove all mapped network drives. Why does the ‘DHCP Client’ affect windows explorer? I don’t know, but Microsoft if your reading this, please fix it.

What do I use to write software?

I started off with Dbase III, then Borland Turbo C for about 5 years, then when Microsoft Visual Studio v1.0 came out, I moved to that. I've been using Visual Studio ever since. Coding in C++ and have since moved to C# when that came into existance. Do I use component? Yes. Which ones then? Telerik http://www.telerik.com/ Dundas http://www.dundas.com/ Rebex http://www.rebex.net/ I've also used DevExpress reports, but they peg the CPU to 100% on the webservers when exporting an excel spreadsheet with a lot of data in them, and more often than not, cause a timeout on the ASPX page. So I don't like to use them anymore. My essential toolkit consists of: SVN - Subversion source control http://subversion.tigris.org/ Winrar http://www.rarlab.com/ Colour Schemer (web design) http://www.colorschemer.com/online.html SQL Prompt http://www.red-gate.com/ ANTS Profiler http://www.red-gate.com/ NUnit http://www.nunit.org/ Microsoft Visual Studio http://msdn2.microsoft.com/en-gb/vstudio/de...