Hexaflexamaps

Looking through a very old copy of Martin Gardner’s Mathematical Games, I stumbled upon his article about Flexagons and thought “what would these look like with maps on them?”. This is what they look like (at a really low resolution), but it is much more fun to make your own…

Video of hexaflexamap flexing.
(more…)

November 12th, 2008 - Posted by Matt Amos in ruby, tips | | 4 Comments

Where’s interesting?

Visualising geographic statistics usually means drawing a coloured map (called a choropleth), but this can be confusing as the human brain tends to associate importance with the area covered. For example, first impressions of the choropleth for the U.S. presidential elections would give the misleading impression that the Republicans won, as 56% of the map pixels are red. However, there is a different style of maps (called cartograms) in which the map is warped such that the area is proportional to the data being visualised.

We can use cartograms of OpenStreetMap data to present a more visually striking and interesting view of the world. For example, here is a cartogram of the distribution of Points of Interest (POIs). It is immediately obvious that most of the POIs in the world are either in the United Kingdom or Germany, but there are other interesting POI-rich pockets; the Philippines, Brasil, South Africa and Eastern Australia. Many thanks to all the contributors in these areas for their fantastic work!

Derived from OpenStreetMap data, CC-BY-SA OpenStreetMap and contributors

(more…)

November 7th, 2008 - Posted by Matt Amos in openstreetmap, tips, tools | | 4 Comments

Add Custom SQL to Rails Active Record Migrations

Ruby on Rails’ Migrations offer a nice alternative to traditional SQL DDL statements, that fit in with the Rails agile development philosophy. Migrations let you use Ruby code to create, alter and drop databases and tables, allowing you, amongst other things to switch databases mid-development, without having to refine your SQL.

Such convenience can sometimes mean a lack of flexibility. If you are trying to add a column to a MySQL database with type bigint unsigned, you’ll run into problems as ActiveRecord does not support unsinged bigints. You can solve the problem with some creative use of Ruby’s command line execution features - any code in a ruby file that is included between backticks(’ ` ‘) will be executed as a command line argument - so now you can include custom SQL statements without losing the benefits of Migrations:

class MyClass < ActiveRecord::Migration
  def self.up
    remove_column :mytable, :old_column
    puts `mysql database -u user -ppassword
    -e 'alter table mytable add column new_column bigint unsigned'`
  end
..
..
end

April 10th, 2007 - Posted by in ruby, ruby on rails, tips | | 0 Comments