Guy and his Travelling Macbook… is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

Say no to Guilt Upon Accusation in New Zealand

February 19th, 2009

New Zealand's new Copyright Law presumes 'Guilt Upon Accusation' and will Cut Off Internet Connections without a trial. Join the black out protest against it!.

Apparently our country has decided that it is ok to terminate your internet connection because of a mere accusation of breach of copyright (ie downloading copyright material). It’s not so much that I care about whether or not I can download copyrighted material, but to make a law which implies guilt without trial is to open a can of worms that leads to a very dark end.

K2.Net 2003 Virtualisation Issues

January 28th, 2009

We recently virtualised our production K2.Net 2003 server and were faced with one key problem: an invalid license key. Now this in itself is not a big deal, it is pretty easy to get a new license key out of SourceCode - they are really good on their customer service - but it did take me a while to realise that this was the problem!

My tale of woe started off with me trying to access the K2 Service configuration on the shiny new virtual server, but coming up against the message box of doom: Authentication with the server failed. I proceeded to try every trick in the book to sort out an authentication issue: credentials, authentication package, the DisableLoopbackCheck registry key - nothing worked. As it turns out, my problem wasn’t authentication in the traditional sense, and the key indicator of this was that my Security Event Log was clean the whole way through.

So, having decided that it was nonsense that my all of my event logs were clean - given that the software clearly wasn’t working - I decided to run K2Server as an application rather than a service because it gives you a very nice console showing everything that happens. Paydirt! The server was throwing an error because the license key was invalid, and not continuing to initialise. Unfortunately this left me with the issue of how to change said license key, or even how to get the new System Key in order to get a new license key. Read on to find out what I did.

If you can’t access the server configuration then the only way you can get your system key is from the installer so the first order of business was to head on over to Control Panel, fire up Add/Remove Programs and hit the Change button on the entry for K2.Net 2003. I then walked through the installer up to the license entry screen and grabbed the system key from there. Getting a new license key was very straight forward from here because SourceCode are very eager to help their customers. Now, to update the License Key for the server without using the Service Manager you must access the database and update the _Server table with the new key.

Not actually that complicated in the end, but quite scary when you have a scheduled, time-bound outage during work hours and the clock is ticking.

New Year Safety Plea

January 15th, 2009

This morning, on the way to work, I witnessed a cyclist getting hit by a car. I have my doubts as to whether the cyclist will survive. There are more and more cyclists on our roads, and this trend will continue in the future because of rising petrol prices, and environmental concern. This requires both cyclists and drivers to increase their awareness of what is going on around them.

If you are driving a car, and you are turning from one street into another, please look carefully, cyclists are easy to miss, particularly if you are turning through a gap in one or more lanes of traffic. Cyclists can often be found proceeding past stopped traffic along the left-hand side of the road, or between two lanes, and they haven’t got a chance if you suddenly turn accross their path. Secondly, cyclists are actually moving a lot faster than you think, it is often not possible to “get in ahead of them”, if it was a car you were turning across and you’d wait, then wait for the cyclist before turing as well. I know most drivers of vehicles are not out there to make life difficult for cyclists, or to hurt them, but the chances of you killing a cyclist in an arguably minor incident are quite high, and fatalities are terrible for all involved.

If you are riding a bicycle, make sure you are wearing a helmet, without one you’ll probably die from something as minor as going over the handlebars, something that happens to most city cylcists multiple times a year. If you’re moving past stopped traffic, keep an eye out for cars that are turning accross that traffic, through gaps in the traffic at side streets and the like - they’ll have a hard time seeing you, and if you can’t see the whites of their eyes, I suggest waiting until they have moved on before moving. Another thing to look for is indicators - actively check the indicators of every vehicle you come across. Also, be sure to indicate with your hands, it is pretty un-fair on drivers of cars if you just appear in front of them without warning.

I for one am glad that I don’t commute on my bicycle any more, because it really is very dangerous, and the more you ride, the more likely you are to get hurt, especially during peak traffic times. Please drive with your eyes wide open, and your brain totally focussed on the other road users around you, and cyclists please ride as though you can not be seen, and take every precaution to avoid being hit.

