Jane's Technical Stuff

Thursday, July 02, 2009

Coding challenge 3


Today, Mark and I announced the winner of the 3rd Madgex Coding Challenge. This coding challenge was announced on the 3rd June and entries needed to be in on the 30th June. The email announcement said:
So, the challenge this time is all around compression.

Take a string, compress it into a byte[], record the size, decompress it.

You can use any algorithm you chose, but it must be coded by you and not included from an external library

I have defined an Interface ICompress as follows:

public interface ICompress
{
   /// <summary>
   /// Take a string and convert it into a byte[]
   /// </summary>
   /// <param name="source">The string to be converted</param>
   /// <returns>The converted byte[]</returns>
   byte[] Compress(string source);

   /// <summary>
   /// Take the bytearray produced by the call to Compress, and decompress it
   /// </summary>
   /// <param name="compressedData">The data to be decompressed</param>
   /// <returns>The string</returns>
   string DeCompress(byte[] compressedData);
}


I have provided a solution with the interface (Interface), a console app (CodingChallenge3) and an implementation of the interface (Compressor) (which just converts from string to byte[] and back again, no compression) on the development file share.

The source string is provided through the app.config file of the CodingChallenge3 project (the console app).

What do you need to submit?
- A Compressor project that I can plug in to the provided solution
- A couple of paragraphs explaining how your algorithm works


We had 4 solutions submitted, and they were all of a really high standard. I tested them with 6 different input scenarios:
- The original provided sample - the text for "Mary had a little lamb"
- An empty string - which caused a few exceptions to be raised
- A single space
- A string of numbers
- The contents of war and peace
- The contents of the 3 musketeers in French

Each sample was run through each person's solution, and the most compressed result won that round. In the end, one person won 2 rounds (having implemented their own algorithm) and one won 4 rounds (having implemented 3 different methods and selected the one with the highest compression).

This was based around Puzzle 16: Zip me up, Buttercup from the great resource Collection Of Puzzles For Programmers

Previous coding challenges have been based loosely on LTD Puzzle 4: Finding Prime Numbers (which was Madgex coding challenge 1) and LTD Puzzle 3: ASCII Art Shapes (Madgex coding challenge 2).

I'm delighted with how these are going, and the interest and general communication that they generate - lots of discussion, hints of secrecy, and comparisons between each other - and then lots of discussion once the results have been announced, and the code is available for scrutiny. So, I'm now busy thinking up ideas for Madgex Coding Challenge 4 - if anyone has any suggestions or resources for me to use, please pop them in the comments

Labels: ,

// posted by Jane @ 6:02 PM   save to del.icio.us

Comments:

Wednesday, June 24, 2009

SQL: Building a comma separated list from a select clause


A colleague asked me today about generating a comma separated list of values based on the results of a SELECT statement. A quick google later and I found Using COALESCE to Build Comma-Delimited String

So, for my table Continent, and my usual SELECT of
SELECT [Name]
FROM Continent

with just a variable declaration and a use of COALESCE and hey presto, we get our required result of Africa, Antarctica, Asia, Australia and Oceania, Europe, North America, South America

The code is now:
DECLARE @List VARCHAR(1000)

SELECT @List = COALESCE(@List + ', ', '') + Name
FROM Continent

SELECT @List


Nice and simple. I like!

Labels: ,

// posted by Jane @ 10:08 AM   save to del.icio.us

Comments:

Wednesday, June 10, 2009

Pocket Pomodoro


I use toodledo to manage my todo list, and this works fine, except that it means I have my browser open all the time and don't really plan my days too well being a bit more reactive than proactive. A few weeks ago I stumbled across a tweet from Craig Murphy linking to the ebook version of a (very well written) Pomodoro manual (Pomodoro being a time mangement system). I've been using the Do It Tomorrow technique with toodledo, but haven't really embraced the daily system. Combining the two looks like it'll work well for me, allowing me to focus on what I need to do each day, whilst still recording other items (tomorrow and beyond) in toodledo.

I also recently stumbled across the PocketMod books from paper concept, and have been using a simple one as my work week planner for the last couple of weeks. Today I went one stage further and used Natalie's Pocket Project html/css work to create a Pocket Pomodoro template for myself to use.

It has a week view on the front page - so I can put known appointments in there, allowing me to carry my calendar around the office with me. And then 5 pages of todos, one per week day with an Unplanned and Urgent section to note down extra items. I haven't put any checkboxes in as the number of pomodoros taken to fulfill a task will dictate this. There is an Activity Inventory page, to put any of the items that appear that are not do it today urgent - these will be put into toodledo at an opportune moment. Finally there is a notes page, to jot down anything that comes up during my week. Over time, as I use this more, this may become a second Activity Inventory page, so watch this space.

