Page 1 of 2 in the Coding category
Next Page
 Wednesday, April 23, 2008

Scott Hanselman has come up with a way of describing us all... read about it here.

I'm this:

Yes, I know, I'm teh lame.

Wednesday, April 23, 2008 4:23:33 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, January 15, 2008

Here's a quick techy post to start the New Year...

In SQL Management Studio you can save your results pane as a CSV file. All you need to do is select the grid, right-click, and select "Save Results as...". Nice and simple (and a quick way of getting your data out of the DB).

However (and there just had to be a "however", didn't there?), the CSV file that's saved can't be read by the .Net StreamReader object, as the Encoding can't be detected (it's Encoding.Unicode) automatically. Initially, I did try to detect it using the BOM (Byte Order Mark) of the file, but there isn't one. In the end, I checked that the 1st and 3rd characters were value zero, which for the files I'm interested in is perfectly valid, and if so explicitly set the Encoding to Unicode. If you do this, make sure you set detectEncodingFromByteOrderMarks to False.

Updated 2008-01-18: And now, just to annoy me (it's a conspiracy, I tell you!), the file has miraculously acquired a BOM: FF FE, which according to Wikipedia means it's UTF-16 little-endian. Not sure if the endian-ness (or whatever the term is) makes a difference, as Encoding.Unicode still works.

I've no idea where this BOM has come from - does anyone know if SQL Management Studio was updated through Windows Update recently?

Coding | Work
Tuesday, January 15, 2008 1:48:35 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
 Monday, August 13, 2007

Good grief, it's been a while....

Ok, my first new post in ages should be something interesting, noteworthy, possibly controversial, so I shall choose: my new phone!

HTC Touch

Maybe not the *most* fascinating subject, but there are a couple of things that it's probably worth posting about. First off, it's an HTC Touch, and I think it's great. From the review I've seen there seems to be disappointment that the processor isn't faster, and there are times when it could certainly do with a bit more speed, but it's a huge improvement over my last handset, and seems perfectly happy most of the time. The only problem I've had so far is with City Time Alarms, which was my preferred alarm program on my old handset. Unfortunately, on the Touch when this program is installed it throws a whole bunch of errors on startup, and generally misbehaves. I've contacted the authors about this, and with any luck they'll come up with a fix.

The main point of this post is the weather. To be specific, the weather module in the Touch. You select your city from the list, and it runs off to the web to find your weather report. Very nice, useful, and even rather pretty. However, since the default list for the UK appears to contain Edinburgh, London, Manchester and Plymouth, and not a whole lot else, it's of limited use.

Now, the list of cities is kept in the HH_0409_WeatherCities.xml file, located in the Windows directory on the phone. To add new cities we must edit this file. However, it appears to be a read-only system file, and the built-in File Explorer won't let you edit it. However, the Pocket version of Total Commander will, so that's what I'm using. To add a city, you need to insert a line like this:

<city locationcode="EUR|UK|UK001|READING" name="Reading, England"/>

The next question is where to find city details - you can't just put in the name of any town and expect it to work. A little digging on the web told me that AccuWeather was the source of the weather information, and a look at that site shows that there is a pre-set list of cities for different countries. Go to the AccuWeather site, and use the "Find your local forecast" feature and you can see which cities are available. A bit of "view source" and we can see that the list of cities is populated by an ASP page (change the reqion and country to suit yourself): http://www.accuweather.com/includes/ajax-functions/favoriteCities.asp?region=EUR&country=UK

Ok, so now we have a list of cities for our country. We now need to get them in the correct format. The AccuWeather feed looks like this:

<cities>

  <city code="EUR|UK|UK002|ABERDEEN" display="ABERDEEN, SCOTLAND"/>

  <city code="EUR|UK|UK001|ASHFIELD" display="ASHFIELD, ENGLAND"/>

  <city code="EUR|UK|UK001|BARNET" display="BARNET, ENGLAND"/>

  <city code="EUR|UK|UK001|BARNSLEY" display="BARNSLEY, ENGLAND"/>

<cities>

and we need this:

<locations>

  <city locationcode="EUR|UK|UK002|ABERDEEN" name="Aberdeen, Scotland"/>

  <city locationcode="EUR|UK|UK001|ASHFIELD" name="Ashfield, England"/>

  <city locationcode="EUR|UK|UK001|BARNET" name="Barnet, England"/>

  <city locationcode="EUR|UK|UK001|BARNSLEY" name="Barnsley, England"/>

</locations>

A bit of search and replace should do the trick! I now copied this file, HH_0409_UK_Cities.xml (8.86 KB) , to my Touch, made a backup of the original list (HH_0409_WeatherCities.xml (24.62 KB)), and replaced the original list of cities with my list of UK cities. Done!

Note to self: try and remember to blog a little more often!

Monday, August 13, 2007 8:28:06 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
 Friday, July 20, 2007
GOTO

From (where else?) XKCD.

Friday, July 20, 2007 7:43:09 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
 Friday, July 06, 2007

I don't seem to have posted anything this week, so I feel I really ought to rectify that... So, here's a few words about some Visual Studio Addins that I use regularly.

1. GhostDoc

This addin helps you generate source documentation. It's such a faff writing what are often no more than restatements of the name of the function, but this addin takes care of a lot of it for you. It's written for C#, but can be used for VB.Net as well (to an extent).

For example, the VB.Net function:

Private Function Translate(ByVal sourceXml As String, ByVal xslFile As String) As String

gets the comments:

''' <summary>

''' Translates the specified source XML.

''' </summary>

''' <param name="sourceXml">The source XML.</param>

''' <param name="xslFile">The XSL file.</param>

''' <returns></returns>

Private Function Translate(ByVal sourceXml As String, ByVal xslFile As String) As String


2. CodeKeep

An on-line repository for code snippets. Ok, I keep a few on my main website, but with this plugin they're browsable from within Studio.

3. CopySourceAsHTML

This one adds a context menu into Studio that allows you to copy the highlighted text, formatted as HTML, retaining the colour and style information used in Studio. A nice solution to the code colouring problem that those of us with techy blogs have! It's what I've used for the comment snippets above.

N.B. The above tools all work with Visual Studio 2005. I have no idea about other versions!

Coding | Software | Work
Friday, July 06, 2007 11:55:16 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
Page 1 of 2 in the Coding category Next Page