K!

by Karl Bunyan

Programming, PHP, JavaScript, .Net, motorbikes, pubs, poker, football, news, restaurants and anything else

Facebook
http://twitter.com/karlbunyan

Medieval, Total War

"Medieval, Total War" is the latest drain on my time. The PC game is fantastic. A quick rundown: take control of a medieval faction and try to conquer the whole of Europe. Gameplay is like a cross between Risk and Sim City for the strategic Europe-wide map part, and then you get to control your army on the battlefield. Note that as a general you don't get to control the fight, only order the units. And they may not do what you expect them to...

The depth of the game is huge. As the Italians I was a Catholic faction, until I made the mistake of invading Hungary (more Catholics) and, after ignoring the Pope's warnings, was excommunicated. England then cancelled their alliance because it conflicted with their alliance with Hungary, and Germany declared a crusade. So, I invaded Rome and put a puppet Pope in place and the excommunication was cancelled. A few years later the old Pope led a bit of a rebellion and I had a fight on my hand. At the same time the French decided to join and I'm in the midst of a full-on war with them, but at least I managed to marry a princess to the King of England and have a good alliance with them at least. (The English can always be counted on to do a bit of French-bashing ;-)). And that's just a summary of a few evenings of play. Now that "Rome, Total War" has come out you can pick up "Medieval, Total War" for about half the price of a new game and with the "Viking" extension pack. I haven't even had time to open the box to see what that is yet.

The battlefield is excellent fun, too. I bought the game as I enjoyed the battles in "Shogun, Total War". Controlling armies is quite tricky to start with, thought there are some basic tutorials. Getting to grips with the subtleties of troops takes a bit longer: peasants will turn tail and run at the first sign of anything, spearmen are good against cavalry, cavalry are best used to charge and then pull out etc. Taking a view of the landscape and placing your troops in the best positions also takes some thinking.

All in all: I'm finding this game absolutely fantastic.

Total War community
Activision's Medieval, Total War website
By Medieval, Total War

Link to this post

Comments:

This post has been removed by a blog administrator.
posted by Anonymous Anonymous : November 25, 2006 5:38 AM  

Post a Comment

Frankensteinway video photos

My band (Frankensteinway) is in its first music video. Not one with the highest production values, granted, but I've managed to get hold of a couple of screenshots:

Myself (left) and Jason:
Frankensteinway video - Karl and Jason

Mark (left) and me:
Frankensteinway video - Karl and Mark

Link to this post

Comments:
Post a Comment

Fantasy football update

A pretty good week for the team. We've gotten rid of Beattie and bought Roonie instead (definitely a bargain), and dumped Queudrue as he didn't seem to be getting us many points and now Rio Ferdinand is in at the back. This gave us a few points in the Arsenal/Man Utd match last weekend, although with Lehman in goal that left us a few points lower than I would have liked.

Still, after dropping down to 4th we're now joint 3rd and all catching up on the 1st place man who doesn't seem to have been watching his team as closely as he should. Now my only worry is a) too many Arsenal players and b) too many Man Utd players. Arsenal are certainly not playing the "1-0" game of old and although they're not losing (except the once...) they keep letting in too many goals.

So, the next quandry is: a new goalkeeper? Tottenham were looking like a side that people are having trouble scoring against, until beating Bolton 4-3 on Wednesday. Other potentials are Everton's or Liverpool's, though I don't fancy too many Liverpool players whilst Gerard is still out. Hmmmm....

Link to this post

Comments:
Post a Comment

The Gothic Temple, Landmark Trust, Stowe

Having just come back from a trip to Landmark Trust's 'Gothic Temple' in Stowe I can absolutely recommend it. Staying in a temple in the middle of dozens of acres of National Trust grounds is fantastic. The temple has a triangular footprint wrapped around the central circular (domed) space with turrets at each corner of the triange. One turret is the stair tower, the other two are bathroom and kitchen (ground floor) and double bedrooms (first floor).

