Using Datamapper with Rails 4

Was trying to swap out active record for datamapper on a rails 4 application this morning and had one or two issues with gem version conflicts (I think this is largely due to DM being discontinued in favour of the not-done-yet ROM). At time of writing if you install with rails 4.0.0 and just go for the rubygems repo you’re going to get moaned at for having incompatible gems.

For a fresh rails 4 application you can get around this by installing from github and specifying “release-1.2” as the branch. I managed to get the full suite up and running by adding the following to my Gemfile (adapted from this guide).

%w{core constraints migrations transactions timestamps do-adapter rails active_model sqlite-adapter}.each do |gem|
  gem "dm-#{gem}", :git => "{gem}.git", :branch => 'release-1.2'

What does it do? Basically, it iterates through a bunch of strings interpolating those strings into a gem name and git repo name, and for each one, specifies branch “release 1.2” and gets the gem for that. Whoever maintains those repos has certainly been consistent!

Interactive fiction – a primer

Okay so I’ve just finished my first interactive fiction, The Scarecrow. I wouldn’t say this was enough for me to call myself an “interactive fiction author” and I certainly wouldn’t call myself a writer (seriously, I’m just this computer nerd from Birmingham!) but I do see it as being a bit of a milestone for me as I’ve been a fan of this genre of writing for some years now. There is a chance that through these posts, some of my friends and followers may have become interested in the genre and so I’m making this post just to give any potential fans a gentle nudge in the right direction.

There’s loads of guide online about how to get an interpreter set up, so I won’t go through that here I’ll just link to this.

In terms of authors – the landscape is pretty rich… it would be dismissive of me to just point you straight in the direction of “the ones you gotta read”, so all I’ll say is that my favorites are Emily Short and Andrew Plotkin. We’ll leave it at that.

The other thing to understand is that these days, the factor that seperates the dogs from the puppies is *quality*. Given that these works are mostly free, that means you have a whole wealth of quality literature right there and readily available, provided by a community who would be delighted if you read and enjoyed their works.

In terms of where to find good IF, this is the joint right here. Either that or a good google search.

Annually, the IF community hold a competition in the month of September (one I hope to take part in next year). The quality is always very high in the competition, this years entries should be appearing here soon. Previous years entries are also available for download from the IF database.

Anyway, hopefully this should be enough to get people started if they’re interested. Peace out \m/

The scarecrow is finished!

My first interactive fiction, “the scarecrow”, is now live for you guys to try out.

Hopefully you’ll enjoy it – the intention here was never to write a great work of fiction, it was initially just to learn the platform… but as I started to build the world I got quite attached to it so quite a lot of care has gone into this. I think enough scene-setting has already been discussed in previous posts, but in my opinion here is how best to experience this story:

1) Grab a nice big glass of red wine

2) Curl up on a couch or some other comfortable place. Dim the lights.

3) Stare at this painting by John Constable


4) Imagine the scene in the painting decaying into a rotten, barren landscape.

If by this point you want to know what is in that cottage, click this link and enjoy 🙂

Feedback is most welcome, particularly if you find yourself getting annoyed or stuck (something I’ve tried very hard to avoid happening). An entire playthrough should take around 20-30 minutes.

Edit: Just in case anyone hasn’t played IF before – remember to examine everything, and if you get lost you can “look” to see what’s around you.

Playtesting interactive fiction is TOUGH!

The IF I’m working on currently clocks in at just over 3500 words, and I’ve been writing it in a linear fashion meaning the first part of the story became playable about a week ago. With typical ill-placed optimism I’ve spent the last week testing it out on various people and have come to the following conclusion: If you present someone with a fantasy setting and ask them “what would you like to do?”, they’re going to say something ridiculous 🙂 And we totally had a laugh too – between lying down in the mud, sitting on a plough in the rain and performing unspeakable acts on a roaming cat, it was a total hoot but it didn’t get me any closer to any decent feedback.

