Courtesy of Twitter

Railscamp #4

November 17th, 2008 by Radar

If somebody had told me that 6 months ago on this day I would be cleaning toilets I would’ve laughed at them. But, that’s how Railscamp #4 ended, just me and the SeaLink guys (Adam, Anuj & Vishal) cleaning the Bunk House.

Some Information

There’s a lot that goes into running an event like this. It started shortly after Railscamp #3 when discussion was going on in #roro about the next event and somehow the onus was put on us Adelaidians to hold an event in the coming months. We thought about choosing a sea-side venue for a start, but the ones I contacted were too expensive. Anthony Richardson (hereafter referred to as Richo) suggested Woodhouse and that was seconded by a friend of mine and so we explored the venue and I fell in love. The prices and dates and size and … everything was fabulous. Booked that in right away and paid the deposit. Cost was $20 per head in a bunk, $10 per camper.

The catering was dealt with by Anthony (but recommended by the venue’s website) which was fantastic. $50 per head for that wide of a choice of food was just marvelous.

For the projector screens we went with a company called Hire Intelligence. $75 per screen.

For the projectors Dr Nic brought his and so did anathematic (Thomas Sinclair)

Extra chairs + tables were hired from Atlas Party Hire. 25 chairs + 5 tables was $219.95.

Attendees were hired from the Ruby on Rails community, but can usually be found anywhere near sources of electricity and alcohol.

I’d like to thank…

Although I was the one who put the deposit down on the venue, there’s people who did way more than me.

Firstly, thanks to Richo for everything (yes, even yelling at me on Friday night), you’ve opened my eyes to a whole new world of “let someone else do it”. Also thanks for the pancakes and just generally being there to help run things.

Secondly, on Sunday morning there was one person out of the whole seven who were up who helped me do the dishes and that was Pythonic (Nick Jefferson). Thanks man, was feeling a bit overwhelmed at the time.

Thirdly, thanks to those of you (all of you!) who just cleaned up general. Nothing worse than trying to code surrounded by mess. Also those of you who were still cleaning up after the bus left.

Thanks to Lincoln Stoll for all his work setting up the servers / network.

Thanks to the caterers for absolutely kicking ass on the cooking duties. Beautiful work ladies, well worth the money.

Thanks to Pat Allan for coming and sharing his Sphinx wisdom and holy presence with us, and especially for the Werewolf deck and moderating a couple of games. On a similar line, thanks to Myles for narrating a few games whilst under the influence of “just a couple” of drinks.

Thanks to Lachie for his manipulation of twitter messages. Now, if only the real Twitter did something like that for April Fools.

Thanks to whoever it was who left the Monopoly board out. I think I missed out on a few excellent presentations (judging by the applause) whilst I got my ass handed to me by Tom.

Thanks to those of you who did presentations and got heckled by Dr. Nic.

Thanks to Pete Yandell for making (not during railscamp, but before) and presenting Machinist, what appears to be an excellent replacement for fixtures.

Thanks to those who left iChat open and therefore allowed me to troll their presentations, especially Brenton Fletcher. Thanks to the Apple iPhone team who put Crickets as a ringtone for the iPhone as well and Rick Astley for his song of joy and love.

Thanks to chendo for writing cryptoquote, a word game where you get a quote that is encrypted, for example e = w and d = f and so on and you have to say stuff like e=w in a chat-like text box which will reveal your answer to be correct and give you points. It has a lot of promise to be a great procrastination tool for a lot of people.

And the best for last, all the attendees who were there for one, two, three or all four days. Without you guys there would be no Railscamp and no awesome Australian Rails community. You guys are the greatest people I know.

Railscamp

November 13th, 2008 by Radar

Railscamp is tomorrow!

Everything seems to be arranged, just gotta get the people there and then we can rock on.

Looking forward to it.

Lost in Translation

November 5th, 2008 by Radar

On my pet project rBoard I’ve been adding in t calls every where just in case someone wants to use it and translate it into their own language, and I got petrified of missing a translation somewhere along the lines so tonight (with a little help from #rubyonrails) I made a little rake task to check for you:

task :missing_translations => :environment do
  @missing_translation_count = 0
  for locale in I18n.load_path
    look_for_candidates(File.basename(locale,".*"))
    look_for_candidates(File.basename(locale,".*"), "#{RAILS_ROOT}/lib")
  end
  puts "Total missing translations: #{@missing_translation_count}"
end
 
def look_for_candidates(locale, dir="#{RAILS_ROOT}/app")
  entries = Dir.entries(dir) - [".", "..", ".svn", ".git"]
  for entry in entries
    alerted = false
    real_entry = File.join(dir, entry)
    if File.directory?(real_entry)
      look_for_candidates(locale, real_entry)
    else
      # dunno, guess some people may use the actual method rather than it's shorter brother
      translations = File.readlines(real_entry).to_s.scan(/\s[t|translate]\(.*?\)/)
      for translation in translations
        translated_to = I18n.t(translation.gsub(/^\s[t|translate]/, "").gsub(/[\(|\)|:]/, "").gsub(/(,.*)/, "").to_sym, :locale => locale)
        if translated_to.include?("translation missing:")
          puts "\n\nTranslations missing in #{real_entry}:" unless alerted
          alerted = true
          @missing_translation_count += 1
          puts "    #{translation} (locale: #{locale})"
        end
      end
    end
  end
  rescue I18n::MissingInterpolationArgument
end

This code is also on gist.github.com for your viewing pleasure.

Not the prettiest thing in the world, but that’s what you get when you code when you’re tired. Anyway, stick this in a file in lib/tasks and run it by typing rake missing_translations and you’ll be told what’s missing from what file and from what locale and you’ll even be given a nice counter that you can watch slowly decrement every time you fix a missing translation!

Dear India

November 5th, 2008 by Radar

I grow weary of you undercutting us honest workers in the web design industry and sending people who obviously do not know how to speak the English language into a primarily english based programming language. Perhaps, if you taught them how to speak the language the code is written in, then perhaps I would not be writing this blog post. I am not intending to be racist, but if it comes across that way I don’t really care. I worked with two people from different regions of India for near-on 8 months and they were two of the smartest (and greatest) people I have ever met.

Your slaves workers come into #rubyonrails and ask in their distorted english extremely vague questions and expect us to help them with little or no clue as to what they’re trying to do. Then when you ask them, it takes them forever to respond because they have to translate from their language, to ours. It is annoying and frankly I am no longer willing to put up with it. From now on anybody from India asking a question in #rubyonrails will be promptly placed on my ignore list unless they simply: 1) Ask in clear, concise English 2) Explain what their problem is rather than going “can any1 hlp me plz????”

What I am asking here is that before throwing them into the deep end of a programming language, teach them how to speak English (and not that shorthand crap either) and how to be polite and courteous and grateful for the free help we hand out on a daily basis in #rubyonrails. That’s all, no strings attached. Simple.

Love,
Radar

I18n: An Overview

October 29th, 2008 by Radar

Welcome to yet another overview, this time it’s on the new I18n features in Rails 2.2 which you can install by typing gem install rails -s http://gems.rubyonrails.org -v 2.2.0.

Any mention of the t method in this guide are also spots where you can use translate too, they are just aliased methods (t is aliased to translate), it’s just much easier (for me) to type t than it is to type translate. Please excuse my laziness.

I’ve begun adding in the translation calls for rboard in my personal branch on GitHub and today I would like to show you how I’ve done it.

Firstly I have added these two lines to my config/environment.rb:

config/environment.rb

I18n.load_path = Dir.glob("#{RAILS_ROOT}/locales/*.rb")
I18n.default_locale = "en-AU"

This tells rails to load the translation files (aka locale files) from the locales directory in the root of my rails app, and they are in a ruby format. Alternatively you could load yaml files. this also tells it to set the default locale as “en-AU”, which will load locales/en-AU.rb by default.

My (incomplete) translation file looks like this:
locales/en-AU.rb

{
  :'en-AU' => {
   :forum_heading => "Forum",
   :topics_heading => "Topics",
   :posts_heading => "Posts",
   :last_post_heading => "Last Post",
   :no_forums => "There are no forums.", 
   :administrator_should_create_forum => "Maybe an administrator should create one.",
   :you_should_create_forum => "Maybe you should create a forum.",
   :forum_statistics => "Forum Statistics",
   :posts_per_topic => "Posts per topic",
   :recent_users => "Users on in the last 15 minutes",
   :registered_users => "Registered Users",
   :home => "Home",
   :edit_profile => "Edit Profile",
   :member_list => "Member List",
   :search => "Search",
   :new_message => "new message",
   :logout => "Logout",
   :time_now => "The time is now",
   :viewing_forum => "Viewing forum",
   :new_topic => "New Topic",
   :moderation_heading => "Moderation",
   :topic_heading => "Topic",
   :replies_heading => "Replies",
   :views_heading => "Views",
   :author_heading => "Author",
   :ago => "ago",
   :by => "by"
  }
}

When I have a string I want translated in my app I will simply call stuff like t(:author_heading) and Rails will look up the correct translation for it, which in this case is just “Author”.

Now if I had another translation file, say locales/es.rb and I had Spanish users on rboard they could select a locale from their profile page and that would store it as a string on their user record. To translate this, we can use a before_filter on the application controller:

app/controllers/application.rb

class ApplicationController < ActionController::Base
  before_filter :set_locale
  def set_locale
    I18n.locale = current_user.locale if logged_in?
  end
end

This will set the locale to whatever the user has set, providing that they are logged in.

Interpolation

If you wish to insert a value into a translation you can use interpolation. To do this you can specify the t method call like this:

in a i18n-friendly file somewhere

<%= t(:welcome, :user => current_user.login) %>

And then in your locales file specify this:

locales/en-AU.rb

:welcome => "welcome {{user}}!"

And the output of the translation will now be “welcome Ryan!” or whatever the user login was.

Counting

If you have a translation such as :x_new_messages in your translation file and you want the output of this translation to be correctly pluralized you can pass the count option to this:

In any t method supporting files

<%= t(:x_new_messages, :count => current_user.messages.size) %>

The x_ prefix to our translation is not important, it’s just there to show us that this translation may return different results depending on the count that is passed to it.

Then in your translation file you can do:

locales/en-AU.rb

:x_new_messages => {:zero => 'No new messages', :one => 'One new message', :other => '{{count}} new messages'}

And depending on the value of count it will return one of those three outcomes.

Forcing a Locale

If you want to force a locale on a single translation you can do this by specifying the :locale to the t method call like so:

<%= t(:english, :locale => "en-AU") %>

And this will always show the en-AU translation of the english key in the en-AU.rb locale file.

Alternative Translations

If one of your translations does not match like:

<%= t(:norsk) %>

You can have I18n fall back to any number of other translations:

<%= t(:norsk, :default => [:norwegian, :up_north, :northwards, "norway"]) %>

I18n will attempt to get a default translation from the options specified and will select the first one. If all translations failed then the string version, “norway” will be outputted.

Retrieving Multiple Translations

To get multiple translations back at the same time you can specify an array as the first argument to the t method.

<%= t(:forums, :topics) %>

Assuming you have correct translations for forums and topics you will get the translated versions returned in an array. Assuming you don’t have the correct translations for forums OR topics you will get back a string version of whatever translation is missing, possibly wrapped in a <span class=’translation_missing’></span>.

Further translation files can be found at Sven Fuch’s Github Repository

This is genius!

October 24th, 2008 by Radar

I read Mike Gunderloy’s blog post today and afterwards thought he was crazy! I thought you couldn’t do Blog.find(”1-title”).

But you can.

If you pass in 1-title as params[:id] for any action and then pass it to find, find will do its “thing” and just execute find(1), giving you pretty URLs AND pretty code.

I later found out this was because find just calls to_i when it gets given strings, and calling it on “1-title” will give you “1″.

Ruby Quiz - Matricies

October 22nd, 2008 by Radar
nb = 5
distance = Array.new(nb, Array.new(nb))
k = 0
(0...nb).each do |i|
  (0...nb).each do |j|
    distance[j][i] = k +=1
  end
end
 
puts distance.inspect

This code should generate:
[[1,6,11,16,21], [2,7,12,17,22], [3,8,13,18,23], [4,9,13,19,25], [5,10,15,20,25]]

But generates:
[[5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25]]

I learned why today, and I wonder if anyone else knows.

Did you (Rails) Rumble?

October 20th, 2008 by Radar

NO

I spent the weekend learning (read: having an affair with) Merb. I’m porting rboard to mboard whenever I feel like doing some merb. This is in the interest of seeing how much merb actually kicks Rails’ ass and a learning experience for me.

Also, Merb’s source code is very, very pretty.

Throat Cramps

October 16th, 2008 by Radar

Occasionally when I’m moving my head I get these throat cramps just on the right side of my throat. During these cramping phases the muscle (?) that moves up and down when you swallow (have a look in the mirror and watch your throat as you swallow, you’ll know what I mean) is what cramps. This can be extremely painful and I know of nobody else who gets these. I can only describe it as a cramp. There is a large sharp pain (kind of like when you get hit in the throat) when swallowing and a slightly lesser pain when I tilt my head backwards or to the left. Again, this only happens on one side of my throat.

I was prescribed anti-histamine tablets last year for this problem and it’s only manifested itself 4 times since then, the last 2 times have been within a month of each other. Generally, tilting my head back and drinking about a litre of water helps, but not the last two times. The last two times I’ve had to wait it out, and it’s been 3 hours and 1 hour respectively.

Has anybody out there in the blogosphere heard of this before?

Two Guys Break Into A Car…

October 9th, 2008 by Radar

Well, I’ll assume it was two. Some idiot(s) in the middle of the night smashed the corner of my back-right window and rifled through my car looking for something. Obviously they didn’t find it because the car is still there. They changed the gearstick to reverse, took off the handbrake and moved an American flag I had in the boot into the backseat (I know! The outrage!). Everything’s still in the car, just in more disarray than usual.