<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Matthew Rudy Jacobssee me swimGithubsee some of my codeThought SauceHire me in Hong Kong</description><title>RudyGems</title><generator>Tumblr (3.0; @rudygems)</generator><link>http://rudygems.com/</link><item><title>cd -Tmp-</title><description>&lt;p&gt;How do I cd to a directory starting with a hypen (-)?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;
&lt;pre&gt;# /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 option
cd: usage: cd [-L|-P] [dir]

# quote it
$ cd '-Tmp-'
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]

# double quote it
$ cd "-Tmp-"
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]

# escape it in the quotes
$ cd '\-Tmp-'
-bash: cd: \-Tmp-: No such file or directory

# escape it in the double quotes
$ cd "\-Tmp-"
-bash: cd: \-Tmp-: No such file or directory

# try a "./" hack
$ cd ./-Tmp-/

$ echo "WHOOP"
WHOOP&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/7003518791</link><guid>http://rudygems.com/post/7003518791</guid><pubDate>Tue, 28 Jun 2011 07:16:16 +0100</pubDate><category>bash</category><category>cd</category></item><item><title>Fed up of `bundle exec rake`? Control your `rage`!</title><description>&lt;p&gt;For the past year we&amp;#8217;ve all been happy.&lt;/p&gt;
&lt;p&gt;rake was stable at 0.8.7&lt;/p&gt;
&lt;p&gt;You could run&lt;/p&gt;
&lt;pre&gt;rake&lt;/pre&gt;
&lt;p&gt;In any project and it&amp;#8217;d just work.&lt;/p&gt;
&lt;p&gt;But now, with the release of rake 0.9.0, sometimes we get this&lt;/p&gt;
&lt;pre&gt;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)
&lt;/pre&gt;
&lt;p&gt;And there&amp;#8217;s a simple solution.&lt;/p&gt;
&lt;h2&gt;&lt;a href="https://gist.github.com/1003927"&gt;RAGE!&lt;/a&gt;&lt;/h2&gt;
&lt;pre&gt;#!/usr/bin/env bash
if [ -f Gemfile ]; then
  bundle exec rake $@
else
  rake $@
fi&lt;/pre&gt;
&lt;p&gt;Either copy and paste &lt;a href="https://gist.github.com/1003927"&gt;the gist&lt;/a&gt; into an executable (~/bin/rage maybe)&lt;/p&gt;
&lt;p&gt;Or follow these instructions;&lt;/p&gt;
&lt;pre&gt;git clone git://gist.github.com/1003927.git ~/rage-gist
mkdir ~/bin
cp ~/rage-gist/rage ~/bin/
chmod a+x ~/bin/rage&lt;/pre&gt;
&lt;p&gt;As long as ~/bin is in your path you should be set.&lt;/p&gt;
&lt;pre&gt;rage db:migrate test --trace&lt;/pre&gt;
&lt;p&gt;BOOM!&lt;/p&gt;</description><link>http://rudygems.com/post/6097850437</link><guid>http://rudygems.com/post/6097850437</guid><pubDate>Thu, 02 Jun 2011 05:29:00 +0100</pubDate><category>gist</category><category>rake</category><category>bash</category></item><item><title>I forgot to commit to a feature branch!</title><description>&lt;p&gt;So I just committed to master&lt;/p&gt;
&lt;pre&gt;commit b17a1fbe8f5d59c24a1f2bb50c9905f8345263f5a
Author: Jeffrey Giraffe &amp;lt;Jeffrey.T.Giraffe@gmail.com&amp;gt;
Date:   Wed May 18 18:22:22 2011 +0800
  Started work on an exciting new feature.
&lt;/pre&gt;
&lt;p&gt;But I shouldn&amp;#8217;t have.&lt;/p&gt;
&lt;p&gt;All features should be in a &amp;#8220;feature branch&amp;#8221;&lt;/p&gt;
&lt;p&gt;How do I move my commit onto a different branch?&lt;/p&gt;
&lt;p&gt;Luckily I haven&amp;#8217;t pushed yet.&lt;/p&gt;
&lt;p&gt;So just start my &amp;#8220;feature branch&amp;#8221; right now.&lt;/p&gt;
&lt;pre&gt;git checkout -b exciting-new-feature
git push origin exciting-new-feature&lt;/pre&gt;
&lt;p&gt;Then go back to master, and undo the commit&lt;/p&gt;
&lt;pre&gt;git checkout master
git reset --hard HEAD~1&lt;/pre&gt;
&lt;p&gt;Or if there are 3 commits&lt;/p&gt;
&lt;pre&gt;git reset --hard HEAD~3&lt;/pre&gt;
&lt;p&gt;Of course, if I&amp;#8217;ve already pushed this would be a little more tricky.&lt;/p&gt;
&lt;p&gt;I suggest (for verbosity) you shouldn&amp;#8217;t try to do anything fancy.&lt;/p&gt;
&lt;p&gt;Just revert it&lt;/p&gt;
&lt;pre&gt;git revert HEAD&lt;/pre&gt;
&lt;p&gt;and humbly explain why&lt;/p&gt;
&lt;pre&gt;Revert "Started work on an exciting new feature."

This commit is not ready to be on master yet,
and has been moved onto the branch "exciting-new-feature"

