Archive

Archive for March, 2006

SQL performance: Nested select statements.

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

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

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.
IF ERRORLEVEL == 3 GOTO LIVE
IF ERRORLEVEL == 2 GOTO BACKUP
IF ERRORLEVEL == 1 GOTO LOCAL
EXIT
 
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
EXIT
 
Categories: Uncategorized

Google Toolbar buttons… second attempt

Categories: Uncategorized

Transparent Localisation

I’ve just launched one website, in four different languages all in the same path, with the same files & database under IIS.
    www.sms-txt.co.uk (english)
   www.handyspruche.com (german)
   www.envoyezsms.com (french)
  www.mensajetexto.com (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.es-ES.resx, strings.en-GB.resx etc.

public static string Translate(string ID)

{

rmTranslations.IgnoreCase =

true;

string strTranslation ="";

Thread.CurrentThread.CurrentCulture =

new CultureInfo(getGetSiteCulture());

Thread.CurrentThread.CurrentUICulture =

new CultureInfo(getGetSiteCulture());

try

{strTranslation= rmTranslations.GetString(ID);}

catch{

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

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

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];

fsIco.Read(bIco,0,(

int)fsIco.Length);

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

fsIco.Close();

 

Step 3: Create an XML file containing the encoded icon

 

<?xml version="1.0" encoding="utf-8" ?>
<custombuttons xmlns="http://toolbar.google.com/custombuttons/">
<button>
<title>CheapFlights.ie</title>
<description>Cheap Flights from Ireland</description>
<search>http://www.cheapflights.ie/search.aspx?txt={query}</search&gt;
<icon mode="base64" type="image/x-icon">AAABAAEAEBAA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Xz/aXz/aXz+aHz9Z3v3laL9cYL+Z3r+aHz+aHv/aHz/aXz/aXz/aXz/aXz/aXwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</icon>
</button>
</custombuttons>

 

step 4.

Host the xml file on line  – I called it slashdot_button.xml

Then let people download it from

http://toolbar.google.com/buttons/add?url=http%3A%2F%2Fwww.cheapflights.ie%2Fslashdot_button.xml

 

Categories: Uncategorized

“Cannot open SQL server” bug Crystal Reports

This one baffled me for a while. I was trying to connect to a Crystal Report from VB, with an Access database. And it was giving me a "Cannot open SQL server", even though I was not using SQL server.
 
Under Database / Add Database, you have several options to add an access database,
eithe ODBC, OLEDB or Database File.
 
I found that Database File worked, the other two didn’t. This could be down to the
connection string that I used in my program though.
 
 
 
 
Categories: Uncategorized

IT clearout

Hi,
 
   I’m clearing out my house of some books and equipment, prob. going to list them on ebay soon. If you’re interested in any of these, drop a note on the blog or by email.
 
http://www.blackcomb.co.uk/pics/040306_0912~02.jpg Developing windows based applications in c#
 
http://www.blackcomb.co.uk/pics/040306_0918~01.jpg Net2Plug power cable home networking kit.
Categories: Uncategorized