Saturday, June 15, 2013

Website ideas

I often have ideas for websites, but due to a lack of time I never actually get round to doing anything about them. They may well be terrible ideas, or may already exist in some form already, and almost all of them are guaranteed to not make any money, but I present them here in case anyone wants to pick up the baton and run with them.

Random acts of kindness

Say you have some spare cash and you want to give it to a good cause, but you don’t have a good idea about who to give it to. Wouldn’t it be great if there was a website where you could post a message saying ‘I have some money, who wants it?’ and from the other side people could post messages asking for money, help or whatever? When you find someone you want to help, you can contact each other and arrange to hand over the cash (although there needs to be some kind of protection here against receiving shedloads of begging emails).

Domain reminder

So you’re interested in buying that doogal.com domain (oh, that’s just me is it?) but somebody has bought it already and is sitting on it, only being prepared to sell it for a ludicrous 2800 euros? If you’re willing to wait, wouldn’t it be great if there was a website that would send you reminders when the domain name was about to expire? And whenever the status of the domain changed in any other way?

Foreign exchange market

The difference between the official exchange rates and the price you’ll pay to exchange money yourself can be huge. But whenever I convert 100 pounds to euros, there’ll be thousands of other people who want to take their euros and convert them into pounds, so how about a website to match the buyers and sellers? I’ve not really thought through how the exchange takes place, but that’s just a minor detail…

Re-open nominations

This is more than just a website, this is a political movement. Back in the day when I was at university, any election would include RON, re-open nominations. So if you weren’t happy with any of the candidates, you could vote for RON and if enough people voted for him then the election would be rerun. Currently I’m pretty disappointed with all three of our major parties, since there seems to be very little difference between them in terms of policy and they all seem to be led by people who have no experience of the real world. But there is no way to register the fact that I still believe in the democratic process but don’t want to vote for any of the options available to me. So for my take on this idea in real elections, the RON Party would stand in every election, promising to immediately stand down if elected. Along with that, it would lobby the government to include RON as an option in all elections.

Fat cyclists

I enjoy cycling, but have no desire to wear lycra. There are lots of clubs for cyclists, but they are generally full of extremely fit people who cycle 50 miles a day. So how about a web community for people who like to cycle but aren’t necessarily as fit as they could be and don’t take it too seriously so they can get together and have a slow ride together?

Wednesday, June 05, 2013

Poor man’s XSLT profiling in detail

A couple of years ago I wrote a post giving a vague idea of how to profile XSL transforms without shelling out for Visual Studio Team System. I went back to it recently and realised it didn’t really provide enough information on how to actually perform the profiling. So here’s another go at it.

The first thing we need to do is compile the XSLT into a .NET assembly. For this we need to use the XSLTC.EXE tool that ships with the Windows SDK. You can find this somewhere like this C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools. The command-line required will be something like this xsltc.exe /settings:dtd "/out:c:\temp\style.dll" /class:MyXslt "C:\temp\TEST.xsl"

So now we have an assembly for our XSLT file. Next we need a little wrapper program to load it up and call the transform. I used a simple command line app, with code as follows

    static void Main(string[] args)
    {
      XslCompiledTransform transform = new XslCompiledTransform();
      transform.Load(typeof(MyXslt));
      XmlTextReader reader = new XmlTextReader(@"C:\temp\input.xml");
      XmlTextWriter writer = new XmlTextWriter(@"C:\temp\out.html", Encoding.UTF8);
      transform.Transform(reader, writer);
    }

Now we are ready to profile the XSLT. In the past I’ve always recommended AQTime, but my old version of it doesn’t seem to work on Windows 8. I didn’t fancy paying for an upgrade, so looked around for alternatives and found the Eqatec profiler. The free version seems to work pretty well, certainly good enough for my limited needs.

So after running my little test app through the profiler, I had a much better idea of where things were slow in my XSLT. As is often the case, it was due to some XPath using “//element” to find elements. Often you can get away with it, but if the XML document is large or that piece of code is getting hit a lot then it can bite you. 

There is another slight complication with this approach to XSLT profiling. Some of the compiled templates may have a name of “compiler:generated”, meaning it’s pretty tricky to figure out how they relate to the original XSLT. From my experience, it seems that these templates are generated by the compiler itself when it decides to split larger templates into smaller compiled templates. I found ILSpy was pretty useful here to match the compiled code back to the original XSLT.

Sunday, April 28, 2013

Traversing JavaScript objects in .NET