This reverts commit b17a1fbe8f5d59c24a1f2bb50c9905f8345263f5a.
&lt;/pre&gt;
&lt;p&gt;Boom!&lt;/p&gt;</description><link>http://rudygems.com/post/5603783386</link><guid>http://rudygems.com/post/5603783386</guid><pubDate>Wed, 18 May 2011 11:45:00 +0100</pubDate><category>git</category><category>undo</category></item><item><title>Running a Test Case only when we have internet</title><description>&lt;p&gt;So I have some tests for geocoding, that I want to be run live.&lt;/p&gt;
&lt;pre&gt;test "geocoding" do
  record = Address.create!(:address =&amp;gt; "Pretty Cottage, Winding Road, Beautiful Country")
  assert_equal 51.59011, record.latitude
  assert_equal -2.995398, record.longitude
end
&lt;/pre&gt;
&lt;p&gt;Of course, these will fail when there&amp;#8217;s no internet.&lt;/p&gt;
&lt;p&gt;My choices;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;mock the geocoding API&lt;/li&gt;
&lt;li&gt;let them fail&lt;/li&gt;
&lt;li&gt;only run this test when there&amp;#8217;s internet&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;I chose the latter.&lt;/p&gt;
&lt;p&gt;How do I know I have internet connection?&lt;/p&gt;
&lt;p&gt;Can I ping google?&lt;/p&gt;
&lt;pre&gt;system "ping -q -c 1 -t 1 google.com 1&amp;gt; /dev/null" #=&amp;gt; true / false&lt;/pre&gt;
&lt;p&gt;Complication!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;the above works on OSX (where -t1 sets a timeout of 1 second)&lt;/p&gt;
&lt;p&gt;but on Linux -t has a different meaning, and -w1 sets the timeout&lt;/p&gt;
&lt;p&gt;Compromise: ignore timeouts for the moment&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;system "ping -q -c 1 google.com 1&amp;gt; /dev/null" #=&amp;gt; true / false&lt;/pre&gt;

&lt;p&gt;Stick this in a method&lt;/p&gt;
&lt;pre&gt;def requires_internet!
  if can_ping_google?
    yield
  else
    flunk "this test needs to be run when there is internet"
  end
end
&lt;/pre&gt;
&lt;p&gt;Now incorporate this into our test.&lt;/p&gt;
&lt;pre&gt;test "geocoding" do
  requires_internet! do
    record = Address.create!(:address =&amp;gt; "Pretty Cottage, Winding Road, Beautiful Country")
    assert_equal 50.0, record.latitude
    assert_equal -0.3, record.longitude
  end
end
&lt;/pre&gt;
&lt;p&gt;Done.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s &lt;a title="get the gist?" href="https://gist.github.com/976285"&gt;the gist&lt;/a&gt;. Fork it and make it better!&lt;/p&gt;</description><link>http://rudygems.com/post/5573479052</link><guid>http://rudygems.com/post/5573479052</guid><pubDate>Tue, 17 May 2011 12:08:00 +0100</pubDate><category>testing</category><category>internet_connection</category></item><item><title>I broke RubyGems.org</title><description>&lt;p&gt;Yes that&amp;#8217;s right.&lt;/p&gt;
&lt;p&gt;I broke RubyGems.org.&lt;/p&gt;
&lt;p&gt;No April Fools Joke! (although this did happen after midnight HKT)&lt;/p&gt;
&lt;p&gt;&amp;#8230; I&amp;#8217;ve hidden the cause so they have a chance to fix it&amp;#8230;&lt;/p&gt;
&lt;p&gt;&amp;#8230; but its a unicode thing &amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;&lt;/blockquote&gt;
&lt;p&gt;I packaged it with &lt;a title="gem-this makes you a simple `gem this` away from releasing a gem!" href="https://github.com/lazyatom/gem-this"&gt;gem-this&lt;/a&gt;,  and did a `gem push` it turned out &lt;a href="http://rubygems.org"&gt;http://rubygems.org&lt;/a&gt; was down!&lt;/p&gt;
&lt;p&gt;I went to bed hoping it would go away, and woke up on April 1st morning to find an email;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;Hi Matthew! Looks like you just found a bug that made our homepage unhappy.&lt;br/&gt;&lt;br/&gt;=&amp;gt; #&amp;lt;Rubygem id: 39928, name: &amp;#8230;,&lt;br/&gt;&lt;br/&gt;I straight up deleted that gem. Can you send or paste the gem/gemspec&lt;br/&gt;with that so we can make sure this doesn&amp;#8217;t happen again?&lt;br/&gt;&lt;br/&gt;-Nick&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;So, there you go!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Rubygems.org currently can&amp;#8217;t support unicode gem names!&lt;/span&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/4250990827</link><guid>http://rudygems.com/post/4250990827</guid><pubDate>Fri, 01 Apr 2011 04:52:00 +0100</pubDate><category>unicode</category><category>ruby</category><category>gems</category></item><item><title>Upgrading Postgres 8.4 to 9.0 with Homebrew</title><description>&lt;p&gt;I hoped it&amp;#8217;d be as simple as a `brew install postgresql`&lt;/p&gt;
&lt;p&gt;And it almost was.&lt;/p&gt;
&lt;p&gt;But&amp;#8230;&lt;/p&gt;
&lt;pre&gt;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.&lt;/pre&gt;
&lt;p&gt;How do I fix the data files?&lt;/p&gt;
&lt;p&gt;Turns out there is a `pg_update` method to do this for you.&lt;/p&gt;
&lt;p&gt;But it requires a bit of manual work.&lt;/p&gt;
&lt;pre&gt;# First of all stop the server
launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