The nearest pub (The Queens Head) is a bit of a trek. The walkable route involves the back gate to the grounds being open; this is supposedly Wednesday to Sunday but we found it closed on Sunday. There is a small wall to climb down and a field to trek across which we didn't find too much trouble. The food in the pub is definitely worth the journey, though, although unfortunately they get fully booked up on a Sunday.

The grounds of Stowe themseves can also occupy quite a few hours. There are a number of follies and temples in the gardens, all positioned for views and generally not as interesting once you actually get near to them. Other sites nearby:

The Rothschilds place (can't remember the name of it), which was extremely decadent and interesting mainly for Baron von Rothschilds general lack of taste.
Silverstone: just about within earshot, but didn't go any closer.

For booking the Gothic Temple contact The Landmark Trust.

Link to this post

Comments:
Post a Comment

TRUNCATE TABLE on MySQL InnoDB databases

Having come up against the extremely poor performance of using TRUNCATE instead of DELETE on MySQL InnoDB tables (see previous post MySQL Truncate slow performance problems) I thought I better come up with a solution that didn't mean leaving a table to clear for an hour.

The solution is to use a combination of SHOW CREATE and DROP. DROPping a table is very quick indeed, so as long as you have the CREATE code to hand then it's a simple matter to empty a table. The main thing to watch out for with InnoDB tables is foreign key constraints which are easily disabled.

Some sample code to use this from within PHP is shown below

function truncateTable($tableName)
{
   //Grab the code to create the table
   $sql = "show create table " . $tableName;
   $dataSet = DataHandler::loggedDbQuery($sql);
   $result = $dataSet->fetchRow();
   $createSQL = $result["Create Table"] . ";
        SET FOREIGN_KEY_CHECKS=1;";
   //Drop the table. We have to disable foreign key
   //checks, which means running the whole thing
   //from the command line
   $sql = "SET FOREIGN_KEY_CHECKS=0;
      drop table " . $tableName . ";".
      $createSQL;
   DataHandler::multipleDbQueries($sql);
}

This is used in conjunction with a static method I've created to run a standard (single) SQL query from within PHP called DataHandler::loggedDbQuery (which works with PearDB, which is where the fetchRow() method comes from) and a multi-line query function I have developed and wrote about in Multiple SQL queries using MySQL and PHP and referred to as DataHandler::multipleDbQueries($sql).

Link to this post

Comments:

If you had an admin tool, similiar to navicat it automates a great deal of this for you. navicat I literally select a table.. hit design save the design as the new table and drop the old. Its instant. Hope that helps. Also does synchronization and all sorts of nerd-stuff ;)
posted by Anonymous Ryan Turner : September 02, 2005 1:23 PM  

Navicat doesn't seem to solve the problem of truncating within code at runtime, though. It appears to be a database design/editing tool whereas I was having the problem of deleting data at runtime and having it take so long on an InnoDB database.
posted by Blogger Karl Bunyan : September 02, 2005 1:29 PM  

Post a Comment

Multiple SQL queries using MySQL and PHP

Something that I've had problems with using MySQL/PHP is the limitation of only being able to run one line of SQL at a time. Using something such as Microsoft SQL Server it's possible to write multiple lines of SQL and run it all in a single database call. Until stored procedures (in MySQL 5) are available (i.e. when it seems that the database engine is ready for a live environment) I've put together the following static method 'hack' using PHP's exec() function (assuming you're using PHP 5's object syntax - otherwise just paste the code into a regular function):

class MySQLInterface
{
   public static function multipleDbQueries($sql)
   {
      $file = fopen(TEMP_CSV_LOCATION .
         "temp_query.sql","a+");
      fwrite($file,$sql);
      fclose($file);
      exec("mysql -u " . DB_USERNAME .
         " --password=='" . DB_PASSWORD .
         "' " . DB_NAME . " < " .
         TEMP_CSV_LOCATION .
         "temp_query.sql");
   }
}

What this allows you to do is to pass in a SQL string and have it executed as if it was being run from the command line. This is especially useful if you need to disable foreign keys for some reason. e.g

