Code Snippet: Ruby Image Scraper
Posted by Ryan Baxter Tue, 14 Aug 2007 03:46:00 GMT
I stumbled upon a screen scraping library for Ruby last week called scrAPI. It’s extremely flexible and can be seen in action on the co.mments blog post scraper. The scrAPI library can be installed by issuing the following command from your console:
gem install scrapiTesting scrAPI was fairly easy once I figured out how to define a scraper. With that aside, I wrote a small script that saves images from a URL provided by the user. The scrAPI library could be used for good or evil, but only you can decide.
#!/usr/bin/ruby
require 'fileutils'
require 'open-uri'
require 'pathname'
require 'rubygems'
require 'scrapi'
# Get the URL input.
puts 'Enter a URL:'
url = gets.chomp
# Get the HTML source.
html = nil
open(url) {|source| html = source.read()}
# Define the scraper.
scraper = Scraper.define do
array :images
process "img", :images => "@src"
result :images
end
# Scrape the HTML for images.
images = scraper.scrape(html)
# Create a directory to save the images in.
directory = url.gsub(/http:\/\//, '')
FileUtils.mkdir directory
images.each do |image_path|
# Determine if image_path is absolute or relative.
path = Pathname.new(image_path)
if not path.relative? then image_path = url + image_path end
# Write the image to disk.
open(image_path) do |source|
file_name = image_path.split('/').last
open(directory + '/' + file_name, 'wb') {|file| file.write(source.read())}
end
end
puts 'Finished...'- Posted in Code Snippets
- Meta 4 comments, permalink, rss, atom
I Want My IDE
Posted by Ryan Baxter Fri, 10 Aug 2007 02:32:00 GMT
The majority of my academic and professional programming career has been spent writing code using an integrated development environment (IDE). I’ve dabbled with Eclipse, Microsoft Visual Studio, Macrodobe Dreamweaver, and various Borland products. Rather than juggle multiple text editors and source control consoles, I find it easier to stay organized using an IDE on large projects. When editing config files or writing scripts I prefer a lightweight text editor. In Linux, vi or gedit is my choice. Notepad2 is at the top of my Windows list.
A few months ago I decided to learn Ruby and the Ruby on Rails framework. I began with the obligatory Hello World program and quickly progressed through a series of tutorials using vi and gedit to get the job done. Since then, I’ve begun some larger projects and am quickly finding myself losing focus and missing the benefits of an IDE. Consulting Google, I compiled a list of prospective IDEs to begin my evaluation. I’m willing to give each of them a fair chance at becoming my Rails development environment, but have a few questions before I begin. What, if any, IDEs have I missed? How long should I try each one?
Needs (in order of importance):
- Linux compatible
- Project Browsing
- SVN integration
- Syntax Highlighting
- Code Completion
- Active Community
- Unit Testing
- Debugging
- Auto-indent
- Plugin support
- Less than $100
The list:
*Each IDE/editor was capable of Project Browsing, Syntax Highlighting, and compatible with Linux.
- Aptana RadRails
Pros- Good SVN integration.
- The latest Beta has working Code Completion.
- Built on Eclipse.
- More Rails features than Eclipse + DLTK.
- Many plugins inherited from Eclipse
- Free.
- Code Completion is broken in the current stable release.
- Built on Eclipse.
- Eclipse + DLTK
Pros- SVN integration.
- DLTK has Code Completion.
- Tried and true.
- Vast library of plugins.
- Active community.
- Free.
- Eclipse is slow and consumes a lot of memory.
- FreeRIDE
Pros- Auto-indenting.
- Debugging.
- Free.
- No SVN integration.
- No Code Completion.
- Performance could be an issue b/c it’s a native Ruby application.
- gedit + plugins
Pros- Lightweight.
- Plugins.
- Free.
- No SVN integration.
- No Code Completion.
- jEdit
Pros- SVN integration.
- Code Completion.
- Plugins.
- Free.
- Not user friendly.
- IntelliJ IDEA 6.0
Pros- SVN integration.
- Code Completion.
- Debugging.
- Unit Testing.
- Plugins.
- Much more…
- $249.
- Komodo IDE 4.1
Pros- SVN integration.
- Code Completion.
- Debugging.
- Built specifically for Ruby on Rails.
- Much more…
- $295
- Mondrian Ruby IDE
Pros- Lightweight.
- Free.
- No SVN integration.
- No Code Completion.
- Performance could be an issue b/c it’s a native Ruby application.
- Spam in support forum.
- NetBeans Beta 6.0 Milestone 10+
Pros- SVN integration.
- Code Completion.
- Debugging.
- Plugins.
- Free.
- Much more…
- Beta.
- Ruby IDE from CodeGear
Pros- CodeGear experience.
- Feature set not yet released.
I’ll be evaluating each of the IDEs/editors in turn and publishing my results as a series. Feel free to leave feedback and check back soon!
- Meta 2 comments, permalink, rss, atom
Expect the Unexpected: THIS IS WAL-MART!
Posted by Ryan Baxter Tue, 07 Aug 2007 00:57:00 GMT
I purchased the Two-Disc Special Edition DVD of 300 from Wal-Mart this evening. Attached to the cover was a sticker that read “DOWNLOAD THIS MOVIE” and in small print, “Must reside in U.S. Windows Media Compatible Only. Not compatible with iPods.” Visiting walmart.com/300 in Firefox yielded the following:

It’s 2007. Why?
- Posted in Expect the Unexpected
- Meta no comments, permalink, rss, atom