Portable C++ on Windows: Part 2 - Libraries

December 9th, 2008

In the previous post in my series on Portable C++ on Windows, Compilers and Command Lines, we walked through the steps required to set yourself up with a windows-based C++ development environment which doesn’t rely on the Microsoft platform. We walked through getting set up with MinGW (GCC for Windows), MinGW-MSYS (BASH for Windows) and more recent versions of the GNU Autotools for your shiny BASH shell.

This time, we will walk through building the Boost libraries and the Xerces C++ XML library. Now, I know I mentioned in the first part that we would cover SFML as well, but this comes pre-built for windows, so we don’t need to worry about that (we will cover installing it and building a small example with it in the next part of this series).

Boost

First things first, you need to get hold of the Boost libraries, and also Boost Jam, which is the Boost build system. Use the links below. If you’re from the future you might want to go to boost.org and get the latest versions, but at the time of writing the links below were to the latest versions.

I unzipped the Boost JAM archive so that bjam.exe was in c:\boostjam, and then used WEVE to edit my PATH environment variable so that the boostjam folder was on it. The next thing you’ll want to do is extract the Boost 1.37.0 archive so that you end up with a folder like c:\libraries\boost_1_37_0.

Next, fire up MSYS (make sure you are running as an administrator, especially if you are on Vista, with UAC turned on). Change directory to /c/libraries/boost_1_37_0 and then run ./configure. After this has completed you should have a file called user-config.jam. Mine looked like this:

# Boost.Build Configuration
# Automatically generated by Boost configure 

# Compiler configuration
using gcc ; 

Now open up a windows command prompt (cmd.exe) and navigate to c:\libraries\boost_1_37_0 and invoke the following commands:

copy user-config.jam tools\build\v2\user-config.jam
bjam debug -toolset=gcc stage

You’ll have to sit and wait for some time, but eventually you’ll have about 4GB of lib and dll files in the stage\lib folder.

Xerces

We’re going to cover building the Xerces 3.0.0 XML library for C++. First, you’ll need to grab the source code and unzip it into the c:\libraries folder as well. You should end up with a folder like c:\libraries\xerces-c-3.0.0. Fire up MSYS again if you closed it, and change directory to /c/libraries/xerces-c-3.0.0 and run:

./configure LDFLAGS=-no-undefined && make && make install

Again, you will have to sit for a while. When everything has completed you should be able to find the Xerces libraries in c:\msys\1.0\local\lib unless you installed MinGW-MSYS somewhere else.

That’s all for this part and I hope that everything went smoothly - if it didn’t, drop me a comment and I’ll try to help you out - next time we’ll be covering setting up the Eclipse CDT to use the tools we installed in Part 1, and also how to choose which libraries to link to.

Top Three Rules for XML

December 9th, 2008

Aside from standard things like using well-formed XML, I have three rules which I think will smooth your use of XML in your applications.

1. Use an XML Schema

Always define a schema for your XML document, using XSD and make sure your code is validating against it. Most (half)decent XML libraries will validate against a schema if it is properly referenced. You can reference your schema as follows:

<?xml version="1.0" encoding="utf-8" ?>
<rootElement xmlns="http://tempuri.org/myschema.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://tempuri.org/myschema.xsd myschema.xsd">

For more info about XSD see the w3schools XSD Tutorial, and also see my post about default namespaces in C# to get you up and running.

2. Use the XML DOM (Document Object Model)

Don’t bother parsing XML yourself, leave that for the geniuses who write the XML library you use, and load your XML into an Xml Document object - available in all (half)decent XML libraries. I can hear faint whimpers of, “What if my connection is not going to be wide enough to get the whole document fast enough?” Don’t use XML. If you are drip feeding messages over a really slow, or small connection, use some sort of binary encoding - XML is too verbose for your little pipe/bus/link/(generic inter-device connection). The DOM makes accessing your data (let’s face it, that’s all we really care about) a lot easier, especially when combined with the next rule.

To read more about the XML DOM, I recommend the w3schools XML DOM Tutorial.

