Google CSE With Ruby

Google CSE with Ruby from Joon You on Vimeo.

In this episode, I create a web service object that grabs Google CSE result and convert it into accessible data by other Ruby objects.

Special thanks goes out to Avi Flombaum of www.designerpages.com for giving me the permission to use the code.

Code:

Issue with String in 1.9.1

I was trying to see if I can Rack to work with 1.9.1. The only web server I can use is WEBrick since Mongrel as well as Thin does not work with 1.9.1. Rack installed without a hitch using ‘gem install rack’ command.

Using extremely simple code below, I wanted to see if I can hit my new super micro app.

[sourcecode language="ruby"]
super_micro_app = Proc.new { |env| [200, {'Content-Type' => 'text/plain'},'Please no more hello world crap'] }
require ‘rack’
Rack::Handler::WEBrick.run(super_micro_app, :Port => 4000)
[/sourcecode]

The problem is that this will barf because of the fact that String is no longer Enumerable. On line 47 of rack/handler/webrick.rb, you’ll see that each is called on ‘vs’ variable. Same thing happens on line 47 with ‘body’. The way I made this run is to change ‘vs.each’ to ‘vs.each_char’ on line 40 and ‘body.each’ to ‘body.each_line’ on line 47.

Of course this is a temporary fix just to run my stupid super micro app. But the lesson here is that String in 1.9.1 has changed lot more than I originally expected.

Ruby Outsourcing + Fork Screencast

Outsourcing + Fork from Joon You on Vimeo.

In this episode, I demonstrate outsourcing a function to the command line within Ruby and create asynchronous process using fork. The example takes a video file and converts it to Flash file using ffmpeg. Forking can be used with Rails, but please use Spawn plugin or do the sensible thing by using other queuing mechanism.

The code for the example used in this screencast:

Rails 2.3 RC1 Released

Rails 2.3 RC1 has been released. You can install the release candidate with:
gem install rails --source http://gems.rubyonrails.org

I have not tested it yet, but reading the release note, they made plenty of improvements and deprecated craps nobody uses. However, it appears that it creates more problems for those switching to 1.9 like myself.

It’s a good thing that they now using Rack everywhere, but the problem is, Rack is not yet compatible with 1.9. This is precisely the reason why I can’t write Sinatra with 1.9. If you don’t know what Rack is, take a look at the video of Dan Webb presenting Rack at Ruby Manor.

« Previous Page

Powered by Olark