$sql = "SET FOREIGN_KEY_CHECKS=0;
   drop table oldTable;
   SET FOREIGN_KEY_CHECKS=1;"

MySQLInterface::multipleDbQueries($sql)

Downsides of this are

  • Requires command line access to mysql
  • Liable to SQL injection

Since i'm working within an internal system I have control over both of these and the code seems to work particularly well.

Link to this post

Comments:

Hi, I had to use the same method for executing multiple MySQL statements with PHP from a dump file. OK, it works, but how do you handle MySQL errors?
What I do:
exec("mysql -v -u user -ppass dbname < rcfile.sql",$output,$how);

So, it works but I get the same output in the browser - even when MySQL error acquires?
posted by Anonymous Anonymous : December 17, 2004 4:02 PM  

and giving a unique filename and then deleting the file would be nice as well, for avoiding overwriting issues
posted by Blogger Georgi Mateev : March 26, 2007 4:37 PM  

and giving the file some unique filename and deleting it at the end of the function would be nice for avoiding overwriting issues. Anyway, the exec() command is usually turned out for security reasons. Any other ideas?
posted by Blogger Georgi Mateev : March 26, 2007 4:39 PM  

Post a Comment

Optimising MySQL a query with packed keys

I've been learning more about MySQL lately and particularly optimising SQL queries on large tables. Large, in this case, being at the moment hundreds of thousands of rows but soon to be millions. One of the problems I've had is that MySQL sometimes decides not to use an index even when a handy one seems to have been created for it. The root of this appears to be to that with B-tree indexes if there are a large number of records with similar looking values then the MySQL engine may decide that it's just as much effort using the index as to search the whole table.

The answer appears to be adding PACK_KEYS = 1 to the end of a create table, or running the SQL command ALTER TABLE MyTable PACK_KEYS = 1 once the table has been created. In effect, this takes account of the similarity of adjacent keys. In our case we have a large column of field type bigint(21) where the starting digits of the index are timestamp generated. So, at present, we end up with a few tens of thousand rows all starting with 108xx. Enabling packed keys means not only that the index is smaller as MySQL only needs to store the differences between keys (plus an extra byte to keep track of where the similarity starts) but also that the index is actually of some use i.e. doesn't become a large, flat structure.

One down side of using packed keys is that inserts are slower, but given that the system we are building is inserting each row once and then (in theory) never touching it again that's a small price to pay. The other major drawback, however, is that packed keys only works on MyISAM tables at present and not InnoDB. This actually isn't much use to me as the large inserts we occassionally have to do would end up with MyISAM locking the table for perhaps an hour or more.

Pack keys reference in the MySQL manual

Link to this post

Comments:
Post a Comment

Restaurant review: Gili Gulu sushi restaurant, London

It's hard not to know about Yo Sushi, the 'famous' conveyor belt sushi restaurant, but what's not so well known is that the idea is almost a direct import from Japan where such restaurants are more common. Gili Gulu is another along the same vein in central London just off the main stretch between Leicester Square and Covent Garden.

One of the big things that you'll notice about Gili Gulu compared to Yo Sushi is the price: the set meals are more than enough for an early evening snack and come in at £7.50 for either a large noodle dish and three sushi's or miso soup and 6 sushi dishes. Very good value and even with a drink on top you can have a reasonable meal for around £10. The buffet is more of a blow-out experience but for around £11.50 it's all you can eat, including any of the noodle dishes off the menu.

The interior is well presented but informal. The tables are ideal for groups of four, yet the bulk of the seating is based around the conveyor belt which snakes around the space. This is ideal for a couple or if you're on your own. Once you're sat down and have decided which of the menu choices to go for you simply watch the food go past and pick up anything that you like the look of. In comparison to Yo Sushi there is not the same range of dishes, and Gili Gulu is lacking some of the more time-intensive sushi rolls, but at a much reduced price I certainly aren't complaining. There's a choice of rice and raw fish sushi rolls, with a light spread of wasabe, as well as a few cooked dishes for the less brave. On the conveyor belt you'll also find dumplings, plates of noodles, peas in their pods, and a few 'tourist pleaser' dishes such as chicken on skewers, spring rolls and prawn crackers.