As with Natalie's example, it only works on Webkit based browsers so I've also created it as a PDF for anyone who is interested in using this but isn't using a webkit based browser.

And of course, once you've got your PocketMod printed, you'll need to fold it, and this YouTube video does a great job of explaining how to do that


The links again: Pocket Pomodoro as HTML, Pocket Pomodoro as PDF

As with the other tools, utilities etc I've made available, leave me feedback either via comments, or via the contact form.

Labels: , , , ,

// posted by Jane @ 6:09 PM   save to del.icio.us

Comments:

Monday, June 08, 2009

spu_generateInsert - handle unicode characters


I updated spu_generateinsert again today when one of my colleagues reminded me that I needed to prefix my strings with a capital N to ensure that any unicode values go into the database correctly.

So now instead of the call spu_generateinsert @table = 'LanguageData' producing
INSERT INTO [LanguageData] ([liID], [Value])VALUES (7,'D''Artagnan raconte qu''à sa première visite à')
it produces
INSERT INTO [LanguageData] ([liID], [Value])VALUES (7,N'D''Artagnan raconte qu''à sa première visite à')

As usual, the script is available here
And again as usual, leave me a comment if you think of some new functionality I should include, or any issues you come across.

Labels: , ,

// posted by Jane @ 9:00 PM   save to del.icio.us

Comments:

Tuesday, June 02, 2009

NTS: App_Offline.htm and working around the "IE Friendly Errors" feature


Yet another in the note to self category.

When using App_offline.htm files to take down a site in IIS, if the file size isn't 512 bytes of content or greater then IE may choose to default to the "Show Friendly Http Errors". Comments count towards the byte size so client side comments will work too.

There is more about this at ScottGu's blog

Labels: , ,

// posted by Jane @ 11:50 AM   save to del.icio.us

Comments:

Friday, May 22, 2009

NTS: The HTTP verb POST used to access path '' is not allowed


Another for the Note To Self list

A lot of our sites use a url mapper, so when setting up the sites within IIS we map extension .* to the appropriate aspnet_isapi.dll.

I'd got carried away when setting up the webservice and did the same thing, resulting in a The HTTP verb POST used to access path '/WebService/WebService.asmx/DoSomething' is not allowed. error. Removing the .* mapping fixes this.

Labels: , ,

// posted by Jane @ 3:34 PM   save to del.icio.us

Comments:

Wednesday, May 20, 2009

NTS: InstallUtil and parameters


Definitely under the note to self category this one...

I've been working with installing a service and took the base code from our platform. Part of the command line specifies a parameter to be used within the installer, but no matter what I did I could not get the parameter to be picked up.

An example of the installation command line is
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installUtil.exe" "C:\Services\MyService.exe" /SERVICENAME="My Special Service"
which, at least in theory, allows the service to be created so that in the Services dialog it is listed under the name "My Special Service"

A quick google with the right keywords and I stumbled across The curious case of InstallUtil and service parameters which both explains the situation and provides a lovely working solution.

In my case, the code was even simpler than the example as I was specifically looking for only one parameter, the service name, and so my OnBeforeInstall and OnBeforeUninstall become

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{
   base.OnBeforeInstall(savedState);
   SetServiceNameFromCommandLineParameter();
}

protected override void OnBeforeUninstall(System.Collections.IDictionary savedState)
{
   base.OnBeforeUninstall(savedState);
   SetServiceNameFromCommandLineParameter();
}


where SetServiceNameFromCommandLineParameter is :

void SetServiceNameFromCommandLineParameter()
{
   const string SERVICE_NAME = "SERVICENAME";

   String[] args = System.Environment.GetCommandLineArgs();
   String no_log_file = null;
   InstallContext tmp_ctx = new InstallContext(no_log_file, args);

   string serviceName = tmp_ctx.Parameters[SERVICE_NAME];

   if (serviceName == null)
   {
      throw new ApplicationException(string.Format("{0} undefined", SERVICE_NAME));
   }

//Set service name
   this.serviceInstaller1.DisplayName = serviceName ;
   this.serviceInstaller1.ServiceName = serviceName;
}


where serviceInstaller1 is defined as private ServiceInstaller serviceInstaller1;

As to why this works in the base code, but doesn't for mine I have no idea, but I have at least got it working now

Labels: , , ,

// posted by Jane @ 2:58 PM   save to del.icio.us

Comments:

Brighton Bloggers   This page is powered by Blogger. Isn't yours?   rss Sussex Digital - focusing on the Sussex digital community