June 2011
2 posts
2 tags
cd -Tmp-
How do I cd to a directory starting with a hypen (-)? # /var/folders/*whatever*/ has a folder named '-Tmp-' $ ls -Caches-/ -Tmp-/ # lets try and CD there $ cd -Tmp- -bash: cd: -T: invalid option cd: usage: cd [-L|-P] [dir] # or maybe make sure its a directory $ cd -Tmp-/ -bash: cd: -T: invalid option cd: usage: cd [-L|-P] [dir] # try and escape the first - $ cd \-Tmp- -bash: cd: -T: invalid...
Jun 28th
4 notes
3 tags
Fed up of `bundle exec rake`? Control your `rage`!
For the past year we’ve all been happy. rake was stable at 0.8.7 You could run rake In any project and it’d just work. But now, with the release of rake 0.9.0, sometimes we get this RudiMac:3rdhome matthew$ rake rake aborted! You have already activated rake 0.9.0, but your Gemfile requires rake 0.8.7. Consider using bundle exec. (See full trace by running task with --trace) And...
Jun 1st
14 notes
May 2011
2 posts
2 tags
I forgot to commit to a feature branch!
So I just committed to master commit b17a1fbe8f5d59c24a1f2bb50c9905f8345263f5a Author: Jeffrey Giraffe <Jeffrey.T.Giraffe@gmail.com> Date: Wed May 18 18:22:22 2011 +0800 Started work on an exciting new feature. But I shouldn’t have. All features should be in a “feature branch” How do I move my commit onto a different branch? Luckily I haven’t pushed yet. So...
May 18th
3 notes
2 tags
Running a Test Case only when we have internet
So I have some tests for geocoding, that I want to be run live. test "geocoding" do record = Address.create!(:address => "Pretty Cottage, Winding Road, Beautiful Country") assert_equal 51.59011, record.latitude assert_equal -2.995398, record.longitude end Of course, these will fail when there’s no internet. My choices; mock the geocoding API let them fail only run this test...
May 17th
2 notes
March 2011
1 post
3 tags
I broke RubyGems.org
Yes that’s right. I broke RubyGems.org. No April Fools Joke! (although this did happen after midnight HKT) … I’ve hidden the cause so they have a chance to fix it… … but its a unicode thing … I packaged it with gem-this, and did a `gem push` it turned out http://rubygems.org was down! I went to bed hoping it would go away, and woke up on April 1st...
Mar 31st
2 notes
February 2011
1 post
Upgrading Postgres 8.4 to 9.0 with Homebrew
I hoped it’d be as simple as a `brew install postgresql` And it almost was. But… RudiMac:merlot matthew$ tail -f /usr/local/var/postgres/server.log FATAL:  database files are incompatible with server DETAIL:  The data directory was initialized by PostgreSQL version 8.4, which is not compatible with this version 9.0.3. How do I fix the data files? Turns out there is a `pg_update`...
Feb 23rd
1 note
December 2010
2 posts
3 tags
Dec 16th
Javascript parseInt() may not do what you expect!
I was shocked today to find I’d introduced a bug. It manifested itself like this; This might seem ok. Except the “Number of repayments” is set by javascript as; the number of days interest less the number of days before repayment begins Looking at the dates, the “number of days before repayment begins” should be 2. But the difference is -6. Something is...
Dec 3rd
November 2010
2 posts
3 tags
Bundler as a Gemfile dependency
Bundler is still a work in progress, so you can expect things to change. One of these things that has changed between Bundler 1.0.6 and Bundler 1.0.7 is that the “METADATA” field has been removed. So I’m running Bundler 1.0.7 (with no METADATA) and my colleagues are running 1.0.6 (with METADATA) I keep getting this diff. $ git diff Gemfile.lock diff —git a/Gemfile.lock...
Nov 24th
3 tags
Even more Ruby in Chinese
I realised I can write even more Ruby in Chinese. The only gotchas are; don’t attempt to use Chinese punctuation (”‘=+-,。) it doesn’t recognise Chinese as uppercase, so you can’t start a class or Constant name with a chinese character So here is my code. # encoding: utf-8 class C动物 def initialize(名字) @名字 = 名字 end attr_reader :名字 def 朋友?(别的) true end ...
Nov 23rd
October 2010
1 post
4 tags
Ruby in Chinese
in Ruby 1.8, if you try and assign a variable 你=”ni3” you’ll get an error Invalid char `\344’ in expression Invalid char `\275’ in expression Invalid char `\240’ in expression syntax error, unexpected ‘=’ 你= “ni3” But in Ruby 1.9 it actually works. You just need to add a magic “coding: uft-8” header to your ruby...
Oct 11th
September 2010
2 posts
3 tags
How to delete a file from Git History
I always think about this problem; What happens if I accidentally commit my password into a git repository? Surely it’ll be there forever? Or Oh man… I just committed a 700mb video file into the repository It’s going to take forever to deploy… I’ve always known “get rebase” will probably be the answer Luckily ProGit knows exactly what to do.  ...
Sep 15th
3 tags
git pp (git push && git pull)
I am addicted to committing (not commitment). I make small, distinct commits all the time. But the consequence of this is $ git push origin master To git@myServer:myRepo.git   ! [rejected]        master -> master (non-fast-forward)   error: failed to push some refs to ‘git@myServer:myRepo.git’ To prevent you from losing history, non-fast-forward updates were rejected ...
Sep 8th
August 2010
1 post
4 tags
OR logic in gmail filters
I don’t want to have to read all the emails from my old job, but I do want to read some of them. So the obvious answer is using gmail filters, to tag, and archive the ones I don’t want. It turns out the emails I don’t care about are sent to notifications@somedomain.com and something-notify@otherdomain.com I guess it makes sense, but in the filter box we can use the...
Aug 27th
1 note
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 now...
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
1 note
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
8 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” that...
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