Archive for March, 2006

SQL performance: Nested select statements.

March 24, 2006 Leave a comment
This is a tip for restructuring nested select statements to make them run faster in SQL server. I can’t vouch for this in all situations, but It shortened a long SQL query for me from 1 hour to 7 minutes.
Where you have
Select * from xyz where id in
   Select * from abc where id in
    select id from def
I recommend re-writing as
   Select * into #abcdef from abc where id in
    select id from def
Select * from xyz where id in
   select id from #abcdef
Categories: Uncategorized

Charset reverting to Windows standard

March 23, 2006 Leave a comment
On Internet eplorer 6 SP1, If you perform a Response.Flush() before any content goes to the page, then the charset will revert to Windows. Regardless if the charset is set in the HTML.
If you put this line in Page_load, it should fix the problem
Response.Charset = "UTF-8";
Categories: Uncategorized

Differences between CHOICE command in Batch files

March 22, 2006 Leave a comment
Batch files may be arcane, but they serve well for quick & nasty build scripts. One point to note that I fell into a trap today is the difference in the implementation of the CHOICE command (prompting the user for input) between Windows 9x and Windows 2000/XP. – Alot of documentation on Batch files is quite old, and thus doesn’t mark any difference
Windows 9x:
CHOICE /C:123 /N Please choose a menu option.
Windows 2000/XP:
set choice=
set /p choice=Please choose a menu option.
if not ‘%choice%’==” set choice=%choice:~0,1%
if ‘%choice%’==’1’ goto LOCAL
if ‘%choice%’==’2’ goto BACKUP
if ‘%choice%’==’3’ goto LIVE
Categories: Uncategorized

Google Toolbar buttons… second attempt

March 19, 2006 Leave a comment
Categories: Uncategorized

Transparent Localisation

March 18, 2006 Leave a comment
I’ve just launched one website, in four different languages all in the same path, with the same files & database under IIS. (english) (german) (french) (Spanish).
How did I do it?

public static string getGetSiteCulture()


string strUrl = System.Web.HttpContext.Current.Request.Url.ToString().ToLower();

string strCulture = "en-GB";

if (strUrl.IndexOf("mensajetexto")!=-1) {strCulture = "es-ES";}

if (strUrl.IndexOf("handyspruche")!=-1) {strCulture = "de-DE";}

if (strUrl.IndexOf("envoyezsms")!=-1){strCulture = "fr-FR";}

return strCulture;



Then I have 4 different Resource files,, strings.en-GB.resx etc.

public static string Translate(string ID)


rmTranslations.IgnoreCase =


string strTranslation ="";

Thread.CurrentThread.CurrentCulture =

new CultureInfo(getGetSiteCulture());

Thread.CurrentThread.CurrentUICulture =

new CultureInfo(getGetSiteCulture());


{strTranslation= rmTranslations.GetString(ID);}


throw new Exception(ID + " not found");


return strTranslation;



Then in place of static text, I put Translations.Translate("Whatever")

Categories: Uncategorized

Parsing Skylights Route information

March 17, 2006 Leave a comment
A company which develops airline websites, known as SkyLights, has a common format for javascript which they place on their webpages to populate two dynamic drop down lists for their routes.
This can be parsed out of the page, using this c# code

// var aVCE = new Array(‘TXL’,’HAM’,’HAJ’,’CGN’,’STR’, 0);

string[] strlines = Regex.Split(tbEntry.Text,@"n");

string strOutput = "";

foreach(string strLine in strlines)


string strFromIata = Regex.Match(strLine,@"a(w{3})s").Groups[1].Value;

MatchCollection mcIatas = Regex.Matches(strLine,@"’w{3}’");

foreach(Match mIata in mcIatas)


strOutput+="’" + strFromIata + "’," + mIata.Value + "rn";



tbEntry.Text = strOutput;

Categories: Uncategorized

Google Toolbar buttons

March 14, 2006 Leave a comment
With the new version of Google toolbar, you can add your own buttons to it, with quite a simple technique.
Step 1.Create an .ico file,
Step 2. Base 64 encode it :

FileStream fsIco = new FileStream(tbIco.Text,FileMode.Open);

byte[] bIco = new byte[fsIco.Length];



this.tbOutput.Text = Convert.ToBase64String(bIco);



Step 3: Create an XML file containing the encoded icon


<?xml version="1.0" encoding="utf-8" ?>
<custombuttons xmlns="">
<description>Cheap Flights from Ireland</description>
<icon mode="base64" type="image/x-icon">AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAD/aXz/aXz/aXz+aHz7Z3q+YG7+aHv+aXv+aXz+aHv/aXz/aXz/aXz/aXz/aXz/aXz+aHz/aHv/aHz+aXz5ZnnXvMD+rbj+Y3f+an7+aXv+aHz+aHv+aXz+aXz/aXz/aXz+aXz/aHv+aHv+aXz+an3gipb8+vvglaC4ZW/9aX3+aXz+aHv+aX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