I’ve been playing around with hosting a Google Map in a .NET WinForms control, for no good reason other than to see if it can be done. The key part of this integration is calling JavaScript on a web page from .NET. This appears reasonably straightforward, the WebBrowser control has a Document.InvokeScript method that does the trick. If your JavaScript function returns a value, you can pick this up from the return value of InvokeScript.

This works great for simple types, but what if your JavaScript function returns a more complex type? This is where things get a bit more tricky. The returned object has a type of System.__ComObject and initially it looks like this has no useful methods on it. This is the object that is used when calling any COM object, but generally you’ll be able to import a type library to create a .NET friendly wrapper around the raw object. This obviously isn’t the case here.

So my first thought was to find the real underlying type of the __ComObject. This piece of code helped out here. It turns out the actual underlying type was a JScriptTypeInfo but there’s very little information out there about what this type does or how to use it.

But it turns out there’s a much simpler way to access the returned object, cast the returned object as IReflect and use its methods to get properties etc. So the code for my .NET property looks like this

    [Category("Map")]
    public LatLng Centre
    {
      get 
      {
        object centre = webBrowser.Document.InvokeScript("getCentre");
        if (centre == null)
          return new LatLng(0, 0);

        IReflect reflect = centre as IReflect;
        double lat = (double)reflect.InvokeMember("lat", BindingFlags.InvokeMethod, null, 
          centre, null, null, null, null);
        double lng = (double)reflect.InvokeMember("lng", BindingFlags.InvokeMethod, null, 
          centre, null, null, null, null);

        return new LatLng(lat, lng);
      }
      set
      {
        webBrowser.Document.InvokeScript("setCentre", 
          new object[] { value.Latitude, value.Longitude });
      }
    }

Another approach to this would be to have two JavaScript functions, getCentreLat and getCentreLng, which just return simple types, but that could get cumbersome with really complex types.

I’m not sure if it’s possible to pass complex objects into JavaScript but I haven’t needed that yet. Again, for really complex types, passing in each part of them could get messy.

A dog’s life

WP_000028

It’s a hard life for a dog. It all starts when the sun comes up. “I must inform my master that the sun has come up. Woof woof…”.

Some time later “… woof, woof. Ah good, my master is up to see that the sun has come up, I can now go back to sleep”. Thank you dog!

Wednesday, April 24, 2013

Around the world in 7 years

According to Endomondo, I’ve cycled 2668 miles since I signed up with them, which is just over a tenth of the distance around the world. According to my circle drawing page, this would take me from my house to the North Pole. I’m quite pleased with that.

The distance round the earth is about 24,900 miles, depending on how you measure it. I try to cycle 300 miles a month, so the time it will take me to cycle the whole way round the earth is 24,900/300 which is 83 months, or 6.9 years. So in about 6.1 years I’ll have completed my virtual trip. I’m hoping Endomondo is still around to record my achievement!

Tuesday, January 29, 2013

404s and Google Webmaster Tools

Trying to fix all the things Google Webmaster Tools complains about would drive you insane. Case in point, it will warn you about soft 404s, which are URLs that don’t exist (or contain no useful content) but don’t return a 404 HTTP error code.

I had a few of these on my site where a rebuild of the postcode database meant a few old postcodes had gone missing (here’s one). Although they weren’t any links to them from anywhere, Google never forgets about pages it’s crawled. I guess I could ask Google to remove all these URLs from its index, but I have a life.

So I started returning 404 errors from these pages, hoping it would make Webmaster Tools happy and make the web a better place. Then a few days later I got a warning message from Google telling me there had been an increase in not found errors on my site. Duh, well yeh, because that’s what you told me to do.

So all I’ve managed to do is move my errors from the soft 404 bucket to the not found bucket. Ho hum. It seems like keeping Webmaster Tools happy is actually impossible.  

Sunday, January 27, 2013

The quickest way to charge a Nokia Lumia 800

I can’t say I’ve ever considered the differences between charging my Nokia Lumia 800 via USB and via the AC adaptor. If I had thought about, I would probably have assumed they charge at just the same rate. But this morning when I was thinking about going on a bike ride, I realised my phone was out of juice, so wanted to charge it ASAP. A little research showed using the AC adaptor would be much quicker than plugging into USB.

But in case you don’t believe me (And to be honest not believing random people on the internet is probably a good thing), you can check it out for yourself. From the phone dialler, type ##643# and the diagnostics tool will be installed. Run this app and look at the battery status section whilst charging. I found the AC adaptor was providing about twice as much power as the USB connection.

Friday, January 04, 2013

Post Office Recorded Signed For–Mmm, not so much