# backup the old data directory
mv /usr/local/var/postgres /usr/local/var/postgres.old

# now create a fresh postgres 9 data directory
initdb /usr/local/var/postgres&lt;/pre&gt;
&lt;p&gt;Now we&amp;#8217;re ready to do the upgrade.&lt;/p&gt;
&lt;pre&gt;pg_upgrade -d /usr/local/var/postgres.844/ -D /usr/local/var/postgres -b /usr/local/Cellar/postgresql/8.4.4/bin -B /usr/local/Cellar/postgresql/9.0.3/bin
...
Upgrade complete
----------------&lt;/pre&gt;
&lt;p&gt;Boom Ting&lt;/p&gt;
&lt;p&gt;Now just add the launch control back in and we&amp;#8217;re off.&lt;/p&gt;
&lt;pre&gt;cp /usr/local/Cellar/postgresql/9.0.3/org.postgresql.postgres.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist&lt;/pre&gt;</description><link>http://rudygems.com/post/3460770239</link><guid>http://rudygems.com/post/3460770239</guid><pubDate>Wed, 23 Feb 2011 07:35:00 +0000</pubDate></item><item><title>Hong Kong Ruby Group Christmas Photo</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_ldjsb9GeTr1qzqhg9o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Hong Kong Ruby Group Christmas Photo&lt;/p&gt;</description><link>http://rudygems.com/post/2342419598</link><guid>http://rudygems.com/post/2342419598</guid><pubDate>Fri, 17 Dec 2010 01:04:18 +0000</pubDate><category>ruby</category><category>hk</category><category>meetup</category></item><item><title>Javascript parseInt() may not do what you expect!</title><description>&lt;p&gt;I was shocked today to find I&amp;#8217;d introduced a bug.&lt;/p&gt;
&lt;p&gt;It manifested itself like this;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lcudp52ibv1qzqesv.png"/&gt;&lt;/p&gt;
&lt;p&gt;This might seem ok.&lt;/p&gt;
&lt;p&gt;Except the &amp;#8220;Number of repayments&amp;#8221; is set by javascript as;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;the number of days interest&lt;/p&gt;
&lt;p&gt;less the number of days before repayment begins&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Looking at the dates, the &amp;#8220;number of days before repayment begins&amp;#8221; should be 2.&lt;/p&gt;
&lt;p&gt;But the difference is -6.&lt;/p&gt;
&lt;p&gt;Something is wrong.&lt;/p&gt;
&lt;p&gt;And the answer is here;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;var date_from_field = function(field_id) {&lt;br/&gt;  var field = $(&amp;#8220;#&amp;#8221;+field_id);&lt;br/&gt;  var year, month, day;&lt;br/&gt;&lt;br/&gt;  var date_bits = field.val().split(&amp;#8220;-&amp;#8220;);&lt;br/&gt;  var year  = parseInt(date_bits[0]);&lt;br/&gt;  var month = parseInt(date_bits[1]);&lt;br/&gt;  var day = parseInt(date_bits[2]);&lt;br/&gt;  &lt;br/&gt;  return new Date(year,month-1,day);&lt;br/&gt;};&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I take a date field&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;lt;input type=&amp;#8221;date&amp;#8221; value=&amp;#8221;2010-12-08&amp;#8221; /&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I grab the value&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;2010-12-08&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I split it into year, month, and day&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[&amp;#8220;2010&amp;#8221;, &amp;#8220;12&amp;#8221;, &amp;#8220;08&amp;#8221;]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I turn them into integers&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[2010, 12, 0]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Then I make them into a date&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;new Date(2010,11,0); // Tue Nov 30&amp;#160;2010&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;No problem!&lt;/p&gt;
&lt;p&gt;Except&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;2010-12-08&amp;#8221;&amp;#160;!= Tue Nov 30&amp;#160;2010&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The problem is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;parseInt(&amp;#8220;08&amp;#8221;) == 0&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;parseInt(&amp;#8220;08&amp;#8221;, 10) == 8&lt;br/&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;#8220;08&amp;#8221; is 0 in octal&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Always use parseInt(something, 10)&lt;br/&gt;&lt;/strong&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/2080013000</link><guid>http://rudygems.com/post/2080013000</guid><pubDate>Fri, 03 Dec 2010 07:59:19 +0000</pubDate></item><item><title>Bundler as a Gemfile dependency</title><description>&lt;p&gt;Bundler is still a work in progress, so you can expect things to change.&lt;/p&gt;
&lt;p&gt;One of these things that has changed between Bundler 1.0.6 and Bundler 1.0.7 is that the &amp;#8220;METADATA&amp;#8221; field has been removed.&lt;/p&gt;
&lt;p&gt;So I&amp;#8217;m running Bundler 1.0.7 (with no METADATA) and my colleagues are running 1.0.6 (with METADATA)&lt;/p&gt;
&lt;p&gt;I keep getting this diff.&lt;/p&gt;
&lt;blockquote&gt;$ git diff Gemfile.lock&lt;br/&gt;diff &amp;#8212;git a/Gemfile.lock b/Gemfile.lock&lt;br/&gt;index ec585b3..ee6ba65&amp;#160;100644&lt;br/&gt;&amp;#8212;- a/Gemfile.lock&lt;br/&gt;+++ b/Gemfile.lock&lt;br/&gt;@@ -221,3 +221,7 @@ DEPENDENCIES&lt;br/&gt;   whitelist_mail_proxy&lt;br/&gt;   will_paginate!&lt;br/&gt;   zipruby&lt;br/&gt;-&lt;br/&gt;-&lt;br/&gt;-METADATA&lt;br/&gt;-  version: 1.0.6&lt;br/&gt;&lt;/blockquote&gt;
&lt;p&gt;I want bundler to manage itself&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;# self-referential&lt;br/&gt;gem &amp;#8220;bundler&amp;#8221;, &amp;#8220;&amp;gt;=1.0.7&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And it works&lt;/p&gt;
&lt;p&gt;but the message is a bit unpretty&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;RudiMac:merlot matthew$ bundle install&lt;br/&gt;&lt;br/&gt;Fetching source index for &lt;a href="http://rubygems.org/"&gt;http://rubygems.org/&lt;/a&gt;&lt;br/&gt;Bundler could not find compatible versions for gem &amp;#8220;bundler&amp;#8221;:&lt;br/&gt;  In Gemfile:&lt;br/&gt;    bundler (&amp;gt;= 1.0.7)&lt;br/&gt;&lt;br/&gt;  Current Bundler version:&lt;br/&gt;    bundler (1.0.6)&lt;br/&gt;&lt;br/&gt;Your version of Bundler is older than the one requested by the Gemfile.&lt;br/&gt;Perhaps you need to update Bundler by running `gem install bundler`.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I need to use &amp;#8220;gem install&amp;#8221;?&lt;/p&gt;
&lt;p&gt;I wonder if we can patch bundler to install itself.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I recommend you always have a &amp;#8220;&amp;gt;= x.x.x&amp;#8221;&amp;#8230; just for jokes try setting&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;gem &amp;#8220;bundler&amp;#8221;, &amp;#8220;1.0.6&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://rudygems.com/post/1668122226</link><guid>http://rudygems.com/post/1668122226</guid><pubDate>Wed, 24 Nov 2010 09:39:00 +0000</pubDate><category>ruby</category><category>bundler</category><category>gem</category></item><item><title>Even more Ruby in Chinese</title><description>&lt;p&gt;I realised I can write even more Ruby in Chinese.&lt;/p&gt;
&lt;p&gt;The only gotchas are;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;don&amp;#8217;t attempt to use Chinese punctuation （”‘＝＋－，。）&lt;/li&gt;
&lt;li&gt;it doesn&amp;#8217;t recognise Chinese as uppercase, so you can&amp;#8217;t start a class or Constant name with a chinese character&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;So here is my code.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;# encoding: utf-8

class C动物

  def initialize(名字)
    @名字 = 名字
  end
  attr_reader :名字

  def 朋友?(别的)
    true
  end

  def 吃了?
    false
  end

end

class C狗 &amp;lt; C动物
  
  def 朋友?(别的)
    !别的.is_a?(C马泰)
  end

end

class C人 &amp;lt; C动物
end

class C马泰 &amp;lt; C人
  
  def 吃了?(别的)
    别的.is_a?(C狗)
  end

end

我=C马泰.new("马泰")
puts "我的名字是#{我.名字}"
她=C人.new("张学敏")
puts "她的名字是#{她.名字}"

狗=C狗.new("阿财")
puts "狗的名字是#{狗.名字}"

puts "狗是我的朋友吗？#{我.朋友?(狗)}"
puts "我是狗的朋友吗？#{狗.朋友?(我)}"

puts "狗吃了我吗？#{狗.吃了?(我)}"
puts "我吃了狗吗？#{我.吃了?(狗)}"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See the full gist at &lt;a href="https://gist.github.com/711563"&gt;&lt;a href="https://gist.github.com/711563"&gt;https://gist.github.com/711563&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Maybe I should write a plugin for rails.&lt;/p&gt;</description><link>http://rudygems.com/post/1657758522</link><guid>http://rudygems.com/post/1657758522</guid><pubDate>Tue, 23 Nov 2010 10:26:00 +0000</pubDate><category>ruby</category><category>chinese</category><category>utf8</category></item><item><title>Ruby in Chinese</title><description>&lt;p&gt;in Ruby 1.8, if you try and assign a variable&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;你=&amp;#8221;ni3&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;you&amp;#8217;ll get an error&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Invalid char `\344&amp;#8217; in expression&lt;br/&gt;Invalid char `\275&amp;#8217; in expression&lt;br/&gt;Invalid char `\240&amp;#8217; in expression&lt;br/&gt;syntax error, unexpected &amp;#8216;=&amp;#8217;&lt;br/&gt;你= &amp;#8220;ni3&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But in Ruby 1.9 it actually works.&lt;/p&gt;
&lt;p&gt;You just need to add a magic &amp;#8220;coding: uft-8&amp;#8221; header to your ruby file.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;# coding: utf-8&lt;br/&gt;你= &amp;#8220;ni3&amp;#8221;&lt;br/&gt;好= &amp;#8220;hao3&amp;#8221;&lt;br/&gt;puts(你+好)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Wham!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;matthew@RuPro:~$ ruby chinese.rb &lt;br/&gt;ni3hao3&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;(if you can&amp;#8217;t write chinese, steal my gist &lt;a href="http://gist.github.com/613670"&gt;http://gist.github.com/613670&lt;/a&gt;)&lt;/p&gt;</description><link>http://rudygems.com/post/1290835239</link><guid>http://rudygems.com/post/1290835239</guid><pubDate>Mon, 11 Oct 2010 13:16:28 +0100</pubDate><category>ruby</category><category>chinese</category><category>code</category><category>utf8</category></item><item><title>How to delete a file from Git History</title><description>&lt;p&gt;I always think about this problem;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;What happens if I accidentally commit my password into a git repository?&lt;/p&gt;
&lt;p&gt;Surely it&amp;#8217;ll be there forever?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Or&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Oh man&amp;#8230; I just committed a 700mb video file into the repository&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s going to take forever to deploy&amp;#8230;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&amp;#8217;ve always known &amp;#8220;get rebase&amp;#8221; will probably be the answer&lt;/p&gt;
&lt;p&gt;Luckily &lt;a title='The "Pro Git" book' href="http://progit.org/book/ch6-4.html"&gt;ProGit&lt;/a&gt; knows exactly what to do. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;git filter-branch &amp;#8212;tree-filter &amp;#8216;some-bash-command&amp;#8217; HEAD&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So here&amp;#8217;s my example of how to use it.&lt;/p&gt;
&lt;p&gt;I’ve accidentally added a picture of my bum to this rep.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ git show 84c344&lt;br/&gt;commit 84c344c1874736a6d063ed45abe21e20815525b9&lt;br/&gt;Author: Matthew Rudy Jacobs &amp;lt;MatthewRudyJacobs@gmail.com&amp;gt;&lt;br/&gt;Date:   Wed Sep 15&amp;#160;18:25:35&amp;#160;2010 +0800&lt;br/&gt;&lt;br/&gt;  add my bum&lt;br/&gt;&lt;br/&gt;diff &amp;#8212;git a/mybum.jpg b/mybum.jpg&lt;br/&gt;new file mode 100644&lt;br/&gt;index 0000000..018be38&lt;br/&gt;&amp;#8212;- /dev/null&lt;br/&gt;+++ b/mybum.jpg&lt;br/&gt;@@ -0,0 +1 @@&lt;br/&gt;+a picture of my bum&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;so let&amp;#8217;s try and wipe it from history.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ git filter-branch &amp;#8212;tree-filter &amp;#8216;rm -f mybum.jpg&amp;#8217; HEAD&lt;br/&gt;Rewrite 76a50a3b1b3263d84517c8e6241ec0bf2bf36fdc (4/4)&lt;br/&gt;Ref &amp;#8216;refs/heads/master&amp;#8217; was rewritten&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;now commit 84c344 is still there, but it is not in our branch.&lt;br/&gt;Looking at git log, I can see it&amp;#8217;s been rewritten to f59366&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ git show f59366&lt;br/&gt;commit f59366420a8b753de5a0d2812e0abbfb95fccfdf&lt;br/&gt;Author: Matthew Rudy Jacobs &amp;lt;MatthewRudyJacobs@gmail.com&amp;gt;&lt;br/&gt;Date:   Wed Sep 15&amp;#160;18:25:35&amp;#160;2010 +0800&lt;/p&gt;
&lt;p&gt;    add my bum&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;so my bum is no longer there. In the working tree, or in history.&lt;/p&gt;
&lt;p&gt;Right now &lt;strong&gt;DON&amp;#8217;T git pull&lt;/strong&gt; it will merge your commits with the original commits.&lt;/p&gt;
&lt;p&gt;You&amp;#8217;ll have achieved nothing (except doubling the number of commits)&lt;/p&gt;
&lt;p&gt;I don&amp;#8217;t have an elegant solution&amp;#8230; but this seems the only way.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;delete all remote repositories&lt;/p&gt;
&lt;p&gt;and push to them again&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&amp;#8217;m sure there&amp;#8217;s a better way&amp;#8230; but I haven&amp;#8217;t found it.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s my example repo &lt;a href="http://github.com/matthewrudy/git-rebase-test"&gt;&lt;a href="http://github.com/matthewrudy/git-rebase-test"&gt;http://github.com/matthewrudy/git-rebase-test&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;go play!&lt;/p&gt;</description><link>http://rudygems.com/post/1125902229</link><guid>http://rudygems.com/post/1125902229</guid><pubDate>Wed, 15 Sep 2010 11:40:00 +0100</pubDate><category>git</category><category>tips</category><category>delete</category></item><item><title>git pp (git push &amp;&amp; git pull)</title><description>&lt;p&gt;I am addicted to committing (not commitment).&lt;/p&gt;
&lt;p&gt;I make small, distinct commits all the time.&lt;/p&gt;
&lt;p&gt;But the consequence of this is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ git push origin master&lt;/p&gt;
&lt;p&gt;To git@myServer:myRepo.git&lt;br/&gt; &amp;#160;! [rejected]        master -&amp;gt; master (non-fast-forward)&lt;br/&gt;  error: failed to push some refs to &amp;#8216;git@myServer:myRepo.git&amp;#8217;&lt;/p&gt;
&lt;p&gt;To prevent you from losing history, non-fast-forward updates were rejected&lt;/p&gt;
&lt;p&gt;Merge the remote changes (e.g. &amp;#8216;git pull&amp;#8217;) before pushing again.  See the&lt;br/&gt;&amp;#8216;Note about fast-forwards&amp;#8217; section of &amp;#8216;git push &amp;#8212;help&amp;#8217; for details.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I hate getting push failures.&lt;/p&gt;
&lt;p&gt;But I don&amp;#8217;t trust myself to do a pull beforehand.&lt;/p&gt;
&lt;p&gt;Enter a git alias!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ cat ~/.gitconfig &lt;br/&gt;[alias]&lt;br/&gt;    pp =&amp;#160;!sh -c &amp;#8216;git pull $0 $1 &amp;amp;&amp;amp; git push $0 $1&amp;#8217;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now I am free to &amp;#8220;git pp origin master&amp;#8221; as much as I want.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ git pp origin master&lt;/p&gt;
From myServer:myRepo&lt;br/&gt; * branch            master     -&amp;gt; FETCH_HEAD&lt;br/&gt;Already up-to-date.&lt;br/&gt;Everything up-to-date&lt;br/&gt;&lt;/blockquote&gt;
&lt;p&gt;SAFE!&lt;/p&gt;</description><link>http://rudygems.com/post/1085402153</link><guid>http://rudygems.com/post/1085402153</guid><pubDate>Wed, 08 Sep 2010 08:09:09 +0100</pubDate><category>git</category><category>alias</category><category>config</category></item><item><title>OR logic in gmail filters</title><description>&lt;p&gt;I don&amp;#8217;t want to have to read all the emails from my old job,&lt;/p&gt;
&lt;p&gt;but I do want to read some of them.&lt;/p&gt;
&lt;p&gt;So the obvious answer is using gmail filters, to tag, and archive the ones I don&amp;#8217;t want.&lt;/p&gt;
&lt;p&gt;It turns out the emails I don&amp;#8217;t care about are sent to&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;notifications@somedomain.com&lt;/strong&gt; and &lt;strong&gt;something-notify@otherdomain.com&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I guess it makes sense, but in the filter box we can use the &amp;#8220;&lt;strong&gt;OR&lt;/strong&gt;&amp;#8221; keyword&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;notifications@somedomain.com&lt;strong&gt; OR&lt;/strong&gt; notify@otherdomain.com &lt;strong&gt;&lt;br/&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_l7togsaiBI1qzqesv.jpg"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Boom ting!&lt;/strong&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/1020708326</link><guid>http://rudygems.com/post/1020708326</guid><pubDate>Fri, 27 Aug 2010 18:57:56 +0100</pubDate><category>gmail</category><category>general</category><category>advice</category><category>operators</category></item><item><title>Stop adding methods to Symbol just to make your DSL look pretty!</title><description>&lt;p&gt;I remember the first time I saw &lt;a href="http://datamapper.org/"&gt;Datamapper&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I liked saying &amp;#8220;:something.gt something_else&amp;#8221;.&lt;/p&gt;
&lt;p&gt;It was pretty.&lt;/p&gt;
&lt;p&gt;But after a while I realised it wasn&amp;#8217;t necessary.&lt;/p&gt;
&lt;p&gt;So why are we still building APIs that involve extending Symbol?&lt;/p&gt;
&lt;script src="http://gist.github.com/443165.js?file=symbol-extensions-in-finder-apis.rb"&gt;&lt;/script&gt;&lt;p&gt;&lt;em&gt;I saw &lt;a href="http://railstips.org/blog/archives/2010/06/16/mongomapper-08-goodies-galore/?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+railstips+%28Rails+Tips%29"&gt;this&lt;/a&gt; on an extension called &lt;a href="http://github.com/jnunemaker/plucky"&gt;Plucky&lt;/a&gt; for &lt;a href="http://github.com/jnunemaker/mongomapper"&gt;MongoMapper&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/710107027</link><guid>http://rudygems.com/post/710107027</guid><pubDate>Fri, 18 Jun 2010 04:16:00 +0100</pubDate><category>ruby</category><category>api</category><category>symbol</category><category>sql</category></item><item><title>Ruby Enterprise Edition still faster than Ruby 1.9.2?</title><description>&lt;p&gt;With Ruby 1.9.2 due to ship on July 31st, I thought I&amp;#8217;d take Ruby 1.9.2 preview 3 for a spin.&lt;/p&gt;
&lt;p&gt;A quick&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;rvm install ruby-1.9.2-preview3&lt;/p&gt;
&lt;p&gt;gem install rails prawn erubis&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;#8230; and we&amp;#8217;re done.&lt;/p&gt;
&lt;p&gt;But is it any faster than REE?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What does it mean to be faster?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Perhaps all I care about is how fast my tests run&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;rvm use ruby-1.9.2-preview3&lt;/p&gt;
&lt;p&gt;time rake&lt;/p&gt;
&lt;p&gt;rvm use ree&lt;/p&gt;
&lt;p&gt;time rake&lt;/p&gt;
&lt;p&gt;# repeat..&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;My app:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt; Rails 2.3.6&lt;/li&gt;
&lt;li&gt;rails_xss&lt;/li&gt;
&lt;li&gt;postgres&lt;/li&gt;
&lt;li&gt;~25 models&lt;/li&gt;
&lt;li&gt;~25 controllers&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;My test suite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;~1700 assertions&lt;/li&gt;
&lt;li&gt;~95% &lt;a title="rcov_rails for rails coverage" href="http://github.com/matthewrudy/rcov_rails"&gt;code coverage&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Results;&lt;/strong&gt;&lt;/p&gt;
&lt;script src="http://gist.github.com/421949.js?file=ruby-1.9.2-vs-ree-test-suite"&gt;&lt;/script&gt;&lt;p&gt;So REE is consistently 10% faster at running my test suite than Ruby 1.9.2-preview3&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Does this matter?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Probably not&amp;#8230; but maybe I can use those extra 5 seconds.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(can&amp;#8217;t wait to see if the &lt;a href="http://www.youtube.com/watch?v=ghLCtCwAKqQ"&gt;Phusion.nl&lt;/a&gt; guys can make Ruby 1.9.2 faster&amp;#8230; )&lt;/em&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/655531873</link><guid>http://rudygems.com/post/655531873</guid><pubDate>Wed, 02 Jun 2010 05:40:00 +0100</pubDate><category>ruby</category><category>1.9</category><category>enterprise</category><category>testing</category><category>benchmarks</category></item><item><title>ssh -D is your friend!</title><description>&lt;blockquote&gt;
&lt;p&gt;Are you stuck behind a firewall?&lt;/p&gt;
&lt;p&gt;Does your work block access to facebook?&lt;/p&gt;
&lt;p&gt;Do you want to watch English Telly from abroad?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;SSH -D is your friend.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;All you need to bypass the firewall;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;ssh access to a VPS&lt;/li&gt;
&lt;li&gt;ssh -D8080 me@myserver.com // keep this open&lt;/li&gt;
&lt;li&gt;go to your browser&lt;/li&gt;
&lt;li&gt;set &amp;#8220;connect via SOCKS proxy&amp;#8221; on port 8080&lt;/li&gt;
&lt;li&gt;keep the ssh connection open&lt;/li&gt;
&lt;li&gt;voila!&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Your internet access is now piped via your VPS.&lt;/p&gt;
&lt;p&gt;This means;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;if it is in the UK you can access iPlayer&lt;/li&gt;
&lt;li&gt;if it is in the US you can access Hulu&lt;/li&gt;
&lt;li&gt;if you were in China you can access&amp;#8230; everything&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Boom ting!&lt;/p&gt;</description><link>http://rudygems.com/post/569787317</link><guid>http://rudygems.com/post/569787317</guid><pubDate>Tue, 04 May 2010 03:53:29 +0100</pubDate><category>ssh</category><category>proxy</category><category>vps</category><category>socks</category><category>firewall</category></item><item><title>Rails 3 doesn't allow "open" as a Named Scope</title><description>&lt;p&gt;Rails 3 has involved rewriting pretty much the whole codebase,&lt;/p&gt;
&lt;p&gt;Rails 3 gives off the fragrance of a coherent, cohesive framework.&lt;/p&gt;
&lt;p&gt;But this one kind of annoys me.&lt;/p&gt;
&lt;blockquote&gt;/Users/matthew/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/named_scope.rb:104:in `scope&amp;#8217;: Cannot define scope :open because AbcDef.open method already exists. (ArgumentError)&lt;/blockquote&gt;
&lt;p&gt;So, in Rails 3, when defining a named scope, we can&amp;#8217;t override an existing method.&lt;/p&gt;
&lt;p&gt;This all makes sense, we don&amp;#8217;t want to inadvertently break anything (although I&amp;#8217;d hope your test would catch such a thing)&lt;/p&gt;
&lt;p&gt;But unfortunately, every object in Ruby has an &amp;#8220;open&amp;#8221; method&amp;#8230; so &amp;#8220;open&amp;#8221; suddenly is off the market for named scopes&amp;#8230; bummer&lt;/p&gt;
&lt;p&gt;I spent most of day trying to sort this out&amp;#8230; writing a patch&amp;#8230; trying to convince people to apply it&amp;#8230; but the rails core guys wouldn&amp;#8217;t budge.&lt;/p&gt;
&lt;p&gt;So here&amp;#8217;s a quick hack I put in an initializer&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;# config/initializers/allow_open_as_a_named_scope.rb
require 'active_record'
class ActiveRecord::Base
  class &amp;lt;&amp;lt; self
    alias :_open :open
    undef_method :open
  end
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And we&amp;#8217;re done&amp;#8230;&lt;/p&gt;
&lt;p&gt;Kind of annoying though. I use &amp;#8220;open&amp;#8221; all the time, because it makes sense&lt;/p&gt;
&lt;p&gt;I&amp;#8217;d prefer it if active record just made a logger.warn, and let me make my own decisions&lt;/p&gt;
&lt;p&gt;&lt;a href="http://github.com/matthewrudy/rude-rails/tree/make_named_scopes_warn_rather_than_raise"&gt;My Fork of rails&lt;/a&gt;, &lt;a href="http://github.com/matthewrudy/rails3-doesnt-allow-open-as-a-named-scope"&gt;My Example of the bug&lt;/a&gt;, &lt;a href="http://gist.github.com/306330"&gt;My Undef_Method hack&lt;/a&gt;&lt;/p&gt;</description><link>http://rudygems.com/post/420138339</link><guid>http://rudygems.com/post/420138339</guid><pubDate>Mon, 01 Mar 2010 17:21:37 +0000</pubDate><category>ruby</category><category>rails</category><category>rails3</category><category>activerecord</category><category>named_scope</category></item><item><title>Securing CruiseControl.rb on Nginx</title><description>&lt;p&gt;CruiseControl is great&lt;/p&gt;
&lt;p&gt;Quick and easy to setup&lt;/p&gt;
&lt;p&gt;But takes a few minutes to work out how to secure it.&lt;/p&gt;

&lt;p&gt;we start cruise;&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;cruise@MerlotBuild:~/cruisecontrol.rb$ ./cruise start -d
=&amp;gt; Booting Mongrel
=&amp;gt; Rails 2.3.2 application starting on &lt;a href="http://0.0.0.0:3333"&gt;http://0.0.0.0:3333&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Going directly by IP &lt;a href="http://94.102.144.37:3333"&gt;http://94.102.144.37:3333&lt;/a&gt; we get our cruise install.&lt;/p&gt;
&lt;p&gt;But that&amp;#8217;s not good enough, we need to secure it from the outside world&lt;/p&gt;
&lt;p&gt;In Nginx we do this;&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;server {
  listen 80;
  server_name cruise.matthewrudy.com;
  
  auth_basic "Access";
  auth_basic_user_file /opt/nginx/conf/htpasswd;

  location / {
    proxy_pass http://localhost:3333;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And we&amp;#8217;re almost done&lt;/p&gt;
&lt;p&gt;Except &lt;a href="http://94.102.144.37:3333"&gt;http://94.102.144.37:3333&lt;/a&gt; still works, as mongrel allows requests from any host name&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;cruise@MerlotBuild:~/cruisecontrol.rb$ ./cruise start -d -b 127.0.0.1
=&amp;gt; Booting Mongrel
=&amp;gt; Rails 2.3.2 application starting on &lt;a href="http://127.0.0.1:3333"&gt;http://127.0.0.1:3333&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Does the job&amp;#8230; home&amp;#8230; secure&amp;#8230; safe?&lt;/p&gt;</description><link>http://rudygems.com/post/379741413</link><guid>http://rudygems.com/post/379741413</guid><pubDate>Tue, 09 Feb 2010 10:02:40 +0000</pubDate><category>nginx cruisecontrol</category></item><item><title>How big is my MySQL database?</title><description>&lt;pre&gt;&lt;code class="mysql"&gt;mysql&amp;gt; SELECT table_schema,&lt;br/&gt;  sum(data_length) / 1024 / 1024 "data",&lt;br/&gt;  sum(index_length) / 1024 / 1024 "index",&lt;br/&gt;  sum( data_length + index_length ) / 1024 / 1024 "total"&lt;br/&gt;FROM information_schema.TABLES&lt;br/&gt;GROUP BY table_schema \G;&lt;br/&gt;&lt;br/&gt;*************************** 1. row ***************************&lt;br/&gt;table_schema: aardvarks_development&lt;br/&gt;        data: 5297.32812500&lt;br/&gt;       index: 4407.93750000&lt;br/&gt;       total: 9705.26562500&lt;br/&gt;*************************** 2. row ***************************&lt;br/&gt;table_schema: aardvarks_test&lt;br/&gt;        data: 0.09375000&lt;br/&gt;       index: 0.25000000&lt;br/&gt;       total: 0.34375000&lt;br/&gt;*************************** 3. row ***************************&lt;br/&gt;table_schema: badgers_development&lt;br/&gt;        data: 13.59375000&lt;br/&gt;       index: 16.60937500&lt;br/&gt;       total: 30.2031250&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;as you can see, aardvarks_developpment is almost taking up 10gig&lt;/p&gt;
&lt;p&gt;if we only care about &amp;#8220;test&amp;#8221; databases, we can add a condition on &amp;#8220;table_schema&amp;#8221;&lt;/p&gt;
&lt;pre&gt;&lt;code class="mysql"&gt;mysql&amp;gt; SELECT table_schema,&lt;br/&gt;  sum(data_length) / 1024 / 1024 "data",&lt;br/&gt;  sum(index_length) / 1024 / 1024 "index",&lt;br/&gt;  sum( data_length + index_length ) / 1024 / 1024 "total"&lt;br/&gt;FROM information_schema.TABLES&lt;br/&gt;WHERE table_schema like "%_test"&lt;br/&gt;GROUP BY table_schema \G;&lt;br/&gt;&lt;br/&gt;*************************** 1. row ***************************&lt;br/&gt;table_schema: aardvarks_test&lt;br/&gt;        data: 0.09375000&lt;br/&gt;       index: 0.25000000&lt;br/&gt;       total: 0.3437500&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Boom!&lt;/p&gt;
&lt;p&gt;(credit to &lt;a title="Paul Butcher" href="http://www.paulbutcher.com"&gt;Paul Butcher&lt;/a&gt; for the query)&lt;/p&gt;</description><link>http://rudygems.com/post/206608569</link><guid>http://rudygems.com/post/206608569</guid><pubDate>Wed, 07 Oct 2009 11:33:00 +0100</pubDate><category>mysql</category></item></channel></rss>

