This is a potentially ugly to solve, but you can actually compare two arrays. So it isn't so bad. If the first attributes are the same, it sorts by the second.
def <=>(other)
[self.dtstart, self.dtend] <=> [other.dtstart, other.dtend]
end
This is a potentially ugly to solve, but you can actually compare two arrays. So it isn't so bad. If the first attributes are the same, it sorts by the second.
def <=>(other)
[self.dtstart, self.dtend] <=> [other.dtstart, other.dtend]
end
Sigur Rós made the best video clip ever. It's all naked people running around a forest for several minutes. Totally wonderful. Good song too.
We just watched George Romero's original Dawn of the Dead. It was fully sweet. I really loved the remake, but this was great in a whole different way. It wasn't as funny or smart, but it was quality. And interesting, which isn't something one tends to say about zombie films. Except 28 Days Later I guess.
It was real good but. Good gore spatterings. Lots of gore spatterings. More than you could reasonably ask for in one film.
I found a solution to the problem of month/day ordering by overriding the autocasting code in ActiveRecord. However, that didn't solve the problem more generally. So I came up with a nicer solution that uses the existing Date::Format._parse_sla_eu
method. It replaces the US year/month/day parsing method with the European one.
# Overrides the default Date::_parse() method for dates of format dd/mm/yyyy
# ParseDate does the typical American thing and assumes mm/dd/yyy and
# doesn't seem to be configurable
module Date::Format::EuropeanDates
def self.included(base)
base.class_eval do
class << self
alias_method :_parse_sla_us, :_parse_sla_eu
end
end
end
end
Date.send(:include, Date::Format::EuropeanDates)
With thanks to Simon who showed me how to replace static methods. This is the kind of wacky stuff you could never do with PHP. Not that we should want to. It's kind of ridiculous.
Wally from The Basics (and Gotye) is kind of a web geek I reckon. He manages all their CD ordering and mailing himself it seems. He even hand-wrote the addresses on my Gotye CDs when I ordered them. Ordering CDs online seems like a slight waste of postage, but I also reckon the musicians must get a fair chunk more. Especially if they reckon it's worth the effort of building CD ordering applications and posting people the CDs themselves.
Libby and I are going to Sigur Rós on the 2 August 2008. They are pretty damn good.
I've been a software developer of some description for a fair while, and I've authored at least my fair share of bugs. But my new worst bug I discovered yesterday. It was in code for a published economic paper.
This is the original code:
gen w01ceil = w11ceil + (1-mrw_alpha) * pr * (1-coerc_pi01) + (1-pr)*coerc_pi10
This is the correct code:
gen w01ceil = w11ceil + (1-coerc_alpha) * pr * (1-coerc_pi01) + (1-pr)*coerc_pi10
I'm sure I originally had it right and changed it at some later point for testing. I just didn't change it back. Luckily, although the correct1 results are fairly different, they still support the point we're trying to make.
It seems that the carbon trading market in Australia finally kicked off today. Prices started at $19/tonne, but that's not really based on anything in particular.
The first trade was between AGL and Westpac for 1 unit of carbon (which is 10,000 tonnes). Australia emits 603 million tonnes a year according to SMH, so those traders were really just doing it for the fun of it. I interested in working out how much more my life would cost if my carbon was offset, or if I chose to buy some share of a fixed amount that we decided was OK for the plant. AGL reckons the price could rise to $50/tonne by 2020, which is a much more interesting number to me. The price will rise because it will get harder and harder to reduce emissions as we take advantage of the cheap technologies and have to start using more expensive ones.
Last year I took two short flights and two long flights. AGL reckons that emitted 4.5 tonnes of carbon, but GreenFleet reckons that total impact on the atmosphere is more like emitting 12 tonnes. Those flights cost about $1200. If I added the cost of buying the rights to emit the carbon I produce it would cost $50 * 12 tonnes = $600. Which is a fair whack. So I'm inclined to conclude that I should probably stop flying. Or perhaps only fly for funerals of nuclear family members perhaps. I think I should commit to offsetting my flight emissions if I do decide to fly.
I'm also happy I ride a bike.
And green power is the bomb. It is so easy and so cheap, and you can reduce your emissions by a heap. If we didn't have green power, the Enmore house's carbon emissions from energy would have walloped my flight emissions. So everyone should get green power.
Update: I found a better solution that changes the date parsing code instead.
# Overrides the default AR date casting for dates of format dd/mm/yyyy
module ActiveRecord
module ConnectionAdapters #:nodoc:
class Column
def self.fallback_string_to_date(string)
string.gsub!(/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/, '\3-\2-\1') # Convert to unambiguous date
new_date *ParseDate.parsedate(string)[0..2]
end
end
end
end
Rails ActiveRecord (or ParseDate at least) assumes that date strings with forward slashes are always in the form mm/dd/yyyy
. That's all very well for silly countries like America, but not for a lot of the rest of the world.
This is my fairly shite attempt to transparently solve this problem. If you put this code in lib/autocast_date.rb
for instance you can go require 'autocast_date'
at the top of any model that needs it.
This will obviously break support for American style dates.
I've been frustrated by the lack of humanity in Rails so-called human names. So I wrote a little library, which was largely stolen from Change displayed column name in Rails validation messages. The library lets you do something a little like this...
require 'human_attributes'
class Puppy < ActiveRecord::Base
humanize_attributes :breakfast => "Puppy's preferred breakfast"
validates_presence_of :breakfast
end
It doesn't do anything very spectacular, but it took me a long time to work out.
# lib/human_attributes.rb
module ActiveRecord
class Base
# Humanize attributes
def self.human_attribute_name(attr)
@humanized_attributes ||= {}
@humanized_attributes[attr.to_sym] || attr.humanize
end
def self.humanize_attributes(*args)
@humanized_attributes = *args
end
end
end
ActiveRecord::Base#human_attribute_name
is deprecated and will be replaced by proper string inflection. For those with fancy, modern humanizing Inflectors you might have to change it to something like this.
def self.humanize_attributes(*args)
humanized_attributes = *args
Inflector.inflections do |inflect|
humanized_attributes.each do |attr, label|
inflect.human attr.to_s, label
end
end
end
Although I couldn't get that to work, probably because my Rails isn't new enough.
I thought Hostel was meant to be good, so I made myself sit through it. It wasn't very good, or interesting, or even very scary. Bits of it were kind of gross I suppose, but that's all you could really say.
This is the final route the intrepid road trippers ultimately tripped. It was a mighty fine adventure.
It was 7,371km according to Google but the trip meter reckons we drove about 9,700km (including the optional detour to Uluru).
0.652 seconds