Articles

Learning Ruby Through Testing

We have finally published the Ruby Koans to github at edgecase/ruby_koans If you do not have a github account or use git, do not worry, you can click the download button on that page to receive a zip file containing the latest version of the source.

The idea was born thanks to Mike Clark’s blog post about learning Ruby through unit testing. It teaches both language and culture in a self-paced manner.

Merb gets merged into Rails 3.0 !!

Ruby on Rails team broke the news: the alternative Ruby web application framework, Merb, will be merged into Ruby on Rails 3.0.

text-based graph

Just a short and interesting tip today about git log --graph. If you’re confused about where branches are headed or how merges worked, and you’re either too lazy to fire up gitk, gitx, or the GitHub Network Graph, you can get a really simple and fast graphical representation of your commits with this command.

Sans Serif vs Serif

From a talk by Marissa Mayer

Sans is better for spot reading, serif is better for reading paragraphs and sentences.

Lesson: Find research papers / try harder rather than just assuming something is better.

Ruby DBI does find DBD drivers on Mac when using Gem

I found a very nice problem when trying to use DBI on a mac, with the sqlite3 driver
I've been a avid your of dbi, which is a direct database API in Ruby, that allow
low level access to databases.

I've used it on Linux, and Windows against Oracle extensively, and several other databases.

So expected it to work the same. Seems like I hit a small problem in that oh.

My script was telling me no driver. When I ran the dbi command, it showed there was no drivers.
If I used irb, and did a DBI.drivers_available, it told me none.

branching and merging

Branching in git is easier than you’d think. It’s fast (40 characters written to a file), simple (one command to create a branch), and efficient (it doesn’t create a whole copy of your current working state). The branches you create don’t have to exist in the remote repository, so you can use them to test out new features or bug fixes without breaking what’s already working. Perhaps Why Git is Better Than X puts it best:

A Review of Authentication and Access Control for Ruby On Rails

A review of Authentication and Access Control for Ruby On Rails

Previous Articles That Are Related
http://mentalpagingspace.blogspot.com/2007/11/getting-started-faster-in-...
http://mentalpagingspace.blogspot.com/2008/12/rails-to-windows-integrati...

First, to give some context, when building Rails apps, its common practice to use
a common set of plugins. In "EDGE" rails, there is even a template system so that
when you create a rails apps, it can load your standard plugins.

For my basic set, I use the following:

What’s µF got on XML?

Decisions, decisions. Therein lies the reason why convention over configuration is so bloody great, precisely because it requires fewer decisions. Reap, my humble build tool, outputs log files. Yea, logs are good. But the decision I have to make is, “in what format?”

Inline file upload - iframe - ajax - Ruby on Rails

In View

<% form_for(@images, :url => formatted_images_path(:format => 'js'), :html => { :multipart => true,:target => 'upload_frame' }) do |f| %>
Image
<%= f.file_field :uploaded_data, :size => "50" %>
<%= f.submit :Submit %>
<% end %>
< id="'upload_frame'," name="upload_frame" style="width:1px;height:1px;border:0px" src = "about:blank">

in controller
def create
@image = Image.new
if @image.save
respond_to do |format|

Watermarking an image in Rails - Rmagick

class Image < ActiveRecord::Base

require 'RMagick'
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 4.megabytes,
:resize_to => '640x400>',
:thumbnails => { :thumb => '100x100>',:medium => '250x150' }

validates_as_attachment

def watermark_image
dst = Magick::Image.read("#{RAILS_ROOT}/public/#{self.public_filename}").first

Visually Inspect Ruby Object Models with DrX | Rails Fire

Visually Inspect Ruby Object Models with DrX

Send to friend

When you want to inspect your objects in Ruby, Object#inspect, p, or awesome_print are all valuable. You're stuck with plain-text, though, and primarily designed to look at object data rather than object models. If you want to drill down into parent classes, see object and class relationships, etc, then, check out DrX, a visual object inspector for Ruby!
DrX bills itself as a "small object inspector", but its key features are that it shows results visually (in a GUI interface) and that it focuses on showing the object model behind your objects, rather than the data contained within. A visual example of a DrX session should give you the idea:

Usage
Once DrX is installed (more on that in the next section), you just require 'drx' it into your app (or even within irb) and then use the Object#see method to get DrX into action:
require 'drx'
123.see
Even this rudimentary example will bring up an interesting graph. The DrX author does, however, provide a more interesting example to show off DrX's introspective features:
s = "wizard of oz"
def s.strong
"" + self + "!"
end
s.see
Installation and Prerequisites
Depending on your setup, DrX might take some serious work to get going. If you're running Linux and are heavy on your development experimentation, you might have everything ready to go. Just try gem install drx and see if the above examples work in irb.
Failing that, DrX uses Tk for its GUI work in order to be cross-platform and also requires GraphViz to be present. Install these with your package manager of choice and ensure that your Ruby installation has the Tk bindings installed (again, easier said than done).
On OS X 10.6 (Snow Leopard) I discovered that the stock Ruby installation does not include the Tk bindings, even though Tk is present otherwise. Rather than mess it up, I relied on the always-wonderful RVM and installed Ruby 1.9.2-preview1 (rvm install ruby-1.9.2-preview1). With this, Tk worked "out of the box" and gem install rbx was OK. For the Graphviz dependency, sudo port install graphviz did the trick and also "just worked." If you're one of the anti-Macports crowd, though, you might need to find a different approach.