I needed to send my driving licence off to a company to prove I am who I say I am. Something to do with money laundering, although I’m not entirely convinced sending them my driving licence proves I’m not a criminal. Maybe I’m just a money launderer who can drive?

Anyway, wanting some peace of mind, I decided to use the Post Office’s ‘Recorded Signed For’ service which has “guaranteed signature on delivery” according to their website. That was on 17th December. Over 2 weeks later, when I try and track my package, the Post Office website tells me

Item BY260667256GB was posted at 46 Hawks Road KT1 3EG on 17/12/12 and is being progressed through our network for delivery.

The thing is I know this isn’t true, since the driving licence arrived back at my house a few days ago. So much for a guaranteed signature on delivery. I wonder if the status of my item will get updated to

Item BY260667256GB was posted at 46 Hawks Road KT1 3EG on 17/12/12 and we haven’t got an effing clue where it is.

Friday, November 23, 2012

Endomondo discovers how to get my money

When I logged into Endomondo the other day I discovered that in the process of redesigning their website, they had also decided to hide some of the useful stats from us users who weren’t paying them any money.

I could have started shouting and screaming at this point, since they’d had the temerity to take away my free toys. But frankly $20 a year for a very useful service is a price worth paying if it helps them to keep the lights on.

Of course this approach only works for sites that offer a valuable service, it probably wouldn’t work for quite a few sites (I’m looking at you Facebook!)

Wednesday, November 21, 2012

Windows 8 – How bad are these apps?

For most of my time I’ve been using Windows 8 much as I used previous versions of Windows and stayed well away from the new interface and apps. But I’ve recently started playing with some of the apps and frankly it’s all quite disappointing.

For a start, every app seems to take an age to fire up. This makes no sense, I have a reasonably specced laptop and yet apps take longer to load up than on my phone, even though the apps do the same thing! I really hope this is a problem with the apps, rather than the underlying platform, since at least the apps can get updated quite easily.

The other problem is some of these apps are pretty buggy. We’ve been playing solitaire on our Windows PCs for over twenty years and I can’t remember it ever crashing before, but it’s just happened about 5 times in the space of a few minutes. Ah well, maybe one of those updates advertised in the store is for solitaire? Hard to say since the store keeps telling me I’m not connected to the internet, even though I definitely am. And when I do manage to access it, I can’t actually get to the updates.

I’m not sure the good folk at Apple will be quaking in their boots at the moment.

Thursday, November 08, 2012

UK postcode data is free, mostly

Today someone posted a comment to my site saying this

at [redacted] you can find a full uk postcode database with all postcodes and long / lat values. it is the only source i found where northern ireland is included. there is a download fee, future updates are free though. it contains approx 1.9 million postcodes and is complete and correct. despite the costs it seems to be recommendable for commercial projects given the completeness of the data and the update-service.

This immediately smelt a bit funny, so I headed off to their website. First I noticed the company was registered in the British Virgin Islands, which looked slightly odd. Next I checked the IP address of the commenter. Apparently he/she was located in the Philippines, which also seemed a bit strange for someone talking about UK postcodes.

So I’d be inclined to think this may not be the best company to buy UK postcode data from. But more importantly, this level of postcode data is available for nothing, with a few caveats (Northern Ireland, Channel Islands and Isle of Man are missing). Just grab it direct from the Ordnance Survey or from my website or a host of other sites packaging up the data in various ways.

Not that there is anything necessarily wrong with paying for postcode data, I provide the data for nothing and don’t promise to provide any kind of level of support, though I try to answer any questions people have. So if you want some kind of guaranteed support, paying might make sense.

One thing the free postcode data is missing is address level data. Whereas there are 1.8 million postcodes, there are 28 million addresses in the UK. To get hold of this data, you will need to pay money. And if you do want to pay for postcode data, this is almost certainly the dataset to buy, since it probably won’t cost much more than the smaller dataset and is much more versatile. And if you do decide to buy this dataset, I suggest buying it from one of the Royal Mail’s approved resellers, rather than some random dodgy site.

Update – I’ve only just been made aware of the fact that even the PAF dataset can be free if you are a small charitable organisation or a micro business. I’m not sure of the exact requirements you need to meet to get it for free, but it is certainly worth looking into.

Friday, September 07, 2012

Windows 8 start screen and search is broken

imageBefore I start, I have to point out this is not a me too complaint about not liking the new Windows 8 user interface. I have no problems with it. Or at least I didn’t have until it started to look like this, with no icons. If I press the little [–] button at bottom right then small versions of my icons appear and I can then see the full size versions of them if I click somewhere on the screen. But if I want to search for an app, although Windows says there are apps there, nothing appears in the main window. Search results for settings and files do appear however.

 