So this is an open plea to anyone who is interested: The first 10 minutes or so of the scarecrow is online now. If anyone would like the link, get in touch. Here are the things I could do with help on;

  • General feedback on the world, is it described well enough (or, too much).
  • General feedback on the system itself. Did you try examining things that weren’t there? Did you type in commands that the interpreter didn’t understand but that you thought were totally valid.
  • Help on ideas for puzzles and texture. Possibly involving a pub lunch / day to brainstorm.

The other thing: If you are genuinely interested in reading / playing through the story, you probably don’t want to be involved in playtesting. Basically, I do need the help, but having been working on this for a few weeks I am totally sick to death of reading the same sentences over and over! This is partly why I need assistance (I can’t tell what’s good or bad any more because I’m too close to it) but equally you should probably bear in mind that if you do help me test/develop, it’ll wreck it for you too.

Anyway, I’ll leave you to mull that over. Cheerio for now!

The Scarecrow

This is just a quick post to introduce an interactive fiction I’m working on at the moment. It’s called “The Scarecrow” and is a short horror story set in Suffolk a few years after the end of the Napoleonic wars. You play the part of a nameless traveller with a mysterious past who happens upon an isolated cottage. As the traveller explores the surreal landscape they realise that not everything is as it seems. The story itself will explore themes of isolation (both literal and perceived) and whether or not someone can truly enjoy calm in the wake of a storm.

The setting is inspired by this painting by John Constable;


With additional inspiration being drawn from Frankenstein, HP Lovecraft and Slaughterhouse Five (I also realised that I have unintentionally poached quite a lot of ideas from “A harvesting Moon” by Michael White) . I am writing this mainly to explore and learn the Z-Code platform but also to attract the attention of some of my writer friends who I would like to collaborate with (hello if you’re listening!)

I don’t know when this will be done as creative writing is not something that comes particularly naturally to me (and there’s quite a lot of research involved because I know nothing about nineteenth century agriculture either – yet!) but the coding is well underway and I’m hoping to get it published within the next few months.

Here’s a sneak peek of the intro;

“In the winter of 1815, after countless millions had perished, the Napoleonic Wars came to an end. The little corporal Napoleon Bonaparte, emperor of France for the decade previous, was exiled to the volcanic island of St Helena where he would see out the last six years of his life.

The end of the Napoleonic wars saw the start of a great agricultural depression in the United Kingdom that would last for a quarter of a century. Many farms succumbed to abandonment and disrepair as both landlords and tenants fell into bankruptcy.

It is in the wake of this ruin, far from the bloody fields of Waterloo and Rocquencourt, that you find yourself standing on a long farm road in Suffolk, surrounded by fields of oat and barley. Save for the carrion crow circling above, a dull lifelessness hangs in the air like mist and you feel your heart mourning for the rural paradise now lost to time and neglect.

Five hundred miles away, in seemingly unrelated events, a young author called Mary Shelley has finished writing her first novel, ‘The Modern Prometheus’…”

I’ve felt dead creatively for so long now, and starting this has woken up that side of my brain. More updates soon!

Migrating a rails postgres based application to MySql

Had an application which started out on nginx/postgres, but needed to migrate it to apache/mysql (short summary of reason is that we had some php/mysql-compatible only apps and we didnt’ want to be running two servers). Anyway, here’s how we achieved it.

First get to the point where the application deploys to the new server. If you have your cap recipes set up like I do, that’ll mean you get the structure/indexes and so on all set up and you’ll basically have an “empty” application, save for your master data.

Once it’s there and running, we’re just going to need to do a data-dump of the postgres database, which you can do from your pg server with the following command;

pg_dump replace_with_database_name -f replace_with_database_name.sql --data-only --no-owner --no-acl --attribute-inserts --disable-dollar-quoting --no-tablespaces

Obviously replacing the bit about “replace_your_database_name” with your actual database name. What you’ll end up with is a file with *just* the commands required to do the inserts of your master data. There is some stuff you need to delete from there too though, specifically;

  • The schema migration records (those will already be in the new application from when you deployed it)
  • Any seeded data (for the same reason)
  • any references to postgres system tables (there shouldn’t be any of these if you dumped with the above)