3. Use XPath

XPath allows you to query right into your XML Document. No more iterating through the tree, depth or breadth-first traversing your way to a particular node. From what I gather, most (half)decent XML libraries will build up a form of index into the XML document as it builds the DOM, called an Name Table, which can then exploited by their XPath code to do fast queries of the document. An XPath query looks something like:

/rootNode/someOtherNode[@name="foo"]/box

Querying the following XML, with the query above would return one result:

<rootNode>
	<someOtherNode name="foo">
		<box>Matches the Query</box>
	</someOtherNode>
	<someOtherNode name="notfoo">
		<box>Doesn't match the query.</box>
	</someOtherNode>
</rootNode>

To read more on XPath, I suggest the w3schools XPath Tutorial.

Using XPath with a default namespace in .NET 2.0

December 4th, 2008

I have recently been writing an assembly which facilitates automatic deployment of K2.Net 2003 workflows. The assembly reads in a configuration file and deploys the workflows as specified in the configuration file. Also, rather than writing any custom code to validate the XML, I decided to use an XML Schema Definition, mainly because it saves me time and typing, but also because it’s good practice.

Anyhow, in order to use the XSD, I had to give my schema a namespace, and because I didn’t want to have to add a whole bunch of prefixes to my configuration file, I decided to use the default namespace:


<configuration xmlns=”http://temuri.org/configuration.xsd”></configuration>

This broke all my xpath queries because the .NET XPath query code does not seem to handle the default namespace. What I ended up doing to fix it was using an XmlNamespaceManager to create a fake namespace with the same URI as the default namespace, and then change all of my XPath queries to use the prefix for that fake namespace. Something like:


XmlDocument doc = new XmlDocument();
doc.Load(”configuration.xml”);
// To get the URI for the default namespace
string xmlns = doc.DocumentElement.GetAttribute(”xmlns”);
XmlNamespaceManager namespaceManager = new XmlNamespaceManager();

namespaceManager.AddNamespace( “a”, xmlns );

// Now query with XPath
XmlNodeList nodes = doc.SelectNodes(”/a:configuration/a:solution”);

With a configuration file which looks something like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://temupri.org/configuration.xsd" ... >
	<solution path="">
		<projects>
			<project name="Job Setup">
				<references>
					<reference name="" gac="false" fullname="" />
				</references>
				<processes>
					<process name="RequestLeave" />
					<process name="RequestSomethingElse" />
				</processes>
			</project>
		</projects>
	</solution>
</configuration>

The way I see it, it involves less typing than actually using a prefix. That said, given that it feels like a lazy way out, it probably isn’t the best practice because there is now a difference between my queries and my xml.

C# Developers: Comment your code!

November 27th, 2008

I was just thinking how easy it is to tag all of your code with the essential metadata it needs:

  • What does it do?
  • What are the inputs?
  • What are the outputs?

Now we can, of course, put in plenty more metadata, such as general remarks, what exceptions are thrown, examples of how to use your code etc. What astonishes me is how much code I see which doesn’t even have the essentials listed above. If you’re using Visual Studio you really have no excuse all it takes is literally three /’s and visual studio will put in the skeleton for you.

You will all comment your code religiously from now on, and then you will use Sandcastle to generate a compiled help file from it.

Portable C++ on Windows: Part 1 - Compilers and Command Lines

November 25th, 2008

Danushka and I decided to start a new game engine, and this time portability and simplicity are our two major concerns. The portability is mainly because Danu wants to use linux, and I don’t. Even if we were’t going for portability, we would probably still try to use open tools like Eclipse CDT because the Eclipse platform will allow us to maintain a completely integrated development environment for the engine, including any custom tooling needed for the engine, right through to the end-users of the engine (the game developers).

So, as you may have guessed by now, our tool-chain focusses around the Eclipse CDT (C/C++ Development Tools). In order to use this on windows, you’re going to need a version of gcc, and if you want to build any libraries you’ll probably need a BASH-esque command line replacement. So the tool-chain I am using is this:

  • Eclipse CDT (Gaynemede/3.4)
  • MinGW
  • MinGW-GDB
  • MinGW-MSYS

