Recently, I was tasked with creating a minified version of a web applications Javascript files.

I settled on the Yahoo YUI Compressor, in particular, the .net port of it

When I tried to compress a particular file (the jquery.caret plugin), it would throw up a syntax error.

This error only occurred using the .net port of Yahoo YUI Compressor.
Using the standard java jar version of YUI Compressor did not throw such an error.

The error was a syntax error on this line:

(function($,len,createRange,duplicate){

It was saying invalid character at position 0.

After some time scratching my head, I opened the file in notepad++ and converted text to hex 16
Immediatlely, I could see there were some invalid characters around the function text:

Hex characters in jquery.caret

Removing those characters and saving the file solved my problem, and allowed the file to compress.

I looked at the issues page for the jquery.caret project, and found this issue had already been reported

Update

I’ve created an issue on the codeplex page for this now:

http://yuicompressor.codeplex.com/workitem/10742

I blogged about using incremental ids with mongodb previously, so have a read of that for more information.

Although it’s not ideal, we can use sequential / incremental IDs with MongoDB.
Sometimes (when migrating legacy systems for example) we just can’t get away from using ints for id’s.

While working on implementing MongoDB with N2CMS recently, I came across this very problem.

All IDs are integers, and this can’t be changed
(technically, it could… but I don’t think it’s appropriate… yet)

So, we needed to find a way of generating incremental IDs

Fortunately, the MongoDB driver for .net allows us to write and use our own IdGenerators

So, with that in mind, I’ve created this:

www.github.com/alexjamesbrown/MongDBIntIdGenerator

It works on the principal outlined in my previous blog post:
Have a collection that keeps track of collection names, and increment their sequence each time one is inserted

This works well, on single server setups.

I have not yet tested on other setups, but intend to soon.

Joe Blogs Wrapper V2 – Help required

I’m on the verge of being able to release a second, much improved version of the Joe Blogs WordPress & MetaWeblog API Wrapper.

Some very brief details below, and a cry for help (or several cries!)

New Features / Improvements

Friendlier API
Instead of having to deal with the XML-RPC interfaces directly, I’ve added a “friendly” layer of classes on top.
The WordPressWrapper class has helper methods, with friendly properties, for doing things like uploading files etc…

  • More examples
    The sample project (console application) included in the project demonstrates all methods and features of the library.
  • Better documentation
    XML RPC Comments on all the public properties and methods

Help required

I need help with some of the following, both for this version, and subsequent versions

  • PHP WordPress Re-install script
    Script (configured as CRON job) to “refresh” test install of WordPress (every couple of hours or something)
  • Unit Tests
    Need better code coverage., and more integration tests
    I’m not TDD expert, so unfortunately, a lot of this will be retro-fitting unit tests into the current code.
  • WordPress Plugin development
    I plan to release an “extended” version of XML RPC – with some enhanced methods in, for use with JoeBlogs – for example “GetRecentPosts”
  • ASP.Net Demo Project
    Eventually, and ASP.net MVC “blog” project, running from WordPress – for no other reason than “it can be done”
  • Moving project to GitHub
    See below
  • General code improvement
    Refactoring, performance enhancements, etc…
  • Logo Designed
    ‘cos every cool open source project has to have a cool logo, right?
  • Website
    I’ve dipped my hand into my pocket, and bought joeblogswrapper.org (under £7 – GoDaddy)
    Will have a site dedicated to it on there soon. Obvious CMS choice would be WordPress, but if anyone can think of a better option for Wiki style pages, I’m all ears
    (Media wiki..? What are the benefits?)

Mailing List

I’ve created a Google Group – http://groups.google.com/group/joeblogs/
Please, sign up on there for announcements (I’ll announce when the next versions of the wrapper are available)

GitHub

I really like the idea of moving this project over to GitHub.

Problem is, I have absolutely no experience using Git.

I’ve tried following the instructions, and got as far as some files imported into my repository.. but I can’t get it to work, or commit my changes.

If anyone would like to offer their hand-holding expertise on getting this moved over (and training me on committing files etc…) then I’ll gladly move it to GitHub, which long term, I believe could be beneficial to the overall development of the project.

Get in touch

If you’d like to help with ANY of the above (or anything I’ve missed for that matter) please get in touch, or use the Google Group

C# – String.Concat vs String.Join

I had a quick Google search for a comparison between string.concat and string.join, but I couldn’t find anything.

Say you want to construct the sentence “The quick brown fox jumps over the lazy dog”

This is comprised of 9 words, 8 spaces.

Using string.concat:

public void CreateSentanceUsingStringConcat()
{
    string space = " ";
    string the = "the";
    string quick = "quick";
    string brown = "brown";
    string fox = "fox";
    string jumps = "jumps";
    string over = "over";
    string lazy = "lazy";
    string dog = "dog";

    var result = string.Concat(the, space, quick, space, brown, space, fox, space, jumps, space, over, space, the, space, lazy, space, dog);
}

Using string.join

public void CreateSentanceUsingStringJoin()
{
    var result = string.Join(space, the, quick, brown, fox, jumps, over, the, lazy, dog);
}

With String.concat, we must explicitly add the separator (in our case, space) between each string.

String.join however, allows us to specify the separator as the first parameter.

Performance

I wrote a small benchmark test on the two (see bottom of this post for code)

We can see string.join consistently performs better

image

Benchmark Code:

Note – This is available on GitHub – http://github.com/alexjamesbrown/StringConcatVsStringJoin

class Program
{
    //string.concat or string.join a million times to get a better reading
    const int numberOfTimesToRun = 1000000;

    const string space = " ";
    const string the = "the";
    const string quick = "quick";
    const string brown = "brown";
    const string fox = "fox";
    const string jumps = "jumps";
    const string over = "over";
    const string lazy = "lazy";
    const string dog = "dog";

    static void Main()
    {
        for (var i = 1; i <= 5; i++)
        {
            Console.WriteLine("Pass #" + i);
            Go();
            Console.WriteLine();
        }

        Console.Read();
    }

    private static void Go()
    {
        var concatStopWatch = Stopwatch.StartNew();

        for (var i = 0; i < numberOfTimesToRun; i++)
            string.Concat(the, space, quick, space, brown, space, fox, space, jumps, space, over, space, the, space, lazy, space, dog);

        concatStopWatch.Stop();

        var joinStopWatch = Stopwatch.StartNew();
        for (var i = 0; i < numberOfTimesToRun; i++)
            string.Join(space, the, quick, brown, fox, jumps, over, the, lazy, dog);

        joinStopWatch.Stop();

        Console.WriteLine("string.join - {0}", joinStopWatch.ElapsedMilliseconds);
        Console.WriteLine("string.concat- {0}", concatStopWatch.ElapsedMilliseconds);
    }
}

After attending the UK Tech Days events last week in London, I was keen to jump on the Visual Studio 2010 and .net 4.0 bandwagon.

I converted some of our projects here at Crocus to the .net 4 framework (which was incredibly easy – nothing broke!)
I even took advantage of some of the quick to implement features in .net 4, and converted some of our massively over-ridden methods to use optional parameters.

One project in particular is a Windows Service, that sends out purchase orders on a schedule.
(I recently wrote about how this broke due to Quartz.net expecting a UTC start time)

This has a Visual Studio deployment project associated with it.

After building the newly upgraded .net 4 version of the project, and deploying the .msi file to our target server, I got the following error:

Error 1001 Exception occurred while initializing the installation. System.BadImageFormatException: Could not load file or assembly or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Now, I had definitely upgraded said server to .net 4 (twice, as a matter of fact – after the first time i received this error!)

After some Googling, some people were saying to change the platform target on my assemblies, which i did, to no avail.

I eventually discovered the problem.

You need to set the .NET Framework Launch Condition

Here’s how to do it:

Right click on your deployment project in solution explorer

Right click on your deployment project in solution explorer

Under “Version” Choose .NET Framework 4

Under “Version” Choose .NET Framework 4

After rebuilding and deploying my setup file, everything worked fine.


Page 1 of 3