Stop Being Carbon

Icon

WMSMapServiceLayer – ArcGIS API for WPF

ESRI released a beta version of their ArcGIS API for Silverlight/WPF some time ago. The may version does not support WMS out of the box but posted some code on their Code Gallery.

Unfortunately this code will not work for WPF (and I doubt that it will even work for Silverlight, considering the strange GetCapabilities parsing and the missing formatter information when parsing floating values). Anyway, I had some time at work and fixed the code for WMS version 1.1.1 and 1.3.0 (I didn’t test other versions, but will do so along the way to some fancy, internal prototype).

Have a look at the code on Github.

Things that would make life easier #1

I got something like 400 unread news items in my Google Reader account, which is quite a horrible number. The easiest thing would be to delete some news feeds but actually I’ve already reduced the number to something like 20. Some sites, like Apartment Therapy or Unplugged publish dozens of stories per day. Usually I quickly skip through them, star the most important posts for later reading (haha) and add the really, really great posts to my delicious account.

But: Couldn’t Google, the great data and information cruncher, tell me which items are of greater interest to me than others? I starred some 100 items so it should be fairly easy for them to find a general pattern. Would you do that for me, Google?

Heatmap from AIS data

What do you do with more than 25 gigabyte of compressed AIS data? You play around with it, load it into databases (and wait over a day for an index to get generated), do some funky .kmz files or you generate heatmaps, like this one to the right.

It shows AIS traffic for the UK and northern Europe during 24 hours. You can clearly see the high traffic zones. The original algorithm is not by me (and unfortunately the whole code is in the office, so the attribution will follow tomorrow) but I tweaked it a little bit.

The whole thing is quite memory consuming (the original rendering size was 4000×2000 pixels) and at the moment the .NET Garbage Collector and I are not a good team. I would re-implement it in C (maybe even with proj4 support?) but I first need to read about some drawing algorithms.

Flip an image with Scriptaculous

I was the need of a flip effect for scriptaculous and came up with this solution:

Effect.Flip = Class.create();
Object.extend(Object.extend(Effect.Flip.prototype,
  Effect.Base.prototype), {
 
    initialize: function(element, flip_graphic, original_graphic) {
      var options = arguments[3] || {};
 
      this.element = $(element);
      this.flip_graphic = flip_graphic;
      this.original_graphic = original_graphic;
 
      if (this.element.getAttribute('src') == this.flip_graphic) {
        this.flip_graphic = this.original_graphic;
        this.original_graphic = this.element.getAttribute('src');
      }
 
      this.width = options.width || this.element.getWidth();
      this.delta = this.width * 2;
      this.flip = 1;
 
      this.start(options);
    },
 
    update: function(position) {    
 
      var change = this.flip * (0.5 - position) * this.delta;
      var padding = this.width / 2 - change / 2;
 
      this.element.setStyle({
        width: change + 'px',
        padding: '0 0 0 ' + padding + 'px'
      });
 
      if (change < 0)
      {
        this.element.writeAttribute({ src: this.flip_graphic });
        this.flip = -1;
      }
    },
  });

You can use it like that:

new Effect.Flip(element, 'graphics/original.jpg', 'graphics/flip.png', { width: 120 });

I will post a demo tomorrow – I promise, it looks cool!

Mini DVI to Mini DisplayPort

I’m really thinking about getting the new 24″ LED Cinema Display from Apple. Comparable devices from Dell, for example, are a bit cheaper but I really like the idea of connecting my MacBook with the display and getting a MagSafe and USB connection, too. The only question I have is: Is there a Mini DVI to Mini DisplayPort adapter available from Apple? If not, do I need to get a new MacBook to use the new display? Sounds bizarre.

No title

I really think that discussing with myself if I should write ‘can’ or ‘could’ in an email makes me a better person.

acts_as_geocodable in tests

The last few days I wrote some unit tests for a project I’m currently working on (and which, by the way, should be released to public in a few weeks time). To easily be able to change attributes of my models and not rely on fixtures, I’m using the fixture_replacement plugin and actsasgeocodable to easily deal with address translations and that stuff (it introduces various attributes, like street, country, postal code,…). The last one comes with a nice option, normalized_address, which will update the information in your model with the information it got from the geocoding service (and thus will correct invalid postal codes, etc.).

Well, again, this feature is really handy but can lead to problems if you forgot that you activated it and just want to change the postal code of one of your models. Because the geocoder will still find the right address (mainly because the street name is the same) and actsasgeocodable will correct the invalid postal code for you. And you gonna have no clue why it won’t take the postal code you’ve used in fixture_replacement’s helper methods.

A simple fix for that is to add the following setup method into your unit tests:

def setup
  # This ensures that we can set individual attributes of our model
  # without being overridden by acts_as_geocodable.
  Property.acts_as_geocodable_options[:normalize_address] = false
end

Wildcards for phone numbers

Working for quite a big company has the disadvantage that you cannot now all the people there and their respective telephone numbers (especially when you were lucky enough not to get one of those Blackberry things). I’m pretty bad at remembering telephone numbers – which is actually not quite true, I still know all the numbers of my primary school friends – so for me it would be quite useful if my Nokia phone would support wildcards for phone numbers. So that I could even tell that the call is coming from within my company, even if I don’t have the exact name of the caller.

I always knew that coffee is my lifesaver

I guess every Mac users know the problem: You’re talking with your friends, showing them some drawing, snippet of code or website, talk even more with them and your Mac activates its screensaver and locks down the Keychain. For me that results in entering my password three times (one for login, one for iScrobbler and one for Safari’s Keychain access). Annoying.

But I discovered (or merely googled) a small tool which prevents your Mac from activating the screensaver, dimming down the screen or even going to sleep: Caffeine. Trust me, you need this tool.

Strange module error with Hpricot

I got some strange error today when I tried to deploy one of my rails projects to my slice at slicehost. The problem was that I had a newer version of Hpricot running on the slice (0.6.161) versus 0.6 on my local machine. The following line failed:

Hpricot::XChar::PREDEFINED_U.merge!({"&nbsp;" => 32})

Ahm, okay. I didn’t see any changes made to the overall layout of Hpricot so I suspect that line should work. Any ideas?

(If anyone is interested in the meaning of the above line, check this ticket).

Flickr

delicious