Something I didn’t know Yesterday #2
Rails (or should i say ActiveSupport) adds a blank? instance method to object that encapsulates the nil? || empty? check that I find myself doing all the time.
A quick review of the source show that the empty? method is added to the following:
# An object is blank if it's nil, empty, or a whitespace string. # For example, "", " ", nil, [], and {} are blank. # # This simplifies # if !address.nil? && !address.empty? # to # if !address.blank?
The full source is actually very simple (I Love Ruby)
class Object def blank? if respond_to?(:empty?) && respond_to?(:strip) empty? or strip.empty? elsif respond_to?(:empty?) empty? else !self end end end class NilClass #:nodoc: def blank? true end end class FalseClass #:nodoc: def blank? true end end class TrueClass #:nodoc: def blank? false end end class Array #:nodoc: alias_method :blank?, :empty? end class Hash #:nodoc: alias_method :blank?, :empty? end class String #:nodoc: def blank? empty? || strip.empty? end end class Numeric #:nodoc: def blank? false end end
Installing Ruby Enterprise Edition on CentOS 5.2
Installing Ruby 1.8.6 on CentOS is not as easy as you would hope. The YUM repositories do not have anywhere near the latest version of ruby so you are forced into installing from source, which means locating and installing many dependancies before building ruby itself.
I have found myself building ruby several times on a new CentOS box after realizing that i had missed a dependancy that was required to use rails or some other ruby component.
I was going to write up a step by step guide to installing Ruby 1.8.6, Rails, MySql, etc… on CentOS 5.2 (and i may still do this) however i have found that the guys who wrote Phusion Passenger have also build a version of Ruby that as well as having a lower memory footprint has a convenient installer that takes the pain out of building from source.
Here are my steps for installing Ruby Enterprise Edition on CentOS 5.2
* 1. ssh into CentOS using your favorite ssh client.
* 2. cd /usr/local/src
(this is where I downloaded the source to you can do this anywhere i guess)
* 3. sudo wget http://rubyforge.org/frs/download.php/41040/ruby-enterprise-1.8.6-20080810.tar.gz
(this is the latest version at the time of writing this post)
* 4. tar xzvf ruby-enterprise-1.8.6-20080810.tar.gz
* 5. sudo ./bin/ruby-enterprise-1.8.6-20080810/installer
The last step starts the convenient installer process that will build everything you need from sources.
I found that first time the script ran i didn’t have MySql or PostgreSQL development header files so i installed them using
* sudo yum install postgresql-devel.i386
* sudo um install mysql-devel.i386
After running the install script again it completed with no errors (you could have just ran the gem install again rather than installing the whole of ruby…)
The great thing about this installer is that it isolates the installation and does not touch any system files so it will not screw up any of your existing ruby installs.
We have been using Ruby Enterprise Edition on one of our projects for a few weeks now and i have to say that it works really well, and it also includes the recent security patches for ruby – sweet!
Oh don’t let the name put you off Ruby Enterprise Edition is actually Open Source – Yay
Daily Dose #2
Spent the best part of the day estimating development effort for an upcoming project… Yarn.
CMS Rails Kit
Ben Curtis has released a new CMS Rails Kit.
The Ruby Hoedown in 10 minutes
The guys from Rails Envy give a quick review of the Ruby Hoedown.
Ruby Visual Identity Team
Want to show the world that you love Ruby? Get a high quality Ruby image for your website.
ar-extensions 0.8.0 released!
Some handy extensions to Active Record that now work with Rails 2.1
Internet Radio on iTunes
Today I realized that I have become totally dependent on the Internet Radio support in iTunes when coding at night!
I spend a good amount of time in the office when the other guys have gone home (dedication ey?) and having a random (usually Dance Music) internet radio station blasting out from across the office creates a fantastic coding environment.
Although, I guess you do need to be the sort of person who likes to code to Music.
I’ve spent the last 4 hours listening to a station called Puls which is the sort of non stop dance music that makes you smile
Try it…
Passenger (mod_rails) Preferences Pane for OS X
If like me you have started using Phusion Pasenger for development sites as well as production sites and you are fortunate to work on a Mac, you will really appreciate the Passenger Preferences Pane by Eloy Duran.
Using it, is as simple as…
Step 1 Point it at your rails folder.
Step 2 Give it a host name to use.
Step 3 LOL, there is no Step Three
Something I didn’t know Yesterday
Using the SVN client you can pass –xml to most of the commands to get a response in XML!
This is great for apps that use the SVN Client API and need to parse the response, for example…
svn log http://svn_url --xml
Will produce a nice XML version of the SVN log.
For good measure you can also use the verbose option to extract even more information…
svn log http://svn_url --xml -v
Pretty cool ey?
Daily Dose #1
A few links to get us going…
IPhone Development
iphone-universal
Normalized CSS & HTML framework to develop iPhone webdev applications
C#
Simple REST Client
Some .NET code for consuming RESTful web services.
Rails
Understanding Map and Reduce
Some underused collection functions in Ruby
OS X Utils
Expandrive
Cool app that allows you to mount a sFtp folder.
MarsEdit
Powerful Blog Publishing For Your Mac.
