RudyGems

Matthew Rudy Jacobs
see me swim
Github
see some of my code
Thought Sauce
Hire me in Hong Kong
Welcome home DHH!
After a long time, it seems DHH is back, actively commiting to rails.
Getting ready for 2.2 to be released, he’s committed 20 times in the past week.
It’s nice to see.

Welcome home DHH!

After a long time, it seems DHH is back, actively commiting to rails.

Getting ready for 2.2 to be released, he’s committed 20 times in the past week.

It’s nice to see.

Google App Engine to support Ruby?

A recent post on the Google App Engine blog refers to;

“Support for a new runtime language”

That’s got to be ruby…

Imagine a bespoke Sinatra-style minimal framework, with DataMapper bindings to the Google DataStore.

No doubt it’ll be pretty quick to make it work with Merb as well.

AWESOME.

Why did google never reply to my job application asking to work on it?

(if you haven’t seen the videos from last years Google IO, then they’re well worth watching - here)

it’s hard enough to push out a great idea,
even if you thought of it,
and have spent years thinking about it.

If a potential investor is going to take the time, money, and bother to steal your idea,
then someone else is going to buy it from you
before they have a chance.

me, talking to Stephen Strudwick about startups, already in Beta, being too scared to pitch to investors!

Rendering layouts that live in /public?

At work we have the following concept.

  1. a “site” has a subset of our content
  2. a “site” has a url - eg. “oursite.com/stickers” or “stickersNOTvicars.com”
  3. a “site” can have its own customised layout, or fall back to the default one

How does this work in code?

  1. site.articles (pretty simple)
  2. a whole load of “route filters” that match the incoming host
  3. the code I’m writing about

So, historically we did

class ApplicationController
  layout :determine_layout
  def determine_layout
    if File.exists?("#{Rails.root}/public/sites/#{@site.id}/application.rhtml")
      "../../public/sites/#{@site.id}/application"
    else
      "site_default"
    end
  end
end

This was a hack, and it breaks with Rails 2.1.1, so after a day or so playing with the internals of ActionView I discovered this;

append_view_path("#{Rails.root}/public/sites")

And it works!

We just need to set;

"#{@site.id}/application"

as our layout, and we’re away.

Site-specific layouts that live in /public!

I didn’t get drunk enough to try the Goggles. Next time!
 Google Goggles are good enough for me?
On Monday its the LRUG quiz.
Can Google’s entry into drunken embarassment prevention really hold out against my mathematical skills?
Am I just too elite?
At level 5 (the hardest) we still get sums like “6x9”!
Does my mathematical ability really drop that much?
We’ll see tomorrow!

Google Goggles are good enough for me?

On Monday its the LRUG quiz.

Can Google’s entry into drunken embarassment prevention really hold out against my mathematical skills?

Am I just too elite?

At level 5 (the hardest) we still get sums like “6x9”!

Does my mathematical ability really drop that much?

We’ll see tomorrow!

What would happen if you ripped out your Db server?

Does your application and architecture really have failover?

If I broke into your datacentre, ripped out, and hid one of your servers, what would happen?

Is your architecture the biggest hurdle to scaling your web app?

Blain Cook and Joe Stump not talking about Twitter’s scaling issues.

Need to install MySQL gem for OSX?

… but getting errors?

matthew@iRudy:~/code/rails211again $ sudo gem install mysql
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no

*** extconf.rb failed ***
...
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.

Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out

Found the fix

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

a better :delegate method?

So we have;

class Bum
  attr_accessor :pants
  delegate :smelly?, :to => :pants
end

We want to ask;

bum.smelly?

clearly if the bum has pants, then it’s only smelly if the pants are smelly
that’s cool,
but what if the bum has no pants?

>> bum.pants
=> nil

>> bum.smelly?
   NoMethodError: You have a nil object when you didn't expect it!
   The error occurred while evaluating nil.smelly?
     from (__DELEGATION__):2:in `__send__'
     from (__DELEGATION__):2:in `smelly?'
     from (irb):7

this needs to be fixed,
but how?
by default we’d expect it to be nil,
but perhaps we want to assume that actually they’re smelly by default
but what syntax?

delegate :smelly, :to => :pants, :default => true

perhaps?

ActsAsSolr index out of sync?

Faced with a shocking

>> Phrase.find_by_solr ‘book’
RuntimeError: Out of sync!



The id 296452 is in the Solr index but
missing in the database!


Fix it

>> Phrase.solr_delete(“Phrase:296452”)
>> Phrase.solr_commit()

BOOM!!!