Archive for May, 2007

Google Maps Street View

Wednesday, May 30th, 2007

What do you get when you spend billions of dollars hiring tens of thousands of the smartest programmers on earth, and then tell them to go improve your map application – which is already far and away the best available?

. Doesn’t work in too many places outside San Fran right now but jesus it’s impressive.

Stick it on AMEX

Tuesday, May 29th, 2007

US taxpayers have debt and unfunded future liabilities totalling a mind-boggling $59 trillion dollars, almost equal to the annual GDP of the entire planet ($61.3 trillion, according to the IMF).

That’s .. a lot of money.

Updating multiple child records in a single form

Monday, May 28th, 2007

I wanted to update multiple child items on a single form. The situation is – I have an order form, and I’d like to give the customer the opportunity to edit quantity of individual line items in a text box, then update them all at once with a single “update” button, or even better, RJS. Pretty easy, huh?

Apparently not. After literally hours of experimentation, here’s what I came up with, but warning: it’s ugly.

controller setup:

 
  def basket
     = find_cart # children => cart_items
  end

in the view:

<% form_for :cart_item, :url => {:action => 'update_cart'} do |form| %> 
 <% for  in .cart_items %>
   <%= form.text_field :quantity, {:size => 4, :index => .id}  %>
<% end %>
 
<%= number_to_currency(.total_price) %>
<%= submit_tag "Update Cart" %>
<% end %>

Note that I’ve added an “index” field to the text field, otherwise there’s no way to tell which row you’re operating on. This generates a params hash as follows:

{"commit"=>"Update Cart", "cart_item"=>{"2"=>{"quantity"=>"4"}, "3"=>{"quantity"=>"2"}}}

Which is a 3-layer nested hash!

So the update_cart action in the controller has to go through that somehow, and here’s where it gets ugly:

  def update_cart
     = find_cart
    for key in params[:cart_item].keys
        quantity = params[:cart_item][key][:quantity].to_i
        cart_item = CartItem.find(key.to_i)
        cart_item.change_quantity(quantity) #method in the model
    end
    redirect_to :action => :basket
  end

Ugly, huh. But as far as I know this is, if not the only, then at least the simplest way to do it. I’m not aware of any helper in Rails to go through that hash for you, even though it generated it with the “index” function. Hardly the worst thing I’ve ever seen, but for such a common task I kind of expected it to be easier ..

Next task: AJAX that bitch so a change in the text field updates the record dynamically. This is going to be “fun”…

Error Driven Development

Monday, May 28th, 2007

You know what, all this time I’ve been working and I hadn’t even realised.

I’ve invented a whole new style of development!

You’ve heard of all those old boring kinds, like “Test Driven Development” and “Agile Development”. Well, throw all those old books away – here’s the heads up on the funky new shit.

It’s called “Error Driven Development” and it’s awesome.

The basic idea is simple enough (it’s always the simplest ideas that are the best!). You’re building a website. You get heaps of errors. You solve them, exposing more errors. Repeat this process until there’s no more errors, not that you can see right now anyway – and that’s what counts.

Tools Required: “refresh” button on browser, patience

Stay tuned for the book, tentatively titled RuntimeError: Called id for nil, which would mistakenly be 4 — if you really wanted the id of nil, use object_id

UPDATE: I’ve thought of a more crowd-pleasing name: “Exceptional Development”. Yup, my projects certainly are “exceptional” .. lol.

Procrastination

Monday, May 28th, 2007

I’ve recommended Paul Graham’s essays so many times it’s boring even to me. But I couldn’t resist passing on this fantastic quote from his thesis on procrastination:

Errands are so effective at killing great projects that a lot of people use them for that purpose. Someone who has decided to write a novel, for example, will suddenly find that the house needs cleaning. People who fail to write novels don’t do it by sitting in front of a blank page for days without writing anything. They do it by feeding the cat, going out to buy something they need for their apartment, meeting a friend for coffee, checking email. “I don’t have time to work,” they say. And they don’t; they’ve made sure of that.

Feeding the cat, checking email .. updating your blog …

Stay Hungry, Stay Foolish, in Chinese

Monday, May 28th, 2007

