January 2010
1 post
December 2009
1 post
November 2009
2 posts
October 2009
1 post
Named Scopes with PostgreSQL
When using chained named scopes that modify the :select finder option, the PostgreSQL adapter appears to give SELECT query preference to the first scope defined:
named_scope :foo, {:select => "foo.*"}
named_scope :bar, {:select => "bar.*"}
Tester.bar.foo.all #=> SELECT bar.* FROM tester...
While it seems somewhat straightforward in this example, when chaining multiple scopes, it is...
September 2009
1 post
Pushing to a different git remote branch
If you have the need to push a local git branch to a differently named remote branch, try this:
git push origin master:refs/heads/experimental
Where “origin” is the remote name, “master” is your local branch name, and “experimental” is the remote branch to push into.
August 2009
1 post
Ignoring database.yml
When database.yml is already in the repository, but you must have a modified local copy:
git update-index --assume-unchanged config/database.yml
July 2009
2 posts
June 2009
1 post
May 2009
2 posts
April 2009
1 post
March 2009
1 post
February 2009
9 posts
Ruby Gems with Autotest Discovery Break Rails
We’ll start off by clarifying which versions of which software I’m currently running:
rails 2.2.2
ZenTest 3.11.1
mbleigh-seed-fu 0.0.3
I’m developing a basic Ruby on Rails application. Using Test::Unit and Shoulda for the test suite. The issue that I kept running into (sadly, for nearly a couple of hours) was this:
loading autotest/rails_rspec
Autotest style...
Functional test for 404s in Rails 2.x
The Ruby on Rails version 2.x ActionController::TestCase thankfully abstracts a lot of the setup of your functional tests. There is a hidden issue, however, a problem that lingers for fully testing your controllers. How do you test for those automatically generated FAIL pages (i.e. 404, 500, 403, etc.)?
Hidden in the TestCase code, there is an answer. By default, all @request calls are made...
Linux is the expert mode of operating systems.
– Nathaniel Bibler
1 tag
Automated Phusion Passenger installation prior to...
The following snippet will run the Phusion Passenger installation script (passenger-install-apache2-module) in an automated fashion. This would allow you to install the software via a boot script:
echo -en "\n\n\n\n" | passenger-install-apache2-module
Application Error
Hoptoad has hopped the toad.
The application has notified...
– Hoptoadapp
1 tag
God Damn Tropicana...
Of course, my last entry is a rant on how horrible the box design is for Tropicana. Now, two days ago, my wife sent me to the grocery store (“uhh ohhh”) … and what’d I get ? Tropicana, No Pulp. Low Acid.
Seriously? All the f’n boxes look the same. REALLY? ReaLLY? I swear I stared at that shelf for .. easily 2 minutes, if not longer … trying to...
1 tag
1 tag
January 2009
4 posts
1 tag
Using the Ruby Array#uniq with custom classes
You may (or may not) have noticed that when you create a custom class in Ruby, Array#uniq — and friends — no longer work as advertised. You can override the eql?, equal?, ==, and still not get it right.
For the solution, you must override both the eql? and hash member methods of your custom object:
class MyFoo
attr_reader :custom_unique_id
# Internally, Ruby converts your...
1 tag
1 tag
Fox News, Fear Imbalance. God, I hate Fox News. Smite them, please.
1 tag
December 2008
6 posts
2 tags
Phusion Passenger 2.0.5 and Ruby
After an hour or so of configuring a new, fresh CentOS 5.2 server, primarily relying on yum repositories, I thought I was nearly done. I installed Apache2, Ruby, rubygems, passenger, …. I was good to go.
Passenger spawn server: symbol lookup error: /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.5/ext/passenger/native_support.so: undefined symbol: RARRAY_LEN
*** Exception NoMethodError in...
3 tags
git and opendiff
git config --global merge.tool opendiff
2 tags
Remotely Securing CentOS
Lets assume you’ve got root access to a CentOS VPS. Further, lets assume you want to secure it in some way. Lets go with the following:
First, create a new, non “root” user which will have sudo privileges. This creates the user, expires their password (prompting them to immediately change it), and sets the password empty.
$ /usr/sbin/useradd my_user_name
$ /usr/bin/chage -d...
1 tag
1 tag
OpenSSL::HMAC vs ruby-hmac Benchmarks
So, I’m writing a gem which requires an HMAC calculation. I came across the ruby-hmac gem, I assume to be maintained by Geoffrey Grosenbach, and was curious to investigate the performance differences between OpenSSL::HMAC and the ruby-hmac gem. I imagine one day, one other person, sometime between now and eternity, somewhere in the universe, maybe … might be interested in the...
November 2008
6 posts
1 tag
sqlite3-ruby and do_sqlite3 don't play well...
After recently installing merb 1.0.1 with datamapper 0.9.7, it appears that datamapper’s do_sqlite3 gem and the sqlite3-ruby gem (used by Rails) do not play nicely together.
MissingSourceFile: no such file to load -- sqlite3
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
The solution was to remove the do_sqlite3 gem until it has been fixed.
2 tags
Generating a Rails application with a specific gem...
I know I’ve seen this elsewhere once or twice, but I can never find it when I need it. So, if you’ve got several rails gems installed (like me):
$ gem list rails
*** LOCAL GEMS ***
rails (2.2.2, 2.1.2, 2.1.1, 2.1.0)
And you’re looking to generate a new Rails application from a specific, not-most-recent version, you’ll need to do the following:
$ rails _2.1.1_...
2 tags
Slightly better performance in Ruby Liquid 1.9.0
With the not even close to recent release of Liquid 1.9.0, I figured I’d clean the dust off of my template benchmark suite and see how the new code lines up with the past:
Liquid 1.7.0:
user system total real
Attribute Access (Liquid) 0.020000 0.000000 0.020000 ( 0.023265)
Conditional Complex (Liquid) 0.030000 0.000000 ...
rankmaniac
Ok, so forgive me for talking about a link posted on Reddit, but this is slightly amusing (at least, to me..). So, there is a TA at CMU who is giving his students an assignment to get a single web page to rank higher in a Google search than his own, when searching for “rankmaniac”.
So, one smart student, got his entry listed on Digg and Reddit, mainly by explaining the purpose and...
1 tag
October 2008
14 posts
2 tags
That merb install is a little crazy
$ sudo gem install merb
Building native extensions. This could take a while...
Successfully installed extlib-0.9.8
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.2
Successfully installed json_pure-1.1.3
Successfully installed rack-0.4.0
Successfully installed thor-0.9.8
Successfully installed merb-core-0.9.10
Successfully installed RubyInline-3.8.1
Successfully installed...
1 tag
McCain's Campaign Politics are Appalling
There’s politics, with finger pointing and skewed statistics about opponent strategies, and that’s fine. But, then there’s defamation. It’s a very fine (legal!) line he’s walking.
It’s ridiculous that people - mostly Republicans in this election cycle - throw around the ‘terrorist’ label in the first place. The whole thing is sickeningly...
1 tag
1 tag
Toes have become an origami meme.
– Robert Lang, TED Talks
1 tag
1 tag
1 tag
1 tag