Also, to facilitate portable development we are using a couple of libraries, namely:

  • Boost
  • SFML
  • Xerces

This first part in my series on “Portable C++ on Windows” will discuss setting up MinGW, MinGW-GDB and MinGW-MSYS. The second part will discuss building Boost, SFML and Xerces, and the third will show you how to put it all together in the Eclipse CDT.

Part 1 - Compilers and Command Lines

These instructions are based on my experiences following these instructions. I am running Vista, and I have hand-picked a combination of the versions of the tools listed below because they worked for me. I also did things slightly differently to the aforementioned instructions because I ran into problems. If you have any problems, drop me a comment and I’ll try get back to ya.

Yout first step should be to download the following (just download them, don’t do anything with them yet):

Ok, step 2: Install MinGW to c:\MinGW.  It is a very good idea to install into a path where there are no spaces, MinGW doesn’t really like them. The post install process will run, follow it through, it’s quite straight-forward.

Step 3: Install GDB into the c:\MinGW folder. The archive contains a folder structure that is analogous to the c:\MinGW folder, so merge the two. gdb.exe should end up in c:\MinGW\bin.

Step 4 is to install MinGW-MSYS, run the installer, telling it to install in c:\msys\1.0. This will install version 1.0.10. Extract the update archive (version 1.0.11) into the c:\msys\1.0 folder. Again the archive’s structure is analogous to the installed structure so the two should merge.

Step 5: Install the msys dtk by running the installer.

Step 6: Install the latest version of m4. Make sure that m4.exe goes into c:\msys\1.0\bin

By now you should have an “M” icon on your desktop. Make sure you always choose to “Run As Administrator” for this if you are on Vista and you’re not a local admin (But don’t run it yet).

Step 7: Extract the automake, autoconf and libtool archives to c:\temp (they will each then have their own folder, eg c:\temp\automake-1.10 etc…)

Step 8: Run msys as administrator. You are now presented with a unix-esque command line. Directories are mounted so that all of your c-drive contents are under /c, so c:\temp would be /c/temp. Change directory into each of the folders extracted in step 7, and run the following:

./configure --prefix=/mingw && make && make install

If you have problems building or installing the above, you may not be running as administrator.

Step 9: Get a real text editor, like TextPad, or Notepad++ (or any other one that allows you to choose your line ending type, we want LF endings), and edit C:\msys\1.0\etc\profile. Make the following changes:

Find the line that says:

export HOME LOGNAME MSYSTEM HISTFILE

and replace it with:

export HOME LOGNAME MSYSTEM HISTFILE CFLAGS PKG_CONFIG_PATH CVS_RSH

Then add the following immediately before the line you just changed:

PKG_CONFIG_PATH="/mingw/lib/pkgconfig"
CVS_RSH=ssh
CFLAGS="-pipe -O2 -mms-bitfields -march=i686"

That’s it. Close MSYS and re-open it, and you should be away laughing. Stay tuned for the next part of the series on building Xerces, Boost and SFML (we may not have to build SFML).

John Resig Micro-Template script

November 18th, 2008

I have been doing a bit of AJAX-enabled web development today and was directed to a blog post by John Resig (the creator of jQuery) detailing a very simple piece of javascript he uses for templating. It is very, very cool, and oh so simple to use.

I will probably begin to use this more and more.

Blog theme fixed

November 9th, 2008

Having found that my theme rendered differently (and somewhat horribly) on each different browser I have updated it so that it now renders exactly the same on the following platforms and browsers:

Windows:
  • Explorer 7
  • Firefox 3
  • Safari 3
  • Chrome
Mac OS Leopard:
  • Firefox 3
  • Safari 3

This is mostly thanks to Eric Meyer’s CSS Reset which makes all of the above browsers behave roughly the same. I did find that IE seemed to ignore some z-index stuff so I had to move the bottom fixed position div above any of the content of the page. I also found that I had to set the wmode parameter of the flash video posted a couple of weeks ago to transparent because firefox, chrome and safari still rendered it on top of everything else when it was set to opaque.