For the benefit of my (apparently quite large) chinese audience, here’s the text of Steve Job’s 2005 Stanford Graduation Speech in Simplified Chinese.

你必须找到你所钟爱的东西—-史蒂夫乔布斯2005年6月斯坦佛大学演讲

关于如何将生命中的点点滴滴串联起来,关于爱和损失,关于死亡,乔布斯如是说

 我今天很荣幸能和你们一起参加毕业典礼,斯坦福大学是世界上最好的大学之一。我从来没有从大学中毕业。说实话,今天也许是在我的生命中离大学毕业最近的一天了。今天我想向你们讲述我生活中的三个故事。不是什么大不了的事情,只是三个故事而已。

 第一个故事是关于如何把生命中的点点滴滴串连起来。

 我在里德学院读了六个月之后就退学了,但是在十八个月以后——我真正的作出退学决定之前,我还经常去学校。我为什么要退学呢?

 故事从我出生的时候讲起。我的亲生母亲是一个年轻的,没有结婚的大学毕业生。她决定让别人收养我,她十分想让我被大学毕业生收养。但是我亲生母亲随后发现,我的养母从来没有上过大学,我的养父甚至从没有读过高中。她拒绝签这个收养合同。只是在几个月以后,我的养父母答应她一定要让我上大学,那个时候她才同意。

 在十七岁那年,我愚蠢的选择了一所几乎和你们斯坦福大学一样贵的学校。我父母还处于蓝领阶层,他们几乎把所有积蓄都花在了我的学费上面。在六个月后,我已经看不到其中的价值所在。但是在这里,我几乎花光了我父母这一辈子的所有积蓄。所以我决定要退学。不能否认,我当时确实非常的害怕,但是现在回头看看,那的确是我这一生中最棒的一个决定。

 但是这并不是那么罗曼蒂克。我失去了我的宿舍,所以我只能在朋友房间的地板上面睡觉,我去捡5美分的可乐瓶子,仅仅为了填饱肚子,在星期天的晚上,我需要走七英里的路程,穿过这个城市,只是为了能吃上饭——这个星期唯一一顿好一点的饭。但是我喜欢这样。我跟着我的直觉和好奇心走,遇到的很多东西,此后被证明是无价之宝。让我给你们举一个例子吧:

 里德学院在那时提供也许是全美最好的美术字课程。在这个大学里面的每个海报,每个抽屉的标签上面全都是漂亮的美术字。我决定去学学怎样写出漂亮的美术字。

 当时看起来这些东西在我的生命中,好像都没有什么实际应用的可能。但是十年之后,当我们在设计第一台Macintosh电脑的时候,就不是那样了。我把当时我学的那些东西全都设计进了Mac。那是第一台使用了漂亮的印刷字体的电脑。如果我当时没有退学,就不会有机会去参加这个我感兴趣的美术字课程, Mac就不会有这么多丰富的字体,以及赏心悦目的字体间距。那么现在个人电脑就不会有现在这么美妙的字型了。当然我在大学的时候,还不可能把从前的点点滴滴串连起来,但是当我十年后回顾这一切的时候,真的豁然开朗了。

 你在向前展望的时候不可能将这些片断串连起来;你只能在回顾的时候将点点滴滴串连起来。所以你必须相信这些片断会在你未来的某一天串连起来。你必须要相信某些东西:你的勇气、目的、生命、因缘。这个过程从来没有令我失望,只是让我的生命更加地与众不同而已。

 我的第二个故事是关于爱和损失的。

 我非常幸运,因为我在很早的时候就找到了我钟爱的东西。斯蒂夫·沃兹尼亚克和我在二十岁的时候就在父母的车库里面开创了苹果公司。十年之后,这个公司从那两个车库中的穷光蛋发展到了超过四千名的雇员、价值超过二十亿的大公司。在公司成立的第九年,我们刚刚发布了最好的产品,那就是Macintosh。  我也快要到三十岁了。在那一年,我被炒了鱿鱼。你怎么可能被你自己创立的公司炒了鱿鱼呢?嗯,在苹果快速成长的时候,我们雇用了一个很有天分的家伙和我一起管理这个公司,在最初的几年,公司运转的很好。但是后来我们对未来的看法发生了分歧。当争吵不可开交的时候,董事会站在了他的那一边。所以在三十岁的时候,我被炒了。在而立之年,我生命的全部支柱离自己远去。

 在最初的几个月里,我真是不知道该做些什么。我把从前的创业激情给丢了,我觉得自己让与我一同创业的人都很沮丧。但是我渐渐发现了曙光,我仍然喜爱我从事的这些东西。苹果公司发生的这些事情丝毫的没有改变这些。我被驱逐了,但是我仍然钟爱它。所以我决定从头再来。

 我当时没有觉察,但事后证明,从苹果公司被炒是我这辈子发生的最棒的事情。因为,作为一个成功者的极乐感觉被作为一个创业者的轻松感觉所重新代替:对任何事情都不那么特别看重。这让我觉得如此自由,进入了我生命中最有创造力的一个阶段。

 在接下来的五年里,我创立了一个名叫NeXT的公司,还有一个叫Pixar的公司,然后和一个后来成为我妻子的优雅女人相识。Pixar现在是世界上最成功的电脑制作工作室。在后来的一系列运转中,苹果收购了NeXT,我又回到了苹果公司。我们在NeXT发展的技术在苹果的复兴之中发挥了关键的作用。我还和Laurence一起建立了一个幸福的家庭。

 我可以非常肯定,如果我不被苹果开除的话,这其中一件事情也不会发生的。这个良药的味道实在是太苦了,但是我想病人需要这个药。有些时候,生活会拿起一块砖头向你的脑袋上猛拍一下。不要失去信心。我很清楚唯一使我一直走下去的,就是我做的事情令我无比钟爱。你需要去找到你所爱的东西。对于工作是如此,对于你的爱人也是如此。你的工作将会占据生活中很大的一部分。你只有相信自己所做的是伟大的工作,你才能怡然自得。如果你现在还没有找到,那么继续找、不要停下来、全心全意的去找,当你找到的时候你就会知道的。就像任何真诚的关系,随着岁月的流逝只会越来越紧密。所以继续找,直到你找到它,不要停下来!

 我的第三个故事是关于死亡的。

 当我十七岁的时候,我读到了一句话:“如果你把每一天都当作生命中最后一天去生活的话,那么有一天你会发现自己是正确的。”这句话给我留下了深刻的印象。从那时开始,过了 33年,我在每天早晨都会对着镜子问自己:“如果今天是我生命中的最后一天,你会不会完成你今天想做的事情呢?”当答案连续很多次被给予“不是”的时候,我知道自己需要改变某些事情了。

 “记住你即将死去”是我一生中遇到的最重要箴言。它帮我指明了生命中重要的选择。因为几乎所有的事情,包括所有的荣誉、所有的骄傲、所有对难堪和失败的恐惧,这些在死亡面前都会消失。我看到的是留下的真正重要的东西。

 你有时候会思考你将会失去某些东西,“记住你即将死去”是我知道的避免这些想法的最好办法。你已经赤身裸体了,你没有理由不去跟随自己的心一起跳动。

 大概一年以前,我的一次体检结果清楚的显示在我的胰腺有一个肿瘤。医生告诉我那很可能是一种无法治愈的癌症,我还有三到六个月的时间活在这个世界上。我的医生叫我回家,然后整理好我的一切,那就是医生准备死亡的程序。那意味着你将要把未来十年对你小孩说的话在几个月里面说完;那意味着把每件事情都搞定,让你的家人会尽可能轻松的生活;那意味着你要说“再见了”。

 我整天和那个诊断书一起生活。后来有一天早上医生将一个内窥镜从我的喉咙伸进去,通过我的胃,然后进入我的肠子,用一根针在我的胰腺上的肿瘤上取了几个细胞。我当时很镇静,因为我被注射了镇定剂。但是我的妻子在那里,后来告诉我,当医生在显微镜地下观察这些细胞的时候他们开始尖叫,因为这些细胞最后竟然是一种非常罕见的、可以用手术治愈的胰腺癌细胞。我做了这个手术,现在我痊愈了。

 那是我最接近死亡的时候,我还希望这也是以后的几十年最接近的一次。从死亡线上又活了过来,死亡对我来说,只是一个有用但是纯粹是知识上的概念的时候,我可以更肯定一点地对你们说:

 没有人愿意死,即使人们想上天堂,人们也不会为了去那里而死。但是死亡是我们每个人共同的终点。从来没有人能够逃脱它,也应该如此。因为死亡就是生命中最好的一个发明。它将旧的清除以便给新的让路。你们现在是新的,但是从现在开始不久以后,你们将会逐渐的变成旧的然后被清除。我很抱歉这很具有戏剧性,但是这十分的真实。

 你们的时间很有限,所以不要将他们浪费在重复其他人的生活上。不要被教条束缚,那意味着你和其他人思考的结果一起生活。不要被其他人喧嚣的观点掩盖你真正的内心的声音。还有最重要的是,你要有勇气去听从你直觉和心灵的指示——它们在某种程度上知道你想要成为什么样子,所有其他的事情都是次要的。

 当我年轻的时候,有一本叫做“整个地球的目录”振聋发聩的杂志,它是我们那一代人的圣经之一。它是一个叫Stewart Brand的家伙神奇地将这本书带到了这个世界。那是六十年代后期,所以这本书全部是用打字机,、剪刀还有偏光镜制作的。

 Stewart和他的伙伴出版了几期的“整个地球的目录”,当它完成了自己使命的时候,他们做出了最后一期的目录。那是在七十年代的中期,你们的时代。在最后一期的封底上是清晨乡村公路的照片(如果你有冒险精神的话,你可以自己找到这条路的),在照片之下有这样一段话:“保持饥饿,保持愚蠢。”这是他们停止了发刊的告别语。“保持饥饿,保持愚蠢。”我总是希望自己能够那样,现在, 在你们即将毕业,开始新的旅程的时候,我也希望你们能做到这样:保持饥饿,保持愚蠢。