image

I have no idea how it got into this state, or why, or how to get my icons and search results back. Since this is, I think, the only way to get to applications, this is kind of frustrating. It seems I now have to search round in Explorer to find the relevant EXE…

Update -  Turns out the fix for this is the old favourite, a reboot…

Tuesday, September 04, 2012

Windows 8 - The Module DLL C:\Windows\system32\inetsrv\rewrite.dll failed to load

After installing Windows 8, one of my AppPools in IIS kept stopping with the error ‘The Module DLL C:\Windows\system32\inetsrv\rewrite.dll failed to load’ appearing in my Event Log. Since I’m not really using the IIS URL Rewrite module, I tried removing it from IIS, but this didn’t fix the problem. But uninstalling it via Control Panel did fix the issue. Not sure what the underlying problem was and obviously this isn’t a great solution if you are using the URL Rewrite module, but it worked for me!

Friday, August 24, 2012

Windows 8 – what’s all the fuss about?

I’d read a lot about what a bad OS Windows 8 is for desktop systems, since it’s all about adding features for use on tablets. So being the masochist I am, I thought I’d install it on my desktop machine, a none too modern Dell box with a couple of monitors. Several hours later, it was done and I hit my first problem. Windows didn’t like my mouse. This made navigating round the new user interface a little tricky. But after swapping out the mouse for another one, things got better.

So the big complaint about Windows 8 is that the Start button is no more. But move the mouse to the bottom left of the screen and a little Start popup appears. Click on that and most of your apps are listed. For the ones that aren’t, just start typing and a list of matching apps appear. And here’s the important thing about that search facility, it’s much faster than the same search functionality in Windows 7, which always seemed to hang for seconds before doing anything. The learning curve for this was about 5 minutes, although I have to admit I do occasionally mistakenly click on the task bar rather than the Start popup.

So the biggest issue seems to be a non issue, for me at least. The things that I like so far are much faster boot times, a task bar that stretches across multiple monitors and a much improved Task Manager. Nothing revolutionary but welcome none the less.

I then installed it on my laptop. Much the same experience, although Minecraft no longer runs due to my graphics card driver not supporting OpenGL. I am not popular with my daughter.

There are shedloads of new things in that Start screen, but as a desktop user I was more concerned about getting to all the stuff I currently use and that all works fine. So what’s all the fuss about?

Thursday, August 09, 2012

Executing multiple SQL statements against multiple databases

In my day job, each of the customers running in our hosted environment have their own SQL Server database. As we develop the software that runs on top of these databases, we often need to update the schema of each database. I knocked together a little console application in C# to do the job and here are the interesting parts of it. First, we need to get a list of the available databases, which can be achieved quite easily.

      List<string> DBs = new List<string>();
      // get list of available databases
      SqlCommand command = conn.CreateCommand();
      command.CommandText = "select * from master.sys.databases where DataBase_ID > 4";
      using (SqlDataReader reader = command.ExecuteReader())
      {
        while (reader.Read())
        {
          DBs.Add(reader.GetString(0));
        }
      }
      DBs.Sort();

Next, we need to execute the SQL updates. This isn’t quite as easy as you’d think. If you want to execute multiple SQL statements with GO statements between them, SqlCommand.ExecuteNonQuery won’t handle them. Fortunately SQL Server comes with some assemblies that solve the problem. So you need to add references to Microsoft.SqlServer.ConnectionInfo.dll, Microsoft.SqlServer.Management.Sdk.Sfc.dll and Microsoft.SqlServer.Smo.dll. Once they have been referenced, the following code should be able to handle any SQL you throw at it.

      foreach (string database in DBs)
      {
        Microsoft.SqlServer.Management.Smo.Server server = 
          new Microsoft.SqlServer.Management.Smo.Server(new ServerConnection(conn));
        server.ConnectionContext.ExecuteNonQuery("USE " + database + "\nGO\n" + sql);
      }

Tuesday, July 17, 2012

Lets build a socialist network

It was five years ago. We’d driven down to Spain to see my dad and as we sat in his living room I was amazed to see my teenage nephew and his mate typing ferociously on their laptops as they chatted away on the social network du jour (I’m guessing Facebook but I might be wrong). I remember thinking at the time what would happen if we could harness all that energy into doing something productive.

