Latest Posts


Jan 2014

While Google Analytics may have been the bees knees when it comes to web stats in the past, it seems to have taken an almighty tumble from the top spot in recent years. The interface has gone from being one of the cleanest, easiest to use, to one of the most confusing out there.

I decided it was time to consider moving away from Google Analytics, so recently I have been playing around with a few different web stat packages, running multiple at once on the same page. In doing so, I began to notice that some packages were reporting a higher number of views than others.

When I started to dig closer to see what was causing this, I discovered that some of the packages were showing a large number of hits to pages localhost:page_name.

Yep, it seems that not all of the packages are clever enough to filter out page views from your development server.

To resolve the issue - I found a nice little hack that will only display the tracking code on the live server.

The ASP.NET property Request.Url.Host will reveal the URL by which the site was accessed - by simply checking this value you can tell whether the site is live, or running on a dev server. You can then hide the tracking code accordingly.

@if(Request.Url.Host != "localhost")
{
    // show tracking code - site is live
}
continue...

Jan 2014

There's something about the New Year which encourages change.

Perhaps it's the nice break formed by the Christmas and New Year holidays. I typically take the whole period off work, giving me a full two weeks off. It's also about the only time I take time off work and stay home. With my passion for travel, the limiting factor normally ends up being my annual leave, so I'm always looking to maximise my time off, and go away whenever possible.

Perhaps it's just the tradition of making a New Year's Resolution.

Whatever it is, New Year always presents a nice opportunity to sit back and reflect on the direction you are going in, and feels like a natural time to implement change.

And so with the start of the New Year, it feels like now is a good time to re-design the look and feel of this blog.

It all starts with a new lick of paint.

continue...

Jul 2013

I've been trying to find the perfect blogging platform for years now. I've tried Wordpress, but found it too bloated, slow and difficult to customise.

FunnelWeb looked good, but that project seems to have died recently. Even the founder of the project, Paul Stovel, has dropped it for his own personal blog. Never a good sign.

Paul instead has developed a new platform for his own blog, and describes it in a blog post here. He starts by saying:

A question on StackExchange is "What's the best platform for blogging about coding?", to which the accepted answer is, of course: make your own.

And that got me thinking - why not write my own as well! A quick search online found a good tutorial on how to create your own blog using ASP.NET MVC.

A few days later, and I had built the blog you are currently reading! I made a few changes from the tutorial to meet my own preferences:

  • Entity Framework for the database connection
  • New admin section (still under construction)
  • Markdown support with live previews
  • Prettify for code highlighting
  • Added Pages support

There's still a bit of work to do, particularly on the admin section, but that can come later! Let me know what you think in the comments below!

continue...

Jun 2013

The following tutorial explains how to connect to a Stomp data feed in C#, by using the Apache.NMS client.

To start with, download the Apache.NMS.Stomp Client.

Once downloaded, open the zip file and extract the following DLLs - copy them to the desktop for now:

/build/<.NET or Mono Version Required>/Release/Apache.NMS.Stomp.dll
/lib/Apache.NMS/<.NET or Mono Version Required>/Apache.NMS.dll

Next, start a new Console Application project in Visual Studio. Add a reference to the two DLLs selected earlier. Also add the following using statement - using Apache.NMS;

NOTE: You may receive a compile error that "apache" could not be found. this seems to occur when your project target type is set to ".NET Framework 4 Client Profile". If you change it to ".NET Framework 4" this error goes away.

Ok, lets write some code.

In your main() function, create a ConnectionFactory, which we will then use to create a connection and session:

IConnectionFactory factory = new NMSConnectionFactory(new Uri("stomp:tcp://datafeed:61618"));

IConnection connection = factory.CreateConnection("username", "password");
ISession session = connection.CreateSession();

Next subscribe to the feed you wish to access:

IDestination destination = session.GetDestination("topic://topic_name");
IMessageConsumer consumer = session.CreateConsumer(destination);
connection.Start();

We have now connected to the data source and subscribed to a particular feed. Next we need to handle any messages that are received from the feed. We do this by creating a MessageListener:

consumer.Listener += new MessageListener(OnMessage);

That is all that we need in main - simply add a readline statement to stop the program from exiting immediately:

Console.ReadLine();
connection.Close();

We now create a new function called OnMessage, which will be called every time a message is received:

private static void OnMessage(IMessage message)
{
    ITextMessage msg = (ITextMessage)message;
    message.Acknowledge();

    Console.WriteLine(msg.Text);
}

And that is all there is to it! If you run this now, you should see messages arriving from your data feed. Of course you may need to do additional processing on these to extract the data in a more useful format, but that's a tutorial for another day.

Full application code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Apache.NMS;

namespace ApacheNMS
{
    class Program
    {
        static void Main(string[] args)
        {
            IConnectionFactory factory = new NMSConnectionFactory(new Uri("stomp:tcp://datafeed:61618"));

            IConnection connection = factory.CreateConnection("username", "password");
            ISession session = connection.CreateSession();

            IDestination destination = session.GetDestination("topic://" + "DATA_FEED");
            IMessageConsumer consumer = session.CreateConsumer(destination);


            connection.Start();
            consumer.Listener += new MessageListener(OnMessage);
            Console.WriteLine("Consumer started, waiting for messages... (Press ENTER to stop.)");

            Console.ReadLine();
            connection.Close();
        }

        private static void OnMessage(IMessage message)
        {
            try
            {
                Console.WriteLine("Median-Server (.NET): Message received");

                ITextMessage msg = (ITextMessage)message;
                message.Acknowledge();

                Console.WriteLine(msg.Text);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("---");
                Console.WriteLine(ex.InnerException);
                Console.WriteLine("---");
                Console.WriteLine(ex.InnerException.Message);
            }
        }
    }
}
continue...