(史蒂夫·乔布斯为苹果电脑和Pixar动画公司CEO,本文系其于2005年6月12日在斯坦佛大学所做的演讲)

Greenpeace and climate change

Monday, May 28th, 2007

So in the latest news, Greenpeace is upset at the US for opposing a G8 position statement on climate change:

Greenpeace Director John Sauven described the US position as “criminal”.

“The US administration is clearly ignoring the global scientific consensus as well the groundswell of concern about climate change in the United States,” he said.

Sounds reasonable, right? As a total layperson on climate change, it’s natural for me to at least listen to the environmental groups who, presumably, spend a lot more time than I studying the controversial issue. And the US certainly doesn’t help itself, what with its criminally ignorant President, blatant waste of resources with SUVs, and what not.

I happened to look at Greenpeace’s site earlier this week. I’m always interested in hearing both sides of the story – actually, I was writing a long mini-essay about climate change and the total corruption of all intelligent debat on the subject. I might be a layperson, but I like to think I’m at least a somewhat informed one. I might not have a PhD, but at least I try to learn some facts before I decide on an opinion.

What did I find on Greenpeace’s site? This absolutely ludicrous video.

I’ll say it one more time: I’m a layperson. But even so, I’m pretty sure global climate change didn’t cause the 2004 tsunami. I’m pretty sure there were bushfires before climate change, too. Many of the loving close-ups of “smokestacks” are quite obviously outputting steam. I’m furthermore pretty sure at least a subset of cows died occasionally before the CO2 started going up, and there were rumours of deserts before 1970 or so, as well. Icebergs, too, presumably didn’t just float around forever before George W Bush became president – and I can’t be sure, but I seem to remember literature of the time describing storms, with big waves, occurring in the pre-industrial age. Et cetera, et cetera.

