Blog posts


  • Adobe Illustrator to XAML

    March 30, 2010 | Tags: WPF, XAML, C#
    This is a great plugin for exporting from Adobe Illustrator to XAML for use in WPF or Silverlight projects. The plugin is freely available for both Mac and Windows over at:
    http://www.mikeswanson.com/xamlexport/

  • How to write code faster in .Net and Flash!

    March 25, 2010 | Tags: Actionscript, ASP.NET, C#, AS3
    Flash/Actionscript
    I've been a fan of the very functional development environment FlashDevelop for programming Actionscript. If you're still using the code editor in Flash for your AS2/AS3 programming needs you should head over and download FlashDevelop immediatly. Much better intellisense and hot keys to do common shores (like for instance pressing Ctrl + Shift + 1, which lets you declare functions, variables, properties etc way much faster than writing all the text yourself).

    Visual Studio/C#/VB.Net
    I've missed the above functionality for a long time, but today I found some great tools to add the same functionality into Visual Studio (and more!). There are some products out there to help speeding up your coding skills, like Resharper (which looks really cool and has a price tag starting at $149) from Jetbrains. The product I've just downloaded to install for free is Devexpress´ lite version of  CodeRush (priced $250) called CodeRush Xpress. If you're on a tight budget you should definitivly download it and give it a try (especially the CTRL + ´ feature!! (which is CTRL + ö on a swedish keyboard). If you got a more generous budget you might find the additional features in the commercial programs listed above of interest.

  • Analyze your .NET assemblies with FxCop

    March 12, 2010 | Tags: ASP.NET, Validation, C#, Troubleshooting
    Microsoft has a nice tool for analyzing your assemblies and recognize hundreds of potential security or performance issues as well as some bad mannered code standards.

    FxCop analyzes programming elements in managed assemblies, known as targets, by using rules that return informational messages about the targets when the rules are violated.

    Download FxCop from Microsoft
    Getting Started with FxCop

  • Javascript library via content delivery networks

    March 08, 2010 | Tags: Javascript, Google
    Are you using any of the following javascript libraries?
    • jQuery
    • jQuery UI
    • Prototype
    • script_aculo_us
    • MooTools
    • Dojo
    • SWFObject
    • Yahoo! User Interface Library (YUI)
    • Ext Core
    • Chrome Frame
    Then you may benefit from using Google's CDN (Content Delivery Network) for AJAX libraries. You'll find it over at Google AJAX Libraries API


    If you're using:
    • jQuery
    • jQuery Validate
    ..you might want to check out Microsoft's CDN at Microsoft Ajax Content Delivery Network

  • Cache functions in C# using memoization

    March 02, 2010 | Tags: ASP.NET, C#, Snippet
    Ever wanted to cache the output from a function depending on the parameters in the call, so - that for instance - a heavy calculation that would always return the same answer for a specific parameter set only was computed once? The answer to this i memoization.

    In computing, memoization is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously-processed inputs. Read more about memoization at Wikipedia.

    This is not very suitable for functions that depend on updated data etc. You might want to tweak the routine to handle a timeout for a couple of minutes to get the best out of both worlds, if that's your case.

    Please note that this only works for parameters passed by value. In C# this is the most common data types (string, int, double etc). More complex objects (like arrays or custom objects) is passed by reference.

    Source code (.NET 2.0)

    public delegate TReturn Function<TParam, TReturn>(TParam param);

    static Function<TParam, TReturn> Memoize<TParam, TReturn>(Function<TParam, TReturn> func) {

    Dictionary<TParam, TReturn> cache = new Dictionary<TParam, TReturn>();
    return delegate(TParam arg) {

    TReturn result = default(TReturn);

    if (cache.ContainsKey(arg)) {
    result = cache[arg];
    }
    else {
    result = cache[arg] = func(arg);
    }
    return result;
    };
    }

    Testing the code
    Lets create a dummy function just for testing purposes. It takes a name as inparameter and returns a string
    public string SayHello(string name) {
    return "Hello " + name + "! It's now " + DateTime.Now;
    }

    Setup and call our new function by these lines:
    // Create a memoized version of our function
    var SayHelloFunc = Memoize<string, string>(SayHello);

    string a = SayHelloFunc("Ted");
    string b = SayHelloFunc("John");
    string c = SayHelloFunc("Ted");

    If you set a break point at the first SayHelloFunc call and slowly steps through you'll notice that a and b will contain the exact same timestamp, regardless of the time between the two calls. This is cause their in parameter is the same and the result therefor cached.

    The parameters to the Memoize-function are:
    Memoize(function name);