[BTS] Dr Nic’s Civilizations 2.0

Posted by Dr Nic on August 25, 2006

I’m not promising there ever will be a Dr Nic’s Online Civilizations game, but it has seemed like a good idea for a few weeks, and today I went from ASCII map through to beautiful CSS rendering of the map.

6am
ASCII to HTML mapping
8am
Base tiles
6pm
Correct edges
9pm
Convert table to div structure
Simple layout of map Basic tiles Correct edges Removed table structure

I miss home.

TilesheetThis was a technically interesting process. The images used are actually all on the one base tile sheet [1], and each panel of the map is allocated a separate CSS class relating to the specific tile required.

So for example, to show the base grasslands tile, you’d need some CSS like:

.tiles {height: 30px; width: 30px; background: url(tiles.png) top left no-repeat; ...}
.grasslands {background-position: 0px -30px;}

For a desert tile, with some grasslands to the left, you might use:

.desert-left {background-position: -60px -60px;}

This really gives a nice tiling effect without you needing to do any fancy image manipulations or the user loading up lots of small images. You just assign the appropriate CSS class to the panel (a DIV or TD, for example). Want to change a tile? Change the class (e.g. using Prototype/jQuery libraries)

Yes, this solution requires lots of individual CSS class definitions; but you’re clever - you’ll generate them won’t you :)

Reader assistance required

The one technical trick that I don’t have a solution for at the moment is a Google Maps-like interface for scrolling map around. I’d love to hear from anyone with some bright thoughts on how they implement that (I don’t want to have to try to read their compact Javascript code).

Any thoughts?

[1] The source images came from the FreeCiv GPL game

[Preview] Magic Announcements

Posted by Dr Nic on August 20, 2006

While other people in the world have been doing real work, I’ve been on maternity leave. Thus in spare time, I’ve been cooking up something much more fun…

Today, you get to see a magic trick. No code to download, no brain cells to engage. Its Sunday after all. A day of rest, BBQs, beer, football, and magic tricks. Everyone knows that.

But I can’t show you the trick here in your feed reader… the lighting is terrible. Jump to my site for the live magic show itself.

…pausing…

Ok, at the top of the screen… I introduce to you the Magic Announcements. They are just brilliant, and good looking to boot.

Once you’ve read each one, you click on them to make them go away and they will never return. Once you’ve read the announcement of verson 0.7.1 of Dr Nic’s Magic Models, you will never see another announcement until a new version is released (be it 0.7.2, 0.8.0, or 1.0.0, etc). Nod your head with me, this is cool.

When you get your hands on this, it will be a pure Javascript install into any page (or domain of pages such as a blog). It will fetch announcements AND version change information from anywhere on the web, not just the presentation site. For example, the version information for the two projects are being retrieved from the project home pages themselves. This way, I never have to modify my blog to enter new announcements or versions: I just update the relevant data at the relevant place.

How cool is this? Imagine if you could plug the Magic Announcements directly into RubyForge or SourceForge, etc, and whenever you released a new version of your code to *Forge, your blog automatically started announcing it to your readers! Keep nodding, sexy, yes.

I’m still writing up the install/usage docco for it, but I hope to release it within a day or two.

But to give you some preparation time, for each project you want to provide announcements for, you will need to create files that look like this:

MagicAnnouncement.show('magicmodels', '0.7.1');

If you want to provide generic site announcements, like “Welcome to my website”, then it will look like this:

MagicAnnouncement.show('general_notes', 1,
  "Very rarely, you\'ll learn something here. Mostly, you'll just be entertained by the programming magic.",
  "<strong>Welcome to Dr Nic's Magic Castle of Programming Mystery</strong>");

In both cases, the 2nd argument is the announcement version number. The 3rd is an additional description (useful for version announcements and site announcements), and the 4th is for the header. You’ll normally want the header to be generated for you for version announcements, as per the Magic Models and Composite Keys announcements above.

Bonus: want to see the announcements again? Turn on the Debug Controller

[Trick] Live Version Numbers on your blog

Posted by Dr Nic on August 16, 2006

There isn’t much connecting your open source projects - written in one language and possibly stored on a SourceForge/RubyForge server - to your blog - written in some other language and stored on a different server. Pity.

Sure, you can list your available projects/gems/plugins/libraries on your sidebar, and that’s great for new visitors but what about the old warhorses? What about the people who actually use your code? It would would be snazzy to inform them if a new version of your projects was available.

Sure you can spam your entire subscription list about every minor update. And during the lean weeks, you might just do that so people know you’re alive. But you’re a professional, and you want something cool. Something automatic and, dare I say it, magical.