The main failing of Gili Gulu, though, is that at busier times they often don't have enough staff. Although the food from the conveyor belt is self service the idea of free tea refills loses its appeal if you can't attract the attention of someone with a tea pot. Not being a sushi expert I can't comment on the authenticity of the food but having sampled the Yo Shushi experience (and it is still more of an experience) I can't say I have noticed any shortcomings.

Gili Gulu is a great place for a quick, informal meal before an evening out or at the end of an afternoon in town. It's certainly not an upmarket restaurant but if you're in the area and fancy some fast but stylish food then I think it's hard to beat.

Address: Gili Gulu, 50-52 Monmouth Street, London, WC2
Nearest tube: Leicester Square or Covent Garden.
Review of Gili Gulu on London eats

Link to this post

Comments:

DO NOT GO NEAR THIS RESTAURANT. I had the worst experience EVER. Not only did I get shouted at for moving my chair, the incompetent and rude saff couldn't seem to cope with people ordering what they wanted on the menu rather than going for the dreadful set menu. If that's not enough to put you off, I had my mobile, ipod, purse and credit cards stolen from my bag which was BETWEEN MY FEET. Being the only party in there I can only assume that this was the staff. I have been back to the 'restaurant' twice to ask for CCTV footage and have been literally shouted out of the place in front of customers. I cannot believe a place like this can exist. Being London, of course there's nothing I can do and I'm forced to take losing everything of value as 'one of those things'. Avoid this place at all costs.
posted by Blogger Melanie : January 09, 2007 10:01 AM  

Gili Gulu ceased trading and closed shortly before Christmas 2007.
Shame really, because when I first went there about 5 years ago it was really great but slowly the standards of food declined and although I found the service adequate and typical of the ethnic origins of the staff I never had any bad experiences there during my 15 or so visits. In the last 18 months I did notice that there were fewer items of quality on the belt and the place was obvously in decline. I hope someone else can make the "all you can eat" concept work either in the same infrastrucure or somwhere else.
posted by Anonymous Anthony : January 05, 2008 2:30 PM  

Post a Comment

PHP 5 class constants and subclasses

Another one of those 'I wish PHP 5 did this...' moments has occurred to me with class constants. The addition of constants is good but the problem is when it comes to subclassing. The code on the PHP 5 site:

class Foo {
   const constant = "constant";
}

echo "Foo::constant = " . Foo::constant . "\n";

is fine. Of course, what you really want to have is a method to give you the constant in case you want to change the workings later:

class Foo {
   const constant = "constant";

   public function getConstant(){
      return self::constant;
   }
}
$foo = new Foo();
echo "$foo->constant = " . $foo::getConstant() . "\n";

and this works too. The problem is that if you decide a subclass needs a different constant value, so we add

class Bar extends Foo {
   const constant = "bar constant";
}

If we then call

$bar = new Bar();
$bar->getConstant();

then the value returned is "get_constant" i.e. the value of the constant in the parent class. This is because Bar has no handler for getConstant() so it uses its parent. That's fine, but now we're in the parent context then Foo::constant is returned through the reference to self::. The way to get round this (that I have found) is to put a copy of the getConstant() method in each of the subclasses. This kind of defeats the purpose of inheritance in this case.

class Bar extends Foo {
   const constant = "bar constant";

   public function getConstant(){
      return self::constant;
   }
}

Now we call

$bar = new Bar();
$bar->getConstant();

and the correct value is returned. Of course, the other way round is not to use constants at all but to put the value in a private variable, but then what use are constants?

Link to this post

Comments:

meep
posted by Anonymous Anonymous : July 14, 2005 7:33 AM  

Post a Comment

Archive

Current Posts

Other links

Change the background image