Hang on, hang on! Something’s missing! Where’s the big-eyed sad-looking third world children staring beseechingly into the camera? Oh .. wait a sec .. oh sorry, there they are. OK, forget I said that.

Watch that video, why don’t you. It’s a transparently insulting attempt at over-simplified wannabe propaganda. It’s a total fucking joke, actually. Love the cheap-ass “ominous” soundtrack. And note the Greenpeace logo down the bottom right for the duration.

Who can you fucking believe in this? The head-in-the-sand US? Or the fucking morons at Greenpeace who would try to sell you on this contemptibly incompetent propaganda? The end justifies the means, eh, fuckers?

Bah, I wash my hands of all of it. Fuck the weather, fuck the Americans with their SUVs, and especially double motherfuck Greenpeace, the wannabe amateur propagandists with the “Disasters IV” stock footage DVD and the “donate now!” button on their website.

The Sound of Freedom

Saturday, May 26th, 2007

Four F-16s just flew overhead, so I did what I always do – ran outside and watched them fly by, grinning like an idiot. God I love the sound of jets, especially fighters – the ripping sound they make as they tear through the sky, and wondering where they’re going, what they’re doing – just like a kid.

Fuck I love that sound. I’m still smiling :-)

Localisation inside collection_select

Wednesday, May 23rd, 2007

