Google charts + open government data == cool

Yes indeed folks, I bring you the number of passports lost or stolen in Europe as recorded by the British consulates in said countries for the year 01 April 2008 to 31 March 2009.

Red = worse. From which we can falsely infer that we shouldn’t go to the red ones because you are more likely to have your passport stolen 🙂

Hacking WordPress – how to show all comments with a custom quicktag

One of the blessings in WordPress is the vast array of plugins available. However, it is also one of the curses….because it makes us lazy. While this doesn’t seem to be problematic in the short term, in the longer term, large numbers of plugins can cause blogs to slow down, and even worse, the various plugins could start interfering with each other. So, whenever I can, I like to write my own code – the two advantages are that
1 – I can control exactly what goes in to the code, making it do what I need and no more
and
2 – I’ve written the code so if things start to clash, it’s going to be easier to debug.

So, let’s learn how to create a WordPress page to display every comment on our blog and just for fun, let’s also code up a quicktag which we can place into any page or post where we want the comments displayed.
Continue reading Hacking WordPress – how to show all comments with a custom quicktag

C# Dictionary object – know your database structure and I won’t have to hack like this

private Dictionary theThingThatWasNotUnique(){
  blah blah blah;
  Dictionary aSetOfResults= new Dictionary();
  foreach (DataRow dr in ds.Tables[0].Rows){
    DateTime startDate= (DateTime)dr["dtStart"];
    string activityName = (string)dr["sActivityName"];
    aSetOfResults.Add(startDate, activityName);
  }
}

The Dictionary object in C# is pretty neat. It’s fast and light because it’s essentially a hash table and it really is nice to enumerate through. The gotcha is, it relies on unique values in the key. And herein lies the problem with the code above. In the application I was troubleshooting, the dates that were stored were not guaranteed to be unique. This is really a simple case of not understanding the data structure properly and making false assumptions. Continue reading C# Dictionary object – know your database structure and I won’t have to hack like this

Learning Ruby on Rails- Drop Down Lists in One to Many Relationships

If you are just looking for some help without reading my rambling post……
the short answer is, collection_select – something like this:

<%= collection_select(:city, :country_id, @countries, :id, :country_name, {:prompt => false}) %>

not f.select as I did the first time round

<%= f.select('country_id', @countries.collect {|r| [h(r.country_name), r.id] }, { :include_blank => false }) %>

🙁

Continue reading Learning Ruby on Rails- Drop Down Lists in One to Many Relationships