What I hadn’t realised is that Facebook had already figured out how to harness that energy. Most websites (ignoring the ones that sell stuff) draw viewers in by producing interesting content and make their money through advertising on the site. Facebook works in the same way, but it doesn’t produce its own content, it gets its users to do that. In fact it’s a brilliant system since the content that is produced helps to decide what adverts should get shown, but I can’t help feeling there’s a better way. If I write some content, I want to have the chance to earn some income from it. I know from my experiences here that the chances of me making a reasonable amount of cash are pretty low, but I still think the system where the advertising network takes a cut and the content producer takes a cut is a fairer approach.

I think there are two approaches possible. The first is to build a competitor to Facebook, where the users take a cut of profits. I think this could have a few problems, how do you decide who gets what?, how do you stop fake users signing up just for a cut?, how do you stop click through fraud to increase earnings?

So here’s another option, we develop open protocols that allow different sites to hook up together and provide similar functionality to Facebook (and Twitter and Google+ and LinkedIn). There’s not a lot to it as far as I can see, the basic actions are add a friend, follow someone (that’s pretty much RSS), like something, send a message to someone and publish a message (that’s essentially a blog post). None of it is rocket science. And then we all have a choice. A geek like me could mash all my social networking stuff together on my own site and have the chance to earn some money. Ordinary users could continue to use the services they want, new services would crop up that aggregated all your social networks together. Everyone wins…

Sunday, July 15, 2012

Saturday, July 07, 2012

Bike It example Windows Phone app source code

I started to write my own biking app for Windows Phone then found an app that was much better than I could hope to achieve. So here is the source code for my app, which might be useful if you want to do something similar, or just want to see an example Windows Phone app. Be warned, the code is not particularly pretty.

Tuesday, July 03, 2012

Endomondo and the app that will never be

I’ve written before about the two bike apps I’ve found for my Windows Phone, MyBikeMap and MapMyRide. I was so convinced that they were the only two options available that I started to write my own bike app. I got quite far with it, then I noticed a new app, Cyclocomp. I downloaded it and was quite impressed but decided it had a fatal flaw, it lets the phone go to sleep, the same problem that MapMyRide had. Wondering if I’m doing something wrong or am using these apps in a way nobody else is I had a look around for a review of it. That led me on to another app Endomondo. So I thought I’d give it a go and was immediately impressed.

The user interface is simple and elegant, the displayed stats can be configured to whatever you prefer, the map takes up the whole screen and you can even receive pep talks (and you can turn them off!). And even better, the data gets uploaded to the Endomondo website where you can view the map and see lots of geeky stats about your rides. And you can even enter challenges with other users, challenges that I am bound to lose since there’s clearly some very fit, active people on there. My only complaint is the map occasionally seems to get confused and stops showing the trail of where you’ve come from. But for free, it’s pretty much perfect.

And it rather puts my feeble effort to shame, so I guess my bike app won’t be seeing the light of day…

Thursday, May 24, 2012

I don’t rate Rated People (or maybe I do)

You’ve probably seen the adverts where Phil Spencer, the man whose remarkable negotiating skills can sometimes get £5,000 knocked off a £500,000 house purchase, tells us about this remarkable website which can connect us punters with local tradesmen. To me this seems like a good idea for a website and I have some work that needs doing, so thought I’d give it a spin.

So I filled in my details, entered the job details and waited for a response. And then, nothing. OK, not entirely true, I received a couple of text messages and emails. A couple of days passed and I received an email telling me that I hadn’t had a response and maybe I should expand on my job description to get a response. So off I went and updated the description and hit submit and then I was presented with a 404 error (for the non technical, this means the website is broken). So I tried again and got the same result (definition of insanity - doing the same thing over and over again and expecting different results). And I gave up at that point.

OK, slightly annoying, but no worries, I’ll drop them an email and let them know and I’ll update the description later when it’s fixed. So I go to their contact page. I can ring them, but not at this time or I can send them a tweet or write on their Facebook page or add a comment to their blog. No feedback form, no email address. I didn’t particularly want to berate them on a public forum, maybe the problem is something specific to me, so none of those options appealed. Yes, yes, I see the irony, I am now berating them quite publically (hello my many reader), but I’m annoyed now.

So, so far, Rated People is something of a failure for me. I think if you’re going to be spending a bunch of money on TV advertising, quite a bit of effort should also be spent on the product…

Update – A funny thing happened today, I got a call from Rated People, specifically due to this blog post. I’ve ranted about a few companies on here and never got any response from the company involved, so it was a pleasant surprise to get some feedback. I should also say that I did eventually manage to update my job description and also got a response from an interested builder, who is repairing my pointing as I type. So it would appear my initial review of Rated People may have been overly negative. And what’s more, Phil Spencer is no longer doing the voice over on their ads…