After spending SIX FUCKING HOURS trying to make proper localisation work with AJAX-chained select menus (select by itself is buggy and wouldn’t accept my html_options – that was an hour or two right there), I finally had an epiphany.

The Objective:

Obtain a localised name from inside a collection_select.

The Problem:

collection_select does not provide direct access to child objects, only attributes of the child as accessible through the model. For example, if you want the id of the child object, you access it as :id, and if it ain’t in the model, you ain’t accessing it.

The Initial Solution:

Create a method for the model in question to go and translate itself when called

The Reason That Didn’t Work:

collection_select went off and rendered itself somewhere out of scope so the model had no idea of the current language as provided by the controller via both session and instance variables

The Solution:

All Rails developers are familiar with the trick of putting a cattr_accessor of current_user into the User model to make, surprise, the current user available outside the limited range of the controller’s instance variables and session objects.

The solution was to do this for language as well:

# language.rb
class Language < ActiveRecord::Base
  cattr_accessor :current_language
end
 
#application.rb
 
  before_filter :set_language
  after_filter  :clear_language
 
    def set_language
      if session[:language_id]
        Language.current_language = session[:language_id]
      else
        Language.current_language = 1
      end
    end
 
    def clear_language
      Language.current_language = nil
    end
 
#model_you_want_translated.rb
  def localname
    trans(self, Language.current_language)
  end
 
#the collection_select which now works
collection_select(:model_name, :name, , :id, :localname)

Seems pretty easy and obvious now I look at it, but believe me, the troubleshooting process was pretty opaque and unintuitive, and it took a long, long time to figure out what the hell was wrong. Wish I’d thought of this way of doing things earlier, would have saved me a lot of time in an earlier project … always like this!

MacBook Pro 6 Bit Screens

Monday, May 21st, 2007

Some information I’m not very happy with:

EDID output:

EDID Version……..1.3
Manufacturer……..APP
Product Code……..24732 (609C) (9C60)
Serial Number…….0

9C60 => AU Optronics B154PW01 V0.

B154PW01 Specs:

B154PW01 Specs

From a korean site, since the AUO original is unavailable.

Apple Japan MacBook Pro Specifications Page:

Apple Japan MacBook Pro Specifications Page

約1670万色対応 => “Approximately 16.7 million colors”. Last I checked, 16,777,216 is not “approximately” 262,144 – in fact, one is a 64-fold multiple of the other. In other words, this is clear-cut false advertising.

This better be a free replacement. Would you buy a $3000+ laptop whose specifications read “Display: 262k colors”?

UPDATE: I’d just like to clarify that I can’t see any dithering at all on these screens. I still don’t like them, but that’s more to do with the fact that it’s a single-backlight LCD screen and I’ve always hated pretty much all LCD screens in general, especially single backlight ones. My own desktop screen is 6-bit as well. But LCD as a whole is a nasty hack of a technology – the best LCDs I’ve ever seen still look like complete crap compared to my old Trinitron. There’s a whole class of colour that, as far as I know, LCD just can’t display – deep, warm blues and reds – they’re just absent on every LCD screen I’ve ever seen, and I loathe the tunnel effect of the disconnected light source and “filter” of the LCD. OLED can’t come fast enough!

That doesn’t change the fact that it’s false advertising. Everyone else might do it but we expect, and pay for, a better level of treatment from Apple.

Is LaTeX still the best we’ve got?

Monday, May 21st, 2007

Ever written a long, formally structured document? Well then, you’re probably familiar with the question of which format to write it in. It boggles my mind that, still, in 2007, there’s so few “best practise” choices to meet the following criteria:

  1. It must comprise a source file of directly editable plain text. None of these binary formats like .doc or even .pages where my only possible interaction with the contents of the file can be through some slow, buggy proprietary software. My feelings on this only get stronger with time.
  2. It must be human-readable and human-editable. I don’t mind a bit of code, but it must flow readably, which excludes all the XML variants and anything like ODF or PS.
  3. It must be well-supported with syntax highlighting and (hopefully) common action key shortcuts in at least a few common freeware programs, or paid programs I own like TextMate
  4. It must be exportable to anywhere I need, typically PDF and HTML.
  5. It must fucking WORK

It’s unbelievable but the only language I can think of that satisfies the above requirements – and, in fact, the only language that satisfies even the most important first two – is the 25-year-old LaTeX. I can grudgingly put up with LaTeX but it’s nuts there’s nothing better yet.

Is there really no other choice??

UPDATE: Oh yeah, MacTEX is a fucking 703 MB download.

I get awesome keywords

Sunday, May 20th, 2007

Boards of Canada, Dayvan Cowboy
chicas
hold your tears lyrics clazziquai english
Girls Fucking Animals — wtf?? i think this is referral spam
love mode clazziquai project lyrics
Sho Fukamachi
one winged angel
JAPANESE GHOST PICS
Salesman CLAZZIQUAI PROJECT lyric
girls fucking animals — same here
www.trueghoststories.com
japanese ghost images
1pondo 1280 — heh heh looking for PRON eh?
charmmy kitty pictures — sicko
my life billy joel lyrics
ANIMALS FUCK
石川梨華
animals fuck with girls
石川梨華
charmmy kitty
sho fukamachi
石川梨華
li yu chun supergirl
rika ishikawa
rie fu
浮舟 鳴り止まない
clazziquai sweety lyrics translation
石川梨華
浮舟 7188
浮舟 7188
bittorrentcurses options
looking for u left me long and clear lyrics
Lyrics clazziquai project salesman I Hope you know
base.rb:1358: syntax error
japanese mirror ghost
/active_record/base.rb:1358
i’m seventeen and i’m new here today the village i come from seems so far away
animals fucking
mongrel “ram usage”
Fukamachi — this person has class.
chicas
base36 ruby
base.rb:1358
“ipod inside her” lyrics — lol
girls that fuck animals
japanese ghost pictures
love mode ft verbal lyric
she is lyrics by clazziquai (korea)
“all was well”は
japanese ghost pictures
rika fukamachi — omg YES
rika fukamachi
life on mars lyric
one winged angel
mr salesman lyrics
go!go!7188 lyrics japanese
japanese ghost pictures
japanese pictures of ghost

etc etc etc … notice how none of these people are looking for something *I* wrote. Ah well!

Insane RC Helicopter piloting

Sunday, May 20th, 2007

Check out this video of a high-spec RC helicopter being flown by famous pilot Alan Szabo.

the top video on this page (sorry – the idiots don’t allow direct linking).

Having become accustomed to the typical flight characteristics of full-size helicopters, one forgets that the limitations of that flight are not imposed by the form factor of the vehicle – as amply demonstrated by this video! They are, in fact, imposed by material strength, power to weight, and human factors – both the ability of the human pilot to withstand high-G manuevering, and also his basic ability to retain a spatial understanding of his position and movements.

One can predict that given a combination of the orders-of-magnitude increases in materials strength-to-weight promised by nanotechnology, and advances in telepresence, we could conceivably see some descendant of the Apache acting in a similar way over some future battlefield ..

UPDATE: RC indoor aeroplane ballet:

Rails: dump database to fixtures preserving UTF8

Friday, May 18th, 2007

I needed to dump my database to fixtures for testing purposes. None of the commonly referenced scripts could do this while preserving UTF8 characters.

I modified this script to use the Ya2YAML utf8-compliant gem. You will need to install Ya2YAML:

sudo gem install ya2yaml

And save this script into lib/tasks, with the name extract_fixtures.rake:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
desc 'Create YAML test fixtures from data in an existing database.  
Defaults to development database.  Set RAILS_ENV to override.'
 
require 'Ya2YAML'
 
task :extract_fixtures => :environment do
  sql  = "SELECT * FROM %s"
  skip_tables = ["schema_info"]
  ActiveRecord::Base.establish_connection
  (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
    i = "000"
    File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|
      data = ActiveRecord::Base.connection.select_all(sql % table_name)
      file.write data.inject({}) { |hash, record|
        hash["#{table_name}_#{i.succ!}"] = record
        hash
      }.ya2yaml
    end
  end
end

You can then run it:

rake extract_fixtures

.. and behold as your fixtures directory is filled with proper unicode YAML files. It will overwrite anything else there, so be careful.

Transmission now usable with Oink

Friday, May 18th, 2007

Great news for anyone sick of the bloated monster Azureus – Transmission now works with Oink. Finally, a good alternative to Azureus for MacOSX!

Yet another WP update

Friday, May 18th, 2007

If I didn’t have svn to do this for me, I think I’d just throw in the towel. But with svn it’s a fairly painless:

svn switch http://svn.automattic.com/wordpress/tags/2.2/

rinse and repeat for every WP blog under your control. I never bother with disabling plugins or anything first, either.

Got to love the artifacts that accrue in the templates, too .. check out the <<<<.mine stuff which appears pretty much everytime I do anything. Thanks WP for not separating customisable templates and essential code – mixing them together makes everything so much easier!

Not. What a freaking mess. And the more you work with a well-designed framework like Rails, the more contempt you have for the development philosophy of a project like WP.

White and very, very Nerdy

Wednesday, May 16th, 2007

If the Wikipedia entry discussing Weird Al Yankovic’s music video for “White and Nerdy” isn’t the height of unwitting self-parody, I don’t know what is. Highlights:

The equation in the background of the chorus is Schrödinger’s wave equation for the hydrogen atom; however, there is an error in that Planck’s constant (denoted h) is displayed in place of Dirac’s constant (denoted ħ).

At the end of the video, Al flashes the Vulcan salute in place of a gang sign; though he uses Surak’s variant from the episode The Savage Curtain rather than the more standard salute.

Jesus H Christ. It reads like an Onion parody.

Testing times

Tuesday, May 15th, 2007

Well, I finally admitted I need testing in my Rails application. I must admit, I held out for a long time – I just couldn’t see the need! “I’ll test it by reloading the damn page!” said I. But these words could only come from inexperience. As a project grows, is refactored, splits into modules within modules, you just can’t test by loading the page any more. It’s just not practical. You can’t hold everything in your head all the time. It doesn’t scale.

I had been avoiding tests for a long time .. a year, in fact. But in the last few days I’ve been bitten by several horrible bugs which I have belatedly realised were not spotted earlier due to my lack of proper multi-user testing. So, after a day of work, I’m pleased to announce – my first achievements in automated testing:

23 tests, 32 assertions, 19 failures, 1 errors

heh. But at least it isn’t literally crashing the tester anymore.

Now to basically write the whole application again as functional tests!

“Type” a reserved word in Rails database

Monday, May 14th, 2007

I spent an hour trying to figure out why my SQL query crashed ActiveRecordso you don’t have to.

Don’t have a column name “type” in your DB, and if you do, don’t put an integer in it – or AR will crash out with this informative error:

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1358: syntax error, unexpected tINTEGER
Object::1
         ^
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1358:in `compute_type'

Just putting this up here so hopefully someone will find it in a search; I couldn’t.

UPDATE: it *is* apparently reserved. How about that:

self.inheritance_column = 'type'

I guess I’m just not used to thinking of column names as something with which you need to consider namespace clashes .. lesson learnt!

Baby Mimicry

Thursday, May 10th, 2007

Look at the mimicry by this baby of adults talking on the phone. He’s got the cadence and general sound of the conversation, the aimless walk pattern, and the phone-holding pose down. He even says “shit!”.

Kind of spooky.