So basically, once you have that file, you can just import it into your MySql database. I personally use phpMyAdmin, just basically open that and paste the file into the SQL tab, hit go, and there you go!

Concrete5 custom theme cheat sheet


This is a cheat sheet for setting up a custom theme in the current release of the awesome CMS “Concrete5” (which at time of writing is 5.5). This assumes that you have a bunch of static html files and you have your design all up and running within a file system. These are the basic steps to go through when you come to “concrete-fying” your site.

If you haven’t checked out Concrete5 yet, you definately should!

This is not meant to be a comprehensive guide, it’s just a quick step-by-step. Assumes knowledge of concrete5, php and basic front end. If anyone finds it useful then great.

These are, in order, the steps I go through to get a basic html template up and running in Concrete 5.

Basic Setup

Put all your html/js/css in a folder under the concrete5/themes folder

Create an additional file called “Description.txt” in that folder, first line is the title of the theme, second line is a short description.

Copy/paste the most “typical” html file in your collection, rename it “default.php”. Then within default.php…
Paste this after opening head tag:
<?php Loader::element('header_required'); ?>
Paste this before closing body tag:
<?php Loader::element('footer_required'); ?>
If you have a copyright line, use this to auto-populate date:
<?php print date('Y') . ' ' . SITE; ?>
Any relative links to stylesheets, replace with this:
<?php print $this->getStyleSheet('css/your_style_sheet.css'); ?>
Any other relative links (e.g. images, javascripts) should have this pasted before the path
<?php print $this->getThemePath(); ?>
Inside the theme folder, create a new folder called “elements” and two blank php files called “header.php” and “footer.php”

Grab all content that is “common to the top” of every page on your site (typically everything down to and including the opening body tag) and paste it into “header.php”

Grab all content that is “common to the bottom” of every page on your site (typically javascripts and the closing body/html tags) and paste it into “footer.php”

Where the header and footer used to be, place the following;
<?php include("elements/header.php"); ?>

If you have a jquery link in your templates, delete it, concrete5 will put one of these in and you can

Create editable sections

Replace global/local areas of editable content with the following (change string for each one);

<?php $a = new Area('Main'); $a-->display($c); ?>
<?php $a = new GlobalArea('HeroText'); $a-->display($c); ?>

Once they’re added, install the theme and check you have it all set up correctly. This is a good time to splat any bugs as common ones will arise at this point. Particularly common ones are;

  • Your CSS styles are conflicting with concrete 5’s css files (this will produce effects like the editable hover block / edit interface looking a bit screwy)
  • Your javascripts conflicting with the concrete5 javascripts. NOTE: make sure you haven’t included two jquerys (check console for errors).

Sorting out the nav

Add all pages in as you want them, then set up the nav. To do this;

  1. Create a folder – (root)/blocks/autonav/templates
  2. Copy the file “view.php” from (root)/concrete/blocks/templates/view.php and put it in your newly created folder
  3. rename the file to something like “header_nav_template.php”
  4. Edit the file to put in whatever custom html you want (the file is very well commented)
  5. Because we don’t really want the user adding or deleting the nav, we can hard code this block into the view using the following (replace with any options you want);

$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPages = 'top';
$bt->controller->orderBy = 'display_asc';

The setup is similar for doing breadcrumb style navs, but you insteadyou are overriding “concrete/autonav/templates/breadcrumbs” (which you copy into the same folder as above). Then to hard code this into your view you use;

$autonav = BlockType::getByHandle('autonav');
$autonav->controller->orderBy = 'display_asc';
$autonav->controller->displayPages = 'top';
$autonav->controller->displaySubPages = 'relevant_breadcrumb';

Set up your various page types

Copy/paste your “default.php” page, rename it to each of the page-types you want within your site, e.g. “2-column.php”, “home.php”. You can make any ammendments to each of these at this stage (e.g. change markup, any additional editable content areas and so on).

Once you have done this for all your templates, you can pretty safely delete any remaining html files within the theme folder.

If you uninstall/reinstall your theme, concrete5 will see these new files and will then add in the nessecary database rows to get them all set up.