Archive for December, 2007

Jackass free for Jackasses using SilverLight

Sunday, December 30th, 2007

Pretty ironic choice of movie, considering most people I know would say you’d have to be a Jackass to consider using SilverLight for anything at all.

From here.

Set aliases to ruby 1.9

Sunday, December 30th, 2007

What’s all this debate over the best way to try out Ruby 1.9 in MacOSX? Just install in /usr/local as detailed here and then set aliases in .profile:

alias ruby9="/usr/local/ruby1.9/bin/ruby"
alias irb9="/usr/local/ruby1.9/bin/irb"
alias gem9="/usr/local/ruby1.9/bin/gem"

Et voila.

UPDATE: This will only work for scripts you run directly from the console – it (probably) won’t work for scripts that call other scripts, eg rakefiles, so take care. It makes my playing around easier, but that’s probably all it’s good for.

Trains closed for 5 days

Thursday, December 27th, 2007

The North Shore Line in Sydney is closed for heavy trackwork for the next 5 days. They’ve got a pretty good excuse – a new rail line is being integrated into Chatswood station, and a bridge over the rails there pulled down as well. Still, 5 days is a long time for a service like that to be down! I imagine if there was a five-day rail closure in Tokyo, there would be some sort of violent revolutionary overthrow of the government.

Anyway, here’s some pictures of the station nearest to me, Artarmon, a small platform betwixt the much larger stations of Chatswood and St Leonard.

Closed!

Closed!

No-one here

No-one here.

Still no-one here

Still no-one here!

Trees across the track

Taking the opportunity to trim some trees near the line.

Machine bestride the track

A crane bestride the tracks.

Close-up of the machine

Close-up of the crane.

Never, ever use IronRuby

Wednesday, December 26th, 2007

So, you’ve heard of IronRuby? Microsoft’s implementation of Ruby on .NET. I’m hearing a bit of talk about it around the interwebs. Thinking of trying it out, eh?

Don’t. Ever.

Microsoft invented the technique we now refer to as Embrace, Extend, Extinguish. They tried it to Sun Java (MS JVM). They’ve tried it with Kerberos, and even today every web developer in the world is frustrated, wasting time trying to get around MS’s attempts to poison HTML and CSS.

A Leopard doesn’t change its spots. There is only one conceivable reason for Microsoft to implement another language on its own platform, and that’s that it sees it as a threat and wants to kill it. First, make a really good implementation! Fast, easy, Visual Studio! Next, “improve” it – on Windows only, of course! Third, we’re using MS Ruby++ and we’re fucked.

Run a million miles from IronRuby. If you assist in giving it traction, if you feed it any attention at all, you’re just making the world a worse place for all of us.

And one would be advised to think very, very carefully before adopting any technology – or, just as importantly, any *implementation* of a technology – that is not open source from top to bottom. GPL is best but MIT will do.

May MS never stain the history of computing again…

RubyConf 2007 videos online

Wednesday, December 26th, 2007

I didn’t realise that the entire RubyConf 2007 video archive is now online here. Some really good talks there.

Video may seem a poor teaching format, but sometimes I just get tired of reading all the time – and picking up some of the personality of the speaker can be very instructive and convincing. A good presentation can be interesting, educational, and steer you in a direction quite impossible with self-selected study which, almost by definition, only teaches you what you were already looking for. Watching what someone else has to say, and what they think is important, can be really interesting.

It’s great to live in a world where gigabytes upon gigabytes of good-quality conference video are available online, for free.

And there’s other conferences on that site as well – I’m still working my way through, but the Jamis Buck segment at Mountain West, Rails Code Review, was fascinating. I respect Buck a lot – hell, he’s basically second in command, and so I’m very interested in hearing what his views are on what is and isn’t good coding practise.

Check it out.

Ruby 1.9 released!!

Tuesday, December 25th, 2007

See http://www.ruby-lang.org/ja/, it’s not on the English site yet, nor is it tagged in SVN.

Awesome! : )

UPDATE: it’s on the english site now, but still not tagged in SVN.

I wonder what the “best practise” method of upgrading in OSX would be?

Songs of the Week

Tuesday, December 25th, 2007

Song of the week is two songs from the the Korean drama Dae Jang Geum (대장금).

First is Onara (오나라), the famous theme song from the drama. Sung in (old) korean. Has a wikipedia page here if you want more information.

Unaccountably, although I heard this song every saturday night for a year, I never liked it coming from the TV speaker. It was only after I finally heard it on proper speakers that I fell in love with it, several years late! This despite my general liking of korean music, especially drama theme songs, as detailed here before…

Second is The Legend Becomes History, the ending theme, sung in English. Lyrics after the break.

If you like Kanno Yoko or other highly melodic drama soundtracks, you should certainly check the soundtrack out. It’s Kanno-class – what higher praise is there?

(more…)

Optical Illusion

Monday, December 24th, 2007

I could not believe this:

Checker Shadow Illusion

The squares A and B are the same shade of grey.

I couldn’t believe it. I looked at it every way I could, trying to see how it was possible. I couldn’t until I finally sampled the damn pixels in Color Schemer Studio. Both squares are #787878.

Who you gonna believe — me, or your own lyin’ eyes?

Darwinia

Tuesday, December 18th, 2007

Darwinia, a computer-y game from Ambrosia SW, looks pretty cool. I’d like to play it. I downloaded the demo, and gave it a shot until I realised the program, in which view is controlled mouselook-style, maps “mouse up” to “look up”, and does not allow you to flip Y-axis on the mouse.

I cannot fucking stand games that insist on the completely counterintuitive behaviour of mouse up = look up, and I consider anyone who plays any kind of game in that mode to be an utter moron. How fucking hard is it to understand? Head moves forward = LOOKS DOWN. Head moves back = LOOKS UP. Same for the god damn mouse. How can anyone think any differently? Why don’t you try the push forward = go up concept next time you fly a plane, retards?

So maybe Darwinia’s a good game! Maybe not. I’ll never know, because the control system is fundamentally broken for anyone with a good – nay, correct – conceptual understanding of 3D space.

Seriously, it is impossible to convey in mere words the primal fury that wells, nay, boils up inside me when I am confronted with such an insult to the basic motion laws of the whole fucking universe. It makes me want to flay the programmer alive. Man, have you ever watched someone playing a game using this retarded setup? It makes you want to club them from behind. Argh!

Oh, and Ambrosia’s web page looks heaps cool if it’s 2001! Pinstripes! Woo.

Whaling war with Japan

Monday, December 17th, 2007

According to this article in the SMH, Australian Customs is contemplating sending its ice-capable armed patrol ship, the Customs and Fisheries armed Southern Ocean patrol vessel Oceanic Viking, to follow the Japanese whaling fleet this season in the Southern Ocean Whale Sanctuary!

Customs and Fisheries armed Southern Ocean patrol vessel Oceanic Viking

The vessel has light fixed weaponry of 2 .50cal machine guns. Customs officers onboard are also armed.

SOMPRU 0.50 calibre machine gun being test fired

It typically apprehends shitty-looking boats like this.

pprehension of the Taruman

A much cooler-looking ship is the ACV Triton, which performs much the same job in the EEZ up near Indonesia. The illegal fishing boats there are much smaller and more numerous, and Customs simply destroy them, often on the spot. Triton can do almost 40 km/h, and is guided by JORN.

ACV Triton

In a 2003 incident, Customs under the Southern Ocean Maritime Patrol mission famously chased a Uruguayan fishing ship over 21 days and 7200km, starting in the Australian Exclusive Economic Zone and ending near Africa, the longest pursuit in Australian maritime history.

Chase of the Viarsa, 2003

Rails not working yet on Ruby 1.9 trunk

Saturday, December 15th, 2007

For those entranced by these benchmarks results and wanting to host Rails on Ruby 1.9 ASAP …

My testing shows Rails 2.0.1 failing on current svn/trunk installs of Ruby 1.9 on MacOSX 10.5.1.

But WEBrick works!

Ruby 1.9 build:

cd ~/src
svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby-1.9
cd ruby-1.9
autoconf
./configure --prefix=/usr/local/ruby1.9
make
sudo make install
cd /usr/local/ruby1.9/bin/
./ruby -v
-> ruby 1.9.0 (2007-12-15 patchlevel 0) [i686-darwin9.1.0]

Rails 2.0.1 installation:

pwd
-> /usr/local/ruby1.9/bin
sudo ./gem install rails
-> Successfully installed actionpack-2.0.1
-> Successfully installed actionmailer-2.0.1
-> Successfully installed activeresource-2.0.1
-> Successfully installed rails-2.0.1
-> 4 gems installed
-> Installing ri documentation for actionpack-2.0.1...
-> Installing ri documentation for actionmailer-2.0.1...
-> Installing ri documentation for activeresource-2.0.1...
-> Installing RDoc documentation for actionpack-2.0.1...
-> Installing RDoc documentation for actionmailer-2.0.1...
-> Installing RDoc documentation for activeresource-2.0.1...
$

All installs nicely …

Attempting to run a Rails app (after install a few more requisite gems using above method):

$ cd /rails/my_1337_app/
$ /usr/local/ruby1.9/bin/ruby script/server
=> Booting WEBrick...
/usr/local/ruby1.9/lib/ruby/gems/1.9/gems/activerecord-2.0.1/lib/active_record/associations/association_proxy.rb:8: warning: undefining 'object_id' may cause serious problem
/usr/local/ruby1.9/lib/ruby/gems/1.9/gems/rails-2.0.1/lib/initializer.rb:224: warning: variable $KCODE is no longer effective; ignored
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-12-15 07:24:35] INFO  WEBrick 1.3.1
[2007-12-15 07:24:35] INFO  ruby 1.9.0 (2007-12-15) [i686-darwin9.1.0]
[2007-12-15 07:24:35] INFO  WEBrick::HTTPServer#start: pid=3386 port=3000
 
## I request http://0.0.0.0:3000/ ... 500 Internal Server Error
 
Error during failsafe response: can't convert Array into String
127.0.0.1 - - [15/Dec/2007:07:24:52 EST] "GET / HTTP/1.1" 500 60
- -> /

OK, it bombs out trying to actually process a request. But this error is really, really fast! I am actually serious saying that, the error *is* really fast.

Mongrel installation fails:

$ sudo ./gem install mongrel
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mongrel:
        ERROR: Failed to build gem native extension.
 
/usr/local/ruby1.9/bin/ruby extconf.rb install mongrel
creating Makefile
 
make
gcc -I. -I/usr/local/ruby1.9/include/ruby-1.9/i686-darwin9.1.0 -I/usr/local/ruby1.9/include/ruby-1.9 -I.  -fno-common -g -O2 -pipe -fno-common  -c fastthread.c
fastthread.c:13:20: error: intern.h: No such file or directory
fastthread.c:349: error: static declaration of ‘rb_mutex_locked_p’ follows non-static declaration
/usr/local/ruby1.9/include/ruby-1.9/ruby/intern.h:556: error: previous declaration of ‘rb_mutex_locked_p’ was here
fastthread.c:366: error: static declaration of ‘rb_mutex_try_lock’ follows non-static declaration
## etc etc etc

So webrick’s all we have for now.

You can track the state of edge Rails’ 1.9 readiness in this ticket on the Rails Trac. Plugins, though, will be another matter, although some fixes are pretty easy; an early failure I’ve seen is with plugins using File.exists?('file') which is of course deprecated in 1.9 in favour of the far, far superior File.exist?('file').

I like using the 1.9 console, though – it really does feel snappier, especially to load irb!

Migrations much improved in Rails 2

Friday, December 14th, 2007

I hadn’t been using migrations much in Rails 1.x. I just didn’t like the workflow – it was too clumsy, and I got annoyed at writing out the files. The workflow in 1.x was as such:

1.

script/generate migration MigrationName [--svn]

2. go and manually edit 00x_MigrationName.yml in /db/migrations to reflect your desired database changes, both up and down:

class AddCreatedAtToStaff < ActiveRecord::Migration
  def self.up
    add_column :staff, :created_at, :datetime
  end
 
  def self.down
    remove_column :staff, :created_at
  end
end

3. rake db:migrate to apply the changes to the local database.
4. svn commit and cap deploy:migrations to apply the changes to the remote database

Too long – especially step 2. I knew I should do it in principle, but CocoaMySQL is right there – especially if you make several changes in the space of a few hours. In theory it’s best practise – but in actual practise someone as lazy (and impatient) as me tends to just do it directly in the DB, then eternally put off that day where they’ll finally “move to migrations”.

It’s not even the laziness – it’s the “flow”. I’m doing other things, I’ve realised I need this field. I don’t want to stop what I’m doing and write out a damn YAML file! I want the field there, right now. Too demanding? Maybe, but like I said, the DB is right there, and the difference between a 5 second edit and 2 minutes writing the file is a lot of lost concentration.

And various other solutions, such as auto_migrations, seemed good but in practise are too flaky and a dangerous, unsupported road to take.

Enter Rails 2.0, and migrations are far, far better. The core Rails principle of “convention over configuration” is in full effect here, with excellent results.

Now the process of adding a migration is as such:

1.

script/generate migration add_created_at_to_staff created_at:datetime [--svn]

Note the convention at work here. You’re implicitly telling Rails the table to use, in this case “staff”, and the field you’re adding – in this case one of Rail’s magic “created_at” fields. You then explicitly write the fields out, which you’d have to do anyway in CocoaMySQL or similar, or manually at the mysql command line.

2. rake db:migrate to apply the changes to the local database.
3. svn commit and cap deploy:migrations to apply the changes to the remote database

That’s only one step less, but it was the biggest and most annoying one. The actual creation of the migration file and addition to svn is now a single brief, easy-to-remember line. This is now terse enough and convenient enough to enter my personal development workflow, a very welcome improvement to the framework, and an excellent demonstration of Rails’ core principles in action.

Resolve conflict between jQuery and Prototype

Thursday, December 13th, 2007

I had a strange error where Prototype and jQuery were overwriting each other’s namespace. Please don’t ask me why I happen to using both – it’s just on one page, and it’s just until I work out how to duplicate my Prototype effort in JQ (I find JavaScript utterly incomprehensible and incredibly difficult to learn).

Anyway, I tried a number of tricks with loading order and including various bits of each. I couldn’t keep it working – either I had one or the other, never both. Then I read this page: Using jQuery with Other Libraries on the official jQuery developer pages. It recommends you do as such:

   <script>
     jQuery.noConflict();
 
     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });
 
     // Use Prototype with $(...), etc.
     $('someid').style.display = 'none';
   script>

But I don’t have any Prototype script in HEAD. It’s all addressed through the default Rails includes. I didn’t want to start messing with that.

I implemented the above, it didn’t work but the failure was different – now Prototype was trying to work, but erroring out with prototype TypeError: Value undefined (result of expression $) is not object.

Solution: On a lark, I removed jQuery.noConflict(); and renamed all jquery-targeted $(function) shortcuts to jQuery(function):

   <script>
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });
   script>
 
// in body: Ajax.new & co Rails commands

It’s a horrible nasty hack that gets around the horrible nasty problems from using two JS frameworks on the same page. Don’t copy this, I’m posting it only for your morbid curiosity. If you dare copy this horrible technique your Good Programmer’s Card is revoked. But it works!

Rails? Slow?

Tuesday, December 11th, 2007

Rails? Slow?

75 seconds is nothing! Why, when I was young, we’d count ourselves lucky if a web server responded within the day…

In its defence, I’d been doing other things before requesting again .. enough time for some of it to go into swap. But man, 75 seconds!

Transmission 0.95 very buggy

Monday, December 10th, 2007

Just a heads-up to my friends who use Transmission – 0.95 is extremely buggy. You’ll notice it using all your HD space, memory, becoming unresponsive and crashing, and writing bad data into your torrents (check everything you’ve downloaded with it). A terrible release and very worrying that it was released at all with such major problems.

I recommend immediately moving back to 0.94 (or even 0.93, but i’ve had no problems with 94) for now. I would also recommend adopting a (perhaps temporary) posture of suspicion towards this software – disable daily update checks and rely on manual updates a few weeks after release. You can review whether other users have had difficulties on popular Mac software review sites such as VersionTracker and MacUpdate.

You might think this is an overreaction but these kind of bugs should never make it into a public release, even a “beta”, and their presence sets off alarm bells. It’s pretty easy to imagine how, if bugs allowing uncontrolled file writing are allowed into a tagged release, bugs allowing unchecked file deletion might also creep in. Macs don’t really have a virus problem like PCs – but bad software can still delete all your files. This isn’t likely to happen but still – I don’t like the cavalier turn development of Transmission seems to have taken and recommend caution until sanity returns (and is confirmed to have returned over a few weeks of other people’s testing!).

UPDATE: The problem of data corruption is supposedly fixed in 0.96, although the speed problems remain. I’m thinking I’ll hold off a bit before moving from the highly reliable (in my experience) 0.94.

Rails: multiple assets servers with 1 server using Apache

Wednesday, December 5th, 2007

Rails 2 has added the ability to automatically serve static public files – “assets” – from multiple servers, to speed up loading times. This is well worth implementing and will speed loading times considerably. And it’s very simple to do. You’ll need Rails 2.0RC1+ for this. Obviously your implementation details may differ, especially filepaths on the server.

Step 1: In rails_app/config/environments/production.rb:

config.action_controller.asset_host = "http://assets%d.my_kewl_domain.com"

Step 2: In my_kewl_domain.com.zone

www              IN              A       31.337.31.337
 
assets0         IN              A       31.337.31.337
assets1         IN              A       31.337.31.337
assets2         IN              A       31.337.31.337
assets3         IN              A       31.337.31.337

Step 3: In httpd.conf

<VirtualHost 31.337.31.337:80>
ServerName assets0.my_kewl_domain.com
ServerAlias assets1.my_kewl_domain.com, assets2.my_kewl_domain.com, assets3.my_kewl_domain.com
DocumentRoot /www/my_kewl_domain.com/current/trunk/public
VirtualHost>

Note this is a separate vHost from your main application. Note also that it is looking straight into the /public directory of your app.

svn up, cap deploy, restart %w[named httpd mongrel] and you’re done.

Including the coming Ruby 1.9 (apparently still on course for sometime this month), this is a nice free speedup for your application.

Old game music .MODs

Tuesday, December 4th, 2007

Ready for a blast from the past? All files can be played in VLC.

SWIV – probably my favourite Amiga game music ever. Was really blown away at the time ..!

Xenon 2

Magic Pockets

R-Type

Bitmap Brothers sure kicked ass.

Next: Commodore 64 music. Stay a while … stay .. forever!!!

Rails 2 – Too Much Magic?

Tuesday, December 4th, 2007

So I’ve been watching the RailsCasts episodes going through the latest features in Rails 2. I’ve read about them before – but it’s good to see them demonstrated by an expert.

But man – some of this is too much. Don’t get me wrong, I like magic – if I didn’t like magical free stuff I wouldn’t be using Rails at all. But there comes a point where there’s enough magic, and more just trades off too much for too little – diminishing returns, as it’s called.

Take this screencast: Simplify Views with Rails 2.0. It shows very clearly what I’m talking about.

Now some of this is good shit. The ability to write this:

<% div_for_product do %> # is this supposed to be <%= ?
<% end %>

And have it automatically generate div IDs and the like is great. That saves some nasty looking code – assuming it works properly, stays unique across multiple includes, etc. Good shit. A worthwhile addition.

But this:

# from
<%= render :partial => 'product', :collection =>  %>
# to
<%= render :partial =>  %>
# and for a single case
<%= render :partial =>  %>

I think this is bad news. Suppposedly Rails is going to look inside that instance variable, decide whether it’s an object or an array, and automatically use the correct partial, multiple times if it’s an array .. why? To save what, 15 keystrokes?

I would argue the “Rails 1.2″ way of doing this is about the most concise way to write this function imaginable while still maintaining decent at-a-glance understandability. It’s not so long and unweildy, is it? And you can see what’s happening instantly – ok, now render a bunch of partials named ‘this’ using whatever was in this . The word “collection” is a nice touch which helps you remember there’s a number of them.

The second one? Its behaviour literally changes according to what’s in that instance variable. Is it really that much nicer to look at that it’s worth losing the information necessary to see, at a glance and unambiguously, what it’s doing?

There’s more, and worse: forms, where we go from this

<% form_for :product, :url => product_path(), :html => {:method => 'put'} do |f| %>

to

<% form_for  do |f| %>

And if you’ve used the strict Rails conventions, mapped all your resources in routes.rb, are using the strict controller layout as demonstrated in the resources scaffold generator and have a picture of DHH as your desktop background, it’ll know what to do and work.

Now, at this point you might be saying “but you don’t have to use these features – it’s only if you follow the convention, which is the whole point of Rails! Follow the convention, get free benefits – it’s been like that since day 1″!

I agree with that, kind of. But there is such a thing as too much convention, and too many limits, and – this one’s my point – too much “magic”. I know it’s a bit silly to talk about “vendor lock-in” in the context of a Rails project but following “The Rails Way” is beginning to smell strangely similar. And these extraordinary efforts to save a few keystrokes, ONCE, at the expense of readability (and no doubt speed!) are beginning to seem less like cleverness and more like Koolaid-driven idealogy.

We’ve been told, again and again, that it’s all about “Beautiful Code”. And you know, I appreciate that up to a point. But when the code is getting less readable and more dependent on arbitrary chains of “convention dependence” which may or may not work (and which may or may not change in 3.0!!) then I start getting cold feet.

You know what? I’m working on *a* web site, not *the* web site like these changes all seemed designed for.

Predictions of a coming fork, anyone? “Rails Lite”?

Oh, and despite the endless hours which must have been poured into this kind of useless bloat, YAML handling in rails is still UTF8-unsafe.

UPDATE: Sure, you can just not use these features. But the codebase bloats, the execution speed is slower – and it’s not like it was fast to begin with. I argue these new features make the code more difficult to read and learn – hurting the Rails community as a whole, reducing numbers of developers, marginalising the framework – as someone with a considerable investment in that framework I am a stakeholder in Rails, and it’s from that position I comment.

English lesson for DHH

Monday, December 3rd, 2007

Let me put it in a way you’ll understand, my gay Danish friend:

Inflector.inflections do |inflect|
  inflect.uncountable 'staff'
end

That is all.

Make shadow.rb serve unicode

Sunday, December 2nd, 2007

Shadow is an awesome little project that gives you a tiny, zero-config REST server for your database. Just pure GET PUT POST DELETE, nothing more, nothing less. Uses mongrel for the net and AR for the db – you’ll need to point it at your database.yml.

But it didn’t do UTF8 out of the box, so let’s change that:

1
2
3
4
5
6
7
8
9
10
$ diff shadow-old.rb shadow.rb
5a6
> require 'Ya2YAML'
12a14
>     $KCODE='u'
42c44
<       out.write obj.to_yaml
---
>       out.write obj.ya2yaml
$

できた!

I really love this kind of thing. Rails is becoming a MONSTER and is a bitch to force to play with anything else on your server(s). I think we’ll see a lot more of this kind of thing – a breaking-out of small pieces of very nice Rails functionality, into a way that makes them play nicer in a team.