Today, we’ll just do automatic. Tomorrow, soon maybe, we’ll all share a newer, improved magical version! Kazzam!

Screenshot of site - 16th August 2006If you look on the sidebar of my site - http://drnicwilliams.com - you’ll see the dubiously short list of my projects - Composite Primary Keys and Dr Nic’s Magic Models. Your keen eyesite will notice version numbers next to them. On the assumption I’ll change the site one day, here is a screen shot…

The version numbers are not stored at http://drnicwilliams.com - they are both stored at their respective websites: http://compositekeys.rubyforge.org and http://magicmodels.rubyforge.org. This is the super best part - once I start a new project and add it to the list on the sidebar, I never need to touch the blog templates again. Automatic. Almost magical.

Tourists and weary travellers can check if a new version of any project is available whenever they visit the site. If they don’t visit the site because they use feed readers, then now they have a reason to visit the site. Weird logic. Look, the next release of this idea will be so super cool that all your readers will just HAVE to come to your site. I promise. Perhaps you can flog some advertising. Anyway, your mother will be impressed.

How do I get sweet Live Version Numbering love for my projects?

What follows below will work for your 100k line mega-framework down to your 10 line Rails plugin. As long as you can create and modify one file on your project’s website.

Let’s call that file version.js, and give it the following innards:

var myproject_version = "0.7.1";
document.write(" - " + myproject_version);

This is a small Javascript program that you will run within your blog to generate the version number. Its separated on to two lines so that it will be super easy for you to change the version number whenever you need to in the future.

Let’s say you’ve saved this file at the web address: http://www.myproject.org/version.js

Now, modify your blog to include your homebrew wizardry. Go to the templates, and edit the sidebar, or wherever you already have your projects listed. NOTE: if you currently have the projects generated for you from a blog list (like in Wordpress) then you’ll need to stop using the list generator, and hand craft the html yourself. Be a man, its only one time.

For me, my original html for the two projects was:

<li><h2>Open Source Projects</h2>
	<ul>
	  <li><a href="http://compositekeys.rubyforge.org">Composite Primary Keys</a></li>
	  <li><a href="http://magicmodels.rubyforge.org">Dr Nic&#039;s Magic Models</a></li>
	</ul>
</li>

To get the Live Version Numbers working make the following changes:

<li><h2>Open Source Projects</h2>
	<ul>
	  <li><a href="http://compositekeys.rubyforge.org">Composite Primary Keys</a><script src="http://compositekeys.rubyforge.org/version.js" type="text/javascript"></script></li>
	  <li><a href="http://magicmodels.rubyforge.org">Dr Nic&#039;s Magic Models</a><script src="http://magicmodels.rubyforge.org/version.js" type="text/javascript"></script></li>
	</ul>
</li>

Let’s call this Cross-Site Scripting; other people do. If the javascript wasn’t coming from a known site - your project site - it’d be considered a security problem.

So now you have Live Version Numbers working, what do you do if you release a new version of one of your projects? You change the version number in the version.js file. You score extra points if your release mechanism can automatically update this value for you.

The future of Live Version Numbers - the Magic Edition

What your readers really want is an “in your face” notification or dropdown box if they need to know about a new version. Yes you could do a dedicated RSS feed instead/as well, but we’re trying to impress people here. RSS isn’t impressing anyone: if they understand it, they’re not impressed; if they don’t understand it, they’re not impressed.

So, the future version will include cookie support and magical information boxes to inform each individual visitor about changes to projects. This will definitely be magical. Your mother will know her school fees did some good.

[ANN] Dr Nic’s Magic Models

Posted by Dr Nic on August 07, 2006

Magic hatWelcome! Welcome! Welcome! Ladies and Gentlemen, today you shall be thrilled and dazzled by wonders of magical mystery. Dr Nic’s Magic Models will now be unveiled to all. Mystery and magic that you will be able to perform at home.
Within your ActiveRecord models, never again will you need to write:

  • validates_presence_of validations
  • has_many and belongs_to statements
  • has_many :through statements!!

And for the finale, you will be amazed and astounded as you watch ActiveRecord models appear from nowhere. No class definition, just any old database tables you have lying around the home is all you’ll need to perform this trick!

No cover charge. No free steak knives. No heavy lifting involved.

Installation, DIY magical instructions, and a world of mystery awaits you at:
http://magicmodels.rubyforge.org

Original forum notification: http://www.ruby-forum.com/topic/74957

UPDATE: Digg this!

UPDATE 2: Conversations about the Magic Models have been conducted on Ruby/Rails forums too: