June 2010
2 posts
4 tags
Stop adding methods to Symbol just to make your...
I remember the first time I saw Datamapper. I liked saying “:something.gt something_else”. It was pretty. But after a while I realised it wasn’t necessary. So why are we still building APIs that involve extending Symbol? I saw this on an extension called Plucky for MongoMapper
Jun 17th
1 note
5 tags
Ruby Enterprise Edition still faster than Ruby...
With Ruby 1.9.2 due to ship on July 31st, I thought I’d take Ruby 1.9.2 preview 3 for a spin. A quick… rvm install ruby-1.9.2-preview3 gem install rails prawn erubis … and we’re done. But is it any faster than REE? What does it mean to be faster? Perhaps all I care about is how fast my tests run rvm use ruby-1.9.2-preview3 time rake rvm use ree time rake #...
Jun 1st
May 2010
1 post
5 tags
ssh -D is your friend!
Are you stuck behind a firewall? Does your work block access to facebook? Do you want to watch English Telly from abroad? SSH -D is your friend. All you need to bypass the firewall; ssh access to a VPS ssh -D8080 me@myserver.com // keep this open go to your browser set “connect via SOCKS proxy” on port 8080 keep the ssh connection open voila! Your internet access is...
May 3rd
March 2010
1 post
5 tags
Rails 3 doesn't allow "open" as a Named Scope
Rails 3 has involved rewriting pretty much the whole codebase, Rails 3 gives off the fragrance of a coherent, cohesive framework. But this one kind of annoys me. /Users/matthew/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/named_scope.rb:104:in `scope’: Cannot define scope :open because AbcDef.open method already exists....
Mar 1st
February 2010
1 post
1 tag
Securing CruiseControl.rb on Nginx
CruiseControl is great Quick and easy to setup But takes a few minutes to work out how to secure it. we start cruise; cruise@MerlotBuild:~/cruisecontrol.rb$ ./cruise start -d => Booting Mongrel => Rails 2.3.2 application starting on http://0.0.0.0:3333 Going directly by IP http://94.102.144.37:3333 we get our cruise install. But that’s not good enough, we need to secure it from...
Feb 9th
October 2009
1 post
1 tag
How big is my MySQL database?
mysql> SELECT table_schema, sum(data_length) / 1024 / 1024 "data", sum(index_length) / 1024 / 1024 "index", sum( data_length + index_length ) / 1024 / 1024 "total" FROM information_schema.TABLES GROUP BY table_schema \G; *************************** 1. row *************************** table_schema: aardvarks_development data: 5297.32812500 index: 4407.93750000 total:...
Oct 7th
1 note
August 2009
1 post
6 tags
Updating RubyGems on Ubuntu 9.04
I don’t know how many times I’ve had to do this. But every time I install Ubuntu again, I get this; matthew@Rudyness:~$ sudo gem update --system ERROR: While executing gem ... (RuntimeError) gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get. The simple fix; matthew@Rudyness:~$ sudo gem install...
Aug 16th
April 2009
1 post
5 tags
Installing Ruby 1.9.1 on Ubuntu 9.04
Now, I’m upset that Jaunty Jackalope doesn’t ship with ruby 1.9.1 as default, and the packaged version is only 1.9.0. So we’re going to have to build it from source. And because we’re all progressive people, we’re not even going to worry about suffixing the executables with `1.9` I can’t be bothered to type `gem1.9` The dependencies are simple; sudo apt-get...
Apr 22nd
March 2009
1 post
Ruby 1.9 becoming the standard?
There’s a lot of talk recently about pushing the Ruby Community onto Ruby 1.9. Now that’s cool, the more people using 1.9 the quicker the issues will get ironed out (people need to be spurred into fixing their libraries) But there is one thing standing in the way of 1.9 being adopted by the whole community, Default Packages Mac OSX comes with 1.8.6 as standard, Ubuntu 8.10 comes...
Mar 27th
January 2009
1 post
7 tags
Expire eTAGs when you redeploy
Rails 2.2’s eTAG functionality is great. def show @article = Article.find(params[:id]) if stale_record(@article) # do something expensive end end protected def stale_record?(record) fresh_when(:etag => [current_user, record], :last_modified => record.updated_at.utc) !request.fresh?(response) end “304 NOT MODIFIED” all around! But this determines...
Jan 19th
December 2008
2 posts
4 tags
setting up a simple git server
On the internet you’ll see people talking about Gitosis, or just giving over all of their git requirements to github. Github is great, but if you just want to do a small personal project, with an off-site repository, go set up your VPS as your main git server. Here’s how you do it. create a “git” user sudo adduser git add your ssh keys to that user ssh-copy-id...
Dec 20th
4 tags
Rails + Rack Middleware
Rails just released Metal! Giving us a great framework to build custom Rack processors alongside our application. Check out this great article over at Soylent Foo. Recently we had a problem where Microsoft Office was somehow issuing OPTIONS request to our site. This was blowing up our RESTful controllers that weren’t invited to the OPTIONS party. We played with Apache rewrites based on...
Dec 17th
November 2008
5 posts
has_one_accessor
HasOneAccessor is a plugin for ActiveRecord that solves the problem of having associations that act like a attribute. Perhaps only a few users have an openid, so it doesn’t make sense to add an :open_id_url column to your :users table. Instead you create a new model OpenId class OpenId < ActiveRecord::Base belong_to :user end class User < ActiveRecord::Base has_one :open_id ...
Nov 30th
6 tags
SolrQuery - build your solr queries dynamically in...
I’ve been using ActsAsSolr for about 6 months. And at work I developed some code to make SOLR queries work a bit like the conditions in ActiveRecord. Check out my library at Github. http://github.com/matthewrudy/solr_query SolrQuery.build(:keyword => "Feather duster" => "feather duster" SolrQuery.build(:keyword => "clean", :organisation => [organisation1,...
Nov 17th
5 tags
UID problems across a shared mount?
We just moved to new Ubuntu servers. We use file-column (with some modifications) to deal with our file uploads. deploy@jgp-web01:/var/www/oursite$ ls -l public/uploaded_file/file_name/000/000/051/585/ total 4 -rw-r--r-- 1 gerhard www-data 2670 2008-11-15 05:09 MatthewJacobsCV.txt deploy@jgp-web02:/var/www/oursite$ ls -l public/uploaded_file/file_name/000/000/051/585/ total 4 -rw-r--r-- 1 deploy...
Nov 15th
3 tags
“svn switch —relocate svn://oldserver svn+ssh://newserver”
– need to move your svn repository?
Nov 12th
4 tags
Nov 1st
October 2008
10 posts
3 tags
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? ...
Oct 24th
“it’s hard enough to push out a great idea, even if you thought of it,...”
– me, talking to Stephen Strudwick about startups, already in Beta, being too scared to pitch to investors!
Oct 19th
6 tags
Rendering layouts that live in /public?
At work we have the following concept. a “site” has a subset of our content a “site” has a url - eg. “oursite.com/stickers” or “stickersNOTvicars.com” a “site” can have its own customised layout, or fall back to the default one How does this work in code? site.articles (pretty simple) a whole load of “route filters”...
Oct 15th
“I didn’t get drunk enough to try the Goggles. Next time!”
Oct 14th
6 tags
Oct 12th
What would happen if you ripped out your Db...
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.
Oct 11th
6 tags
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...
Oct 9th
5 tags
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...
Oct 1st
September 2008
1 post
6 tags
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!!!
Sep 8th