12.27.07
Posted in Ruby, sqlite3 at 11:00 am by Robert Horvick
After doing some cleanup I reset my Sqlite3 databases and tried to run tests to make sure that everything was still ok. The command I ran was:
$ rake test
and the output from each test was a failure with the message:
34) Error:
test_should_update_user(UsersControllerTest):
SQLite3::SQLException: SQL logic error or missing database
So I did the following:
- Check that test.sqlite3 exists.
- Rebuild test.sqlite3 using “rake db:reset”
- retry … still failed.
- Try loading fixtures using “rake db:fixtures:load”
C:\InstantRails\rails_apps\atompublog>rake db:fixtures:load
(in C:/InstantRails/rails_apps/atompublog)
rake aborted!
SQLite3::SQLException: no such table: atom_entries: DELETE FROM atom_entries WHERE 1=1
(See full trace by running task with --trace)
Ah ha!
That table shouldn’t exist (and it doesn’t…) so there should not be a fixture loading into it.
I checked my fixtures and there was one named “atom_entries.yml”. After deleting that file the fixtures loaded, the tests ran and I was confident that my cleanup changes did not break anything.
A quick google search shows that a lot of people have hit this problem so hopefully this post helps some of them track down one of the potential causes.
Permalink
12.26.07
Posted in Ruby, blog, rails at 11:00 am by Robert Horvick
I have done some digging and there does not seem to be any plugins or gems (or even active projects on RubyForge) that are providing support for an AtomPub server. I did find a sample based on Camping but it was not really what I was looking for. It supports a subset of AtomPub and not in a way that is really friendly for what need.
So I set out on my own.
An atom pub entry can be as simple as this:
<atom:entry xmlns="http://www.w3.org/2005/Atom">
<atom:title>ATOM Post Test</atom:title>
<atom:id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</atom:id>
<atom:content>Some text.</atom:content>
</atom:entry>
Or quite a bit more complex (lifted from http://tools.ietf.org/html/rfc4287):
<entry>
<title>Atom draft-07 snapshot</title>
<link rel="alternate" type="text/html"
href="http://example.org/2005/04/02/atom"/>
<link rel="enclosure" type="audio/mpeg" length="1337"
href="http://example.org/audio/ph34r_my_podcast.mp3"/>
<id>tag:example.org,2003:3.2397</id>
<updated>2005-07-31T12:29:29Z</updated>
<published>2003-12-13T08:29:29-04:00</published>
<author>
<name>Mark Pilgrim</name>
<uri>http://example.org/</uri>
<email>f8dy@example.com</email>
</author>
<contributor>
<name>Sam Ruby</name>
</contributor>
<contributor>
<name>Joe Gregorio</name>
</contributor>
<content type="xhtml" xml:lang="en"
xml:base="http://diveintomark.org/">
<div xmlns="http://www.w3.org/1999/xhtml">
<p><i>[Update: The Atom draft is finished.]</i></p>
</div>
</content>
</entry>
I started with just caring about title and content. Everything else I could infer from authentication (author, anyway).
With this thought, I created some simple xpath queries to find the title and content. That was working out. I could get the atom response created and the post serialized to the database. So with just a few lines of code (beyond the scaffolding) I was able to use Live Writer to post via atompub to my blog engine.
But I wasn’t happy with just winking away the atompub protocol in favor of getting done quickly.
So I sat down and really started reading the atom publishing spec (and the a related atom rfc). I have a lot of work to do.
I started using XmlSimple to parse the XML. That was ok, except some things don’t map well to hashes and it did not get me closer to serializing atom entries to xml (for the feed later on).
So I moved down to REXML and that was working ok. But I still wasn’t happy. I felt like I was writing too much monkey code and not doing making progress on my real goal.
Tinally I found ROXML - and now I’m happy. I’ll cut to the chase and just show the code:
require 'rubygems'
require 'roxml'
class AtomBase
include ROXML
def to_s
self.to_xml
end
end
class AtomAuthor < AtomBase
xml_name "author"
xml_text :name
xml_text :uri
xml_text :email
end
class AtomContributor < AtomBase
xml_name "contributor"
xml_text :name
xml_text :uri
xml_text :email
end
class AtomLink < AtomBase
xml_name "link"
xml_attribute :rel
xml_attribute :type
xml_attribute :href
xml_attribute :length
end
class AtomContent < AtomBase
xml_name "content"
xml_attribute :type
xml_attribute :lang
xml_attribute :base
xml_text :text, nil, ROXML::TEXT_CONTENT
end
class AtomSummary < AtomBase
xml_name "summary"
xml_attribute :type
xml_attribute :lang
xml_attribute :base
xml_text :text, nil, ROXML::TEXT_CONTENT
end
class AtomEntry < AtomBase
xml_name "entry"
xml_text :title
xml_object :link, AtomLink, ROXML::TAG_ARRAY
xml_text :id
xml_object :summary, AtomSummary
xml_text :updated
xml_text :published
xml_object :author, AtomAuthor
xml_object :content, AtomContent
xml_object :contributor, AtomContributor, ROXML::TAG_ARRAY
end
The major gap is that this does not support xhtml content and summary fields. Those fields contain embedded XML and I have not figured out how to get ROXML to stop navigating the tree and make the object property return the inner xml.
I did try hacking ROXML to support an XML_CONTENT tag. It solved about 70% of the problem but it was not working exactly as I wanted after about a half hour and I felt like I was shaving a yak. I can come back to that later on. For now that the atom bits were are neatly wrapped up behind a class with a known bug. I’m ok with that.
I haven’t reviewed the atom syndication spec to make sure I’m doing everything right but it’s working with all the samples I’ve thrown at it (including the samples from the spec) and Live Writer seems to be having a field day with it. So that’s good.
Anyway - that’s where I’m heading.
I have the feeling that I’m reinventing the wheel. I hope not poorly.
Permalink
12.25.07
Posted in Ruby, blog, rails at 9:36 pm by Robert Horvick
Nuby on Rails recently asserted that “every beginning Rails developer should write their own blog software. It’s a great learning experience and you can try things that aren’t possible with just an app running on localhost.”
I can buy into this. It’s the canonical Rails sample app. I’m new to Ruby and Rails. Maybe I should do this. And I don’t mean a little toy that I do in 15 minutes and then throw away. I mean the blogging platform I use for my primary blog.
So I sat down and tried to list out what I would want my blog to look like …
- I don’t want to spend time writing code for a text editor to write blog posts
- I want people to be able to subscribe to my content
- I want caching (not that I plan to get dugg - but it’s good learning)
- I want to be able to easily customize the look/feel
- I want to support tagging and providing post views based on those tags
- I want to support uploading media files (images, etc)
- I want to be able to import this blog into it.
So I spent some time researching those issues and this is what I’ve come up with:
- I will post via atom publishing -there are already blog tool that support this (Microsoft Live Writer, for example - I’m sure there are others).
- I will provide atom feeds.
- Rails has lots of caching examples. I’ll start with file system based caching and move upwards from there.
- I won’t provide full theme support but I’ll have a generic post format and include user defined stylesheets (and possible javascript).
- acts_as_taggable until shown why not.
- atompub can do this.
- I think I can use atom feeds to do this.
Also …
As mentioned I’m hosting with SliceHost.com on a 256 slice so I need to keep it trim. I may go to production on Sqlite3 (if I do the caching right this shouldn’t be a problem - and that would keep 4-10% of my limited RAM free).
Also my goal is to write as little new code as possible. Plugins and gems whenever possible.
I figure it will take about a month to have something I can show to the world and not worry about hiding my face.
Over the next few weeks I’ll be blogging about what I learn that seems interesting. And plenty that isn’t, I’m sure.
Permalink
12.19.07
Posted in Ruby, merb at 8:56 pm by Robert Horvick
When trying to perform a migration (rake db:migrate) I hit the following error:
$ rake db:migrate
(in /home/Robert/ruby/merb_apps/blog)
svn: '.' is not a working copy
Connecting to database...
Thu, 20 Dec 2007 01:48:09 GMT: loading gem 'merb_activerecord' from config/dependencies.rb:16 ...
rake aborted!
No such file or directory - /tmp/mysql.sock
(See full trace by running task with --trace)
After a few minutes of googling and some trial/error I discovered that changing “localhost” in the database.yml file to the loop back address 127.0.0.1 resolved the issue. Apparently when you specify an IP address the :socket: value is not needed. Since the default merb database.yml content includes the line:
:socket: /tmp/mysql.sock
This is something that other Windows users may need to modify.
This is my updated config/database.yml file:
:development: &defaults
:adapter: mysql
:database: blog_development
:username: root
:password:
:host: 127.0.0.1
:test:
<<: *defaults
:database: blog_test
:production:
<<: *defaults
:database: blog_production
Permalink
Posted in merb at 7:10 pm by Robert Horvick
When attempting to create a new controller in merb on a cygwin installation I hit the following error:
$ ./script/generate controller post
svn: '.' is not a working copy
/home/Robert is insecure (40777). It may not be group or world writable. Exiting.
Ignore the svn issue for now - I don’t know why script/generate tries to interact with svn but the problem is the home directory permissions.
I believe this is an issue with RubyInline requiring more secure permissions than Ruby itself requires.
To resolve the issue I executed:
$chmod 750 /home/Robert
After that generating the controller worked as expected.
Permalink
12.17.07
Posted in Ruby, merb at 11:57 pm by Robert Horvick
I’m getting ready to dive deeper into merb and wanted to install merb_activerecord. Unfortunately when I tried this I hit the following error:
$ gem install merb_activerecord
Updating metadata for 32 gems from http://gems.rubyforge.org
................................
complete
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
OpenURI::HTTPError: 404 Not Found reading http://gems.rubyforge.org/gems/activesupport-2.0.2-.gem
So I tried “gem update activesupport” and hit the same error.
I went out to the ActiveSupport RubyForge page found that 2.0.2 was released today. So I went to http://gems.rubyforge.org (which redirected to http://gems.rubyforge.vm.bytemark.co.uk/gems) and the latest version available in 2.0.1. So I assume this is just an issue of needing to wait for data to shuffle around.
But I’m impatient.
So I downloaded the gem file from http://rubyforge.org/frs/download.php/29344/activesupport-2.0.2.gem and installed as:
$ gem install activesupport-2.0.2.gem
Successfully installed activesupport-2.0.2
1 gem installed
Installing ri documentation for activesupport-2.0.2...
Installing RDoc documentation for activesupport-2.0.2...
When that was done I was able to successfully install merb_activerecord as follows:
$ gem install merb_activerecord
Successfully installed merb_activerecord-0.4.3
1 gem installed
Installing ri documentation for merb_activerecord-0.4.3...
Installing RDoc documentation for merb_activerecord-0.4.3...
The lessons here are that just-released gems might not be available via “gem install” even though they are a listed dependency of other gems and that manually downloading and installing gems is trivial.
Permalink
12.14.07
Posted in greasemonkey, javascript at 2:19 pm by Robert Horvick
OpenHulu.com provides a way for the common man to access Hulu.com video content. That’s awesome. However the page sucks. It’s not just the ads either. It’s the layout and the contract between stark white and black. Blegh.
So I decided to pretty it up a little using Greasemonkey (more info at Dive Into Greasemonkey). I’ll let the graphics tell the story:
Before:

And after Greasemonkey:

If this looks better to you install the script from here:
http://www.ghostonthird.com/downloads/openhulu.user.js
This is my first Greasemonkey script. If there is anything obviously stupid - let me know.
For the next version I want to leave the page as-is and instead add a button that will, when pressed, walk the page looking for the active video, make the video nearly almost full screen (leaving the button to toggle the page visible).
This should be more resilient to changes in the page structure.
Permalink
12.13.07
Posted in Ruby, cygwin, merb at 3:39 pm by Robert Horvick
When getting merb working on Windows I provided a patch to the merb folks that resolved a Rakefile compat problem (sudo was being used even when on Windows - where it does not exist).
I’m trying various configurations on Windows and found that in cygwin the platform name does not include “win32″ so the filter no longer worked (and cygwin does not include sudo).
I filed a ticket http://merb.devjavu.com/ticket/361 and attached the patch. It’s very simple:
$ cat cygwin.diffIndex: Rakefile
===================================================================
--- Rakefile (revision 1087)
+++ Rakefile (working copy)
@@ -18,7 +18,7 @@
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
-windows = (PLATFORM =~ /win32/)
+windows = (PLATFORM =~ /win32|cygwin/)
SUDO = windows ? “” : “sudo”
And then it all goes well …
Robert@HORVICKLAPTOP ~/merbsrc
$ rake install
(in /home/Robert/merbsrc)
rake package
(in /home/Robert/merbsrc)
Successfully built RubyGem
Name: merb
Version: 0.4.2
File: merb-0.4.2.gem
gem install pkg/merb-0.4.2 --no-rdoc --no-ri
Successfully installed merb-0.4.2
1 gem installed
Permalink
12.07.07
Posted in Ruby at 1:07 pm by Robert Horvick
As I become more familiar with the Ruby language I have also become more familiar with the global Ruby community (though it will be quite some time before I am familiar to them).
As in all language spaces there are the founders, leaders, thinkers, personalities, corporate players, and random people you’d drink with (if the opportunity presented itself).

What’s interesting about this community, though, is the theme of happiness that everyone keeps talking about.
As in other communities people discuss language features, benefits, failures, frameworks, productivity, metrics, performance, blah blah blah. But this whole notion of happiness, as a language feature, is new to me.
I worked on a commercial compiler for several years early in my career and not once did the word “happiness” come up in design discussions or feature lists. “Tolerable”. “Correctness”. “Performant” (one of my favorite made up words). Absolutely.
But not happiness.
I’m trying to let it soak in slowly. People seem to be happy for basically the same reasons. It boils down to the “feel” of the language. The expressiveness of it. The ease at which things happen. Least surprise. Agile principles. BDD/TDD. RSpec. Lots of good stuff.
And, of course, Rails (and all the MVC, ORM, pluggable goodness it brings to the table).
For me, though, it’s none of those things. Those same things exist in other languages (and will in future languages).
Those things are brick construction, crown modeling and custom paint. Solid. Attractive. Welcoming. Stylish. Fun. But there are other well-made and attractive homes. In the future there will be new well made attractive homes.
Why this one? Why Ruby?
Just like when we picked the neighborhood for our home - it’s the local community. The Raleigh-area Ruby Brigade (Raleigh.rb). Sitting in on the meetings and learning from others. Hearing their stories about past, present and future projects. Listening to their excitement around Ruby and Rails. Learning from them and talking about development topics over laptops and burritos.
Associating with people who are smart, passionate, excited, and who get things done is infectious.
Even just for a few hours a month.
It gets me going. Pushes me to work on my own projects. Revitalizes my spirit. Inspires me to try out new things.

Seeing talented developers with a flare for design pushes me to improve my design skills. I’ve begun reading about graphic design, typography, print layouts, usability and photo processing. I’ve started to draw again. I’m sleeping less (in a good way), thinking more, and generally more excited about my day-to-day work (C#, not Ruby). I’m reconnecting with that person I used to be before I got trapped in the clutches of a monolithic corporate machine. He is much cooler than I am. At least he had better taste in socks.
None of this is really about Ruby as a language, though. It could just as well be Python or a Linux fetish. I’m sure there are some great local groups for those technologies.
But I’m not in those groups. I’m in Raleigh.rb. Maybe I’ll check them out some other time. Maybe not. I’m still having fun here.
So go now. Seek out a local Ruby Brigade in your community. If you can’t find one then start your own.
Sit in the back. Don’t say a word. Or sit up front and chat the place up. Doesn’t matter. Just find one and go. If you’re in the Raleigh area come by to the local meetup. I’ve found it to be a friendly, open group who enjoy seeing new faces.
Make it a New Year’s resolution.
You’ll be glad you did.
I promise.
Permalink