Eric Berry

AddThis Social Bookmark Button

There are many ways that you can create menus for your website. The way I used to do it was by using tables and having a menu item for every menu item. This way I had come to find out is the hard way. Let’s talk about the easy way.

You can download the example code along with the images here.

Goal: Create a simple CSS menu.

Eric Berry

AddThis Social Bookmark Button

As a Rails programmer, I have been using Prototype and Scriptaculous for over a year and a half, solely because it comes packages with Rails and has helpers. About 3 months ago, I discovered JQuery, which is another Javascript library that combines the powers of Prototype and Scriptaculous into one. JQuery is very easy to install for your web app and has a TON of cool things you can do with it.

In this article, I will show you how to create a simple slide show using JQuery and the jQuery Cycle Lite plugin.

Eric Berry

AddThis Social Bookmark Button

I’ve worked with a ton of programmers in the past, and most of them don’t know a lot about web design. My brother, for example, is an insanely good programmer. However, every time I see his web applications, I have a hard time seeing past how ugly they are (sorry Mark).

I believe this may be an issue with a lot of programmers out there, perhaps most of them. In an effort to help all my colleagues out, I have decided to share a quick tutorial on how create a ’sexy’ layout for your applications without having to be a design guru.

Eric Berry

AddThis Social Bookmark Button

I recently ran in to a blog article which referenced an online application called HopToad (http://www.hoptoadapp.com).

HopToad is an online application that plugs directly into your Rails application and collects all errors that are thrown in your app in a neat and readable UI. I have about 15 Rails applications out there right now, and HopToad is a life-saver for me.

The best thing is, it’s free. Go to http://www.hoptoadapp.com to try it out.

AddThis Social Bookmark Button

Sometimes a test case must detect when production code creates new records, as a side-effect. assert_latest{} detects all new records of a given type, and returns them like this:

    f1, f2 = assert_latest Foo do
               2.times{ Foo.create }
             end

    assert 'items return ordered by id' do
      f1.id > 0 and f2.id > f1.id
    end

This post shows how to use assert_latest{} in more advanced configurations. It can detect records of more than one type, and can detect records that belong to only one association. Our platform is Ruby on Rails, yet - as usual - the lessons apply to any unit tests.

AddThis Social Bookmark Button

Object-Relational Models, like Rails’s ActiveRecord, help generate very complex queries. Sometimes we need that complexity - without slow execution times! We might not notice when our queries have grown beyond our databases’s tuning and indices.

This post shows how to trap, interpret, and EXPLAIN SQL SELECT statements under MySQL. Our platform is Ruby on Rails, yet the lessons apply to any ORM.

AddThis Social Bookmark Button

This post is not about your boss growling at you. Another title could have been “whisper-driven development”. It’s about your code whispering its status to you.

To learn this newfangled kind of development, whip out an Apple computer, and start a project using Test-Driven Development. We use Rails, but you can use any platform you like. (You can use any computer you like, so long as you can find and configure a Growl-style program for it. See below.)

In Rails, use ZenTest’s autotest command, or write your own batch file, that triggers a test run each time you save any source files. I have one here; it’s a little more “generic” than ZenTest’s version. “Generic” is a programming euphemism for “scrappy - a fixer-upper”.

Gregory Brown

AddThis Social Bookmark Button

I’m happy to announce I just cut the first alpha release of Prawn. It is chock full of features, and since the release notes are fairly detailed with good links, I’ve just pasted them for your review after the cut.
But first, I have a few words that I couldn’t quite convince myself deserved a separate post:

On a somewhat sad note, this will be my last post to O’Reilly Ruby. Things are changing a lot behind the scenes here, and there has been a lot of re-shuffling of resources. I’ll still be blogging for O’Reilly but over on the News Site. However, since that blog will be a bit more ‘big story’ oriented, I’m going to also be starting up my own tech blog at majesticseacreature.com. Keep an eye out for that, but it may take me a few days to find time to write some blog software I can live with, and the page will be a ghost town until then.

So O’Reilly Ruby, So long, and thanks for all the fish. I had fun here and I hope that folks will still find my stuff over on the news site interesting.

Prawn 0.1.0 Release notes to follow…

Gregory Brown

AddThis Social Bookmark Button

I’m happy to announce that the Prawn PDF library has hit another milestone on the Ruby Mendicant project roadmap. This time we’ll look at Prawn’s shiny new table drawing support, as well as some of the other features that have been added over the last several weeks. We’ll also look at where things are headed in the future, including when to expect a first gem release. All this and more lies just beyond the cut…

Gregory Brown

AddThis Social Bookmark Button

Continuing on a theme, this post brings you the latest news from Prawn, the Ruby PDF library currently being developed under the auspices of the Ruby Mendicant project. The news this time around focuses on m17n progress, TTF font embedding, and some new goodies from contributors. Sexy screenshots and code samples lie just beyond the cut for those who wish to learn more.

Gregory Brown

AddThis Social Bookmark Button

I really like the open command on OS X, but I was too lazy to look for its Linux equivalent.

Actually, my solution probably took less time than sifting through a google search:

system(case ARGV[0]
when /\.pdf/
“epdfview”
when /\.html/
“firefox”
when /\.(rb)|(pl)|(pm)/
“vim”
end + ” #{ARGV[0]}”)

Anyone else have fun little hacks they want to share?

Gregory Brown

AddThis Social Bookmark Button

Several weeks ago I wrote about the first development checkpoint for Prawn, the PDF library currently being developed for the Ruby Mendicant project. I’ve finally reached the second checkpoint, which involves basic text rendering operations, and this post describes these new features, the problems I have run into, and the plans for the coming weeks. If you’re following the project, please read on.

AddThis Social Bookmark Button

One of the rather unique features of the Fortress1 programming language is that it has builtin support for Unicode operators. For example, instead of using “==” you would use U+2261. After reading the spec, and a recent thread on ruby-core, I’ve been wondering something . Are language designers too limited in their decisions about syntax because of the limitations of the QWERTY2 keyboard?

Gregory Brown

AddThis Social Bookmark Button

Back in March, I announced the Ruby Mendicant project after several readers of this blog encouraged me to pursue the idea. For those who didn’t see the follow up details elsewhere, here’s the readers digest version:

Thanks to 70 donors, and donation matching from Ruby Central, Inc. and MountainWest Ruby LLC, I am now able to take 22 weeks off from my commercial work to focus on open source development in Ruby. I had a number of project ideas, but the general consensus is that my time would be best spent building a fast, sleek, and simple PDF library for Ruby. I’ve decided to call this library Prawn, for the time being.

Since I have just reached my first checkpoint on the project, I figured I’d give folks an update on where things are.

Gregory Brown

AddThis Social Bookmark Button

While working on Prawn, I ran into this (not-so) fun little gotcha:

>> 1.to_sym
=> nil
>> 101241.to_sym
=> nil

Anyone cool enough to tell me what this feature is all about?

Update:

I guess it isn’t totally clear what I was asking here. I’m not actually trying to convert integers to Symbols. In fact, my specs were failing because I expected some_number.respond_to?(:to_sym) to be false!

As it turns out, Fixnum#to_sym does have a purpose, but it is quite different than something like String#to_sym.

>> :foo.to_i
=> 14369
>> 14369.to_sym
=> :foo

I knew about the existence of #id2name and it didn’t surprise me much, given the way Symbol objects are implemented. Still, for the folks who keep reminding me about what Symbol objects are, please save your comments because that’s not the point here.

The point is that when I see “foo”, I can easily say. Oh… “foo”.to_sym will give me :foo.
When I see [16393, 16401, 16409], I don’t think “Gee… that must be: [:cat, :monkey, :tomato], I just need to map it with to_sym”.

So what this boils down to is an API clarity thing. Even if a Symbol is closely bound to an integer implementation-wise, I think it’s a bit of a flaw to assume that to be important conceptually. Among our readers, has anyone used Fixnum#to_sym in real code? I’d be very interested in seeing a common use case for this feature. If there isn’t one, maybe a less ambiguous name, such as id2sym might be more appropriate.

What’s more, even with the existing name, it’d be nice if some_number_that_has_no_symbol.to_sym would blow up with an error rather than return nil.

Sorry for the earlier confusion, hopefully this update clarifies that I was talking about a design peculiarity., and not some burning desire to get myself back a :1.

Tim O

AddThis Social Bookmark Button

Sorry, it isn’t entirely Ruby related… it is Python Django to be specific, but it is a message aimed at you (”the wiki-worker types”) from Lawrence Lessig recruiting people to tag members of Congress at Change-Congress.org:

Today we’re launching the second stage of our project. We’re asking wiki-worker-types (and that includes you) to help us tag all candidates and Members of Congress, by tracking for each whether they support the planks of reform in the Change Congress movement or not. We’ve built a set of tools that you can use to document — for each plank of reform — whether a candidate supports that plank or not. After that information is verified by a volunteer administrator, we’ll add it to a map of reform that we’re building. After we’re done, we’ll have a picture of the level of support for fundamental reform of Congress. And with that map, we’ll launch stage 3 of our project — raising money to support candidates who support reform

Django has the edge in the civic-Web20-computing space as Holovaty’s Django was always more focused on the public square from the beginning. You would think Rails would be a no brainer for this, but in my brief encounter with the world of political web sites, many of the people I was talking to thought that PHP was king (ick). (In related news, this is the best online book interface I’ve seen yet.)

Tim O

AddThis Social Bookmark Button

I’m sure you don’t believe it, doesn’t seem like NetBeans is going to take the Ruby developer world by storm, but Sun seems to be pouring money into Ruby support. I’m skeptical that the Ruby community is going to embrace Netbeans, but in this entry, I present some hints that NetBeans may be well on its way to becoming the Ruby IDE of choice. The idea that an IDE traditionally associated with Java development is going to take the Ruby world by storm might seem insane at first glance, but read on…

Eric Berry

AddThis Social Bookmark Button

The long-awaited mod_rails for apache was released yesterday by Phusion, a Netherlands based IT company. As many of you have already done, I hopped on board to see how it worked and was amazed on how easy it was to get up and going.

Ryan Bates, a guy whose voice many of us Rails coders have grown to know and love, assisted the Phusion team in creating a short screencast on how to install Passenger onto your Mac.

It was basically 3 steps:

1. Install the RubyGem
2. Run the passenger installer script
3. Modify your apache conf file to include the new virtual host

Can it really get easier than that? I submit that it can not.

In my opinion, Passenger is filling a void that has haunted the Ruby on Rails community for some time. Matz is quoted as saying “It is often said that Rails is weak on deployment; PHP runs fairly fast just by uploading scripts. Rails is slow on development mode, and requires restarting on production mode (and bit complex to configure). modrails might be the answer for it.”.

To get Passenger, go to http://www.modrails.com

Gregory Brown

AddThis Social Bookmark Button

Reposting from the official announcement on RubyTalk

Gobi version 1.0.0 has been released!

* http://gobi.stonecode.org
* http://metametta.blogspot.com
* gregory.t.brown@gmail.com

I am happy to announce the first release of my new fork of Ruby called
Gobi. The goal of Gobi is to implement features that I have noticed to
be completely missing.

For example, Ruby’s standard library does not even implement a
datastructure that can easily represent a Go board. Gobi has this
built in as an NArray based, highly efficient structure:

 >> x = Goban.new
 >> x.place_stone(:black, :at => "a4")
 >> x.place_stone(:white, :at => "c16")
 >> x.place_stone(:black, :at => "a4")
 StoneCollisionError: There is already a stone at a4.
   from (irb):3 in `place_stone`
   from (irb):6

As you can see from the example above, Gobi is very friendly to those
writing computer Go applications. For those wishing to write AI bots
to play the game, Gobi also goes through a lot of effort to make Ruby
more efficient.

A major improvement in performance was gained through the removal of
automatic garbage collection. This means that programmers need to be
sure to clean up after themselves, but any Rubyist who also has an
interest in Go will surely be sufficiently skilled to design programs
that avoid memory leaks.

The implementation of object destructors in Gobi is simple, due to the
addition of a release_resources hook in Object. A delete keyword has
also been added, which will explicitly start up the garbage collection
process.

Here’s an example of manual garbage collection in Gobi:

 class Foo
   def initialize
     @board = Goban.new
   end
   def release_resources
     delete @board
   end
 end

Please keep in mind that although the built in classes all have
sensible release_resources implementations, that if you’re feeling
adventurous, you can of course override them. A current fun game in
Gobi is to run a stopwatch and see how quickly memory runs out when
you write some code like this:

 class String
   def release_resources; end
 end
 string = 'a'
 1_000_000_000.times do
   string = string.succ
 end

Of course, though humorous, this should serve as a warning to you: Be
sure to properly discard your objects!

This announcement just scratches the tip of the iceberg of what Gobi offers.

Other cool features include:

- The removal of Ruby 1.9’s giant interpreter lock, as Go programs
tend to benefit from the power of true concurrency. (Unfortunately,
these patches are very platform dependent)

- A major reshifting of Ruby’s standard library. Things like option
parsing, zlib support, and fileutils aren’t really that useful for
programming computer Go applications, so they have been removed. Many
new libraries have been added, including an SGF analysis tool and a
GTP network implementation.

- An interface to a special (Proverb Semantics Parsing) PSP tool,
which allows you to train Go playing robots by simply reminding them
of proverbs such as “Hane at the head of two stones”, and “The empty
triangle is bad”, rather than resorting to low level, complicated AI
programming. This system can be used via irb while a game is under
review in Gobi’s built in Tk based SGF editor. Gobi shows that by
mindlessly memorizing proverbs, Go playing bots can decrease their
rank by two stones in half the time that an average human can.

- The removal of all lesser data structures such as the Array, the
Hash, and the Set. In Gobi, all of these structures could trivially
be built as a subclass of the Goban, so there is no need to keep them
around.

Though I will be taking off 6 months from Gobi development to work on
the Ruby Mendicant project, I hope that people enjoy this early
experimental release and that soon Ruby will be free from the core
team’s shackles to do what it truly deserves to: Reach 30 kyu on KGS
with a Gobi based bot!

Though only time will tell, I am considering reworking Gobi to fork
Aaron Patterson’s excellent Brobinius implementation, as Gobi deserves
some high quality Grosenbach screencasts.

* http://gobi.stonecode.org
* http://metametta.blogspot.com
* gregory.t.brown@gmail.com

AddThis Social Bookmark Button

CruiseControl.rb, by ThoughtWorks, is an elegant Continuous Integration dashboard for Ruby projects. This article shows how to call the RoR command “rake stats” once per build, capture the results, and chart them to track trends over time.

Our goal is this chart:

cc_gnuplot.png
Gregory Brown

AddThis Social Bookmark Button

Though I’m typing this from a Mac right now, I’m hardly a fan boy. I spend a little less than half of my time on OS X, the rest spent on cheap PC hardware and ArchLinux, and honestly, I’m happy with both (each for different reasons)

Still, Apple definitely got some things right, and not the least of which was hiring Laurent Sansonetti. He’s the guy who’s been working on cool projects such as RubyCocoa and RubyOSA, and now has just released MacRuby.

MacRuby sounds cool:

MacRuby is a version of Ruby that runs on top of Objective-C. More precisely, MacRuby is currently a port of the Ruby 1.9 implementation for the Objective-C runtime and garbage collector.

Though I’m not actively doing Mac specific Ruby development, that doesn’t mean I can’t extend thanks to a very cool hacker who has been dropping cool free software projects on our community like it was his job…. oh wait… it is. :)

Thanks Laurent for your contributions! You’re one of the reasons why the Ruby community rocks.

Gregory Brown

AddThis Social Bookmark Button

When I wrote the post I’d love to quit my job! (sort of), I was mainly aiming to start a conversation.

Still, enough people took me seriously, and now I can announce that the project is officially under way. I’m in the fund raising stages to collect $8000 so that I can take off 6 months of work to focus on important Ruby open source projects. That sounds even lower than my initial estimate, and the reason for that is because Ruby Central, Inc. decided to back the project! Here’s their press release:

RUBY CENTRAL, INC. WILL MATCH FUNDS DONATED TO GREG BROWN,
UP TO A TOTAL OF $5,000

Ruby Central is always on the lookout for interesting ways to help and
support the Ruby community, and Greg Brown has provided us with one.

Greg has announced a unique plan for himself. You can see the whole plan at
http://rubymendicant.wikidot.com/proposal; meanwhile, here’s Greg’s capsule
summary of the idea:

** Through the donations of community members, I would like to put my
commercial and personal software projects on the back burner for a
prolonged period of time (3-6 months), and focus on working on open
source projects that are of high importance to the majority of
Rubyists. **

Greg has already started to receive donations. And now, Ruby Central
is coming on board to help Greg with matching funds.

Ruby Central will match gross donations to Greg, dollar for dollar, up
to $5000 (five thousand) dollars. That means that if you donate $50 to
Greg’s effort, we’ll donate $50. We’ll stick to the same timeline that Greg
has set for himself (see the above URL).

It’s not quite like anything we’ve done before, but it sounds like a good idea
at the right time, and we’re happy to support Greg’s unusual and imaginative
endeavor.

Please keep in mind that donations to Greg are not donations to Ruby
Central, and therefore do not fall under our tax-exempt status.

Ruby Central, Inc. is a 501(c)(3) tax-exempt organization, chartered to
support Ruby-related events and initiatives that benefit the Ruby community.

Peter Cooper has also decided to support the project by both donating, and posting a summary on Ruby Inside. He does a good job of covering the whole of the story, including relating to those who feel uncomfortable supporting such an effort. I totally understand people’s skepticism, and thats why I encourage people to come talk on the RubyMendicant google group if they have any doubts about the project they want cleared up. The explicit timeline for this project and the fact that I’ve promised to record public hours will hopefully put some folks minds at ease.

Peter mentions that I talked about working on PDF::Writer or Ruport, but this doesn’t really fully explain what I was thinking of doing. With respect to PDF::Writer, I was pondering a from scratch rewrite with a sexy API and less performance problems. With Ruport, I was going to work on 1.9 compatibility for all of its dependencies across ruport-util and acts_as_reportable. Though I haven’t checked in with the maintainers of these libraries yet, it’s truly a laundry list of general purpose gems I’d be working to update. Here are just a few:

  • RubyDBI
  • Gruff
  • Scruffy
  • PDF::Writer
  • transaction-simple
  • roo
  • rubyzip

Outside of Ruport, there are lots of libraries that I’d like to see working on 1.9, and with enough time, I could work on porting them.

The ideas list will be open for suggestions until April 1st when the donations close, the goal is to focus on things that might be hard to reach from traditional open source work that is done in people’s spare time or as part of a commercial project.

Anyway, this is going to be my last mooching attempt on the O’Reilly blog for this project. If you’ve read through the proposal I’ve put together and want to support the project, please consider a donation. If you’ve got questions, please ask them. And perhaps most importantly: If you like this idea, please spread the word. Having Rubyists show that they back this effort is worth more than cash to me, because it gives me confidence that this might actually work.

At the time of writing, with the matching from Ruby Central, Inc., I have enough money for at least two weeks one month of work. That means this project is a ‘go’ even if no one else donates. Of course, a lot more can be done with 26 weeks than with two.

The next post about this you’ll see here from me is going to be a progress report of what I’ve been working on. Until then, thanks so much to those who have supported and will support this project. I think it’ll be a great experiment, and that good things will come from it.

AddThis Social Bookmark Button

This project upgrades an online forum to add a search engine, using Test Driven Development. Our tools are RoR’s Beast, Sphinx, and (naturally) assert{ 2.0 }.

We follow this MVC guideline:

Anything a user can do to the data through the Views,
a unit test can do, the same way, through the Models
Our test cases simulate a user searching.

Gregory Brown

AddThis Social Bookmark Button

UPDATE: Okay kids, now it’s 50% fantasy. It’s up to you to cover the other 50% by donating and spreading the word, after reading my proposal. Here’s hoping for the best!

UPDATE: Though my original post was 95% a fantasy, I’ve received some funding offers that have brought it down to 75% fantasy. I will be documenting any planning I’m doing towards via a wiki called RubyMendicant. If you’d like to follow this on the bleeding edge, keep an eye out on that wiki. Otherwise, if you hear an official announcement within the next few weeks, you’ll know I decided to take the plunge, and if you don’t, then it’s safe to assume this idea went the way of the dodo. If you like this idea, please spread the word through the usual means of the intertubes by sharing this post and the wiki link with others.

Here’s a crazy idea I just had, and I’m wondering what folks think about it.

People do open source for a lot of reasons, ranging from pragmatic to idealistic. Some write a patch every six months or so, others do what they can to dedicate their life to it. Though I try to have a life outside of software, I’m definitely more on the obsessed end of the spectrum when it comes to contributing to open source software.

I find myself in a rather unique situation: Single, living alone in a small studio apartment, only taking a class or two here and there, and basically living off of small contracts. It’s not that I’m not offered big gigs, or that I couldn’t go back to school full time if I really wanted to, I just find I enjoy living a simple lifestyle that lets me spend a lot of time on community oriented projects, especially Ruby stuff.

Right now, I need to do some work each month to pay the rent, and slowly save up to make sure I don’t get evicted during a slow work month. Between BTree and Madriska, I could say that I have two of the most open source friendly commercial relationships I’ve ever seen. Though I’m working on real projects with them, things that have to actually fit some sort of business need, they give me a lot of leeway to improve open source software while working on them, Ruport is pushed along heavily by this.

I could see myself doing that for a while. Working with a few different clients I trust, who in turn hook me up with interesting projects for a variety of companies in various different domains. A lot of it might be Rails work, but not all of it is. Still, in a moment of idealistic fantasy, I thought of another idea:

What if I could just do open source for a while, non-commercially?

How much would it cost for me to do at least 80 hours a month of development on software projects such as PDF::Writer, Ruport, and some other projects I wish I had the time to get my hands on?

I did the math, and the number came out low (subjective). I could meet all my expenses and save some money for about $2000 a month. Basically, if 200 people donated $60 right now, I could take 6 months off and do nearly 500 hours of work, and that’s only if I didn’t find myself obsessed with and doing extra hours on a project. I could more-or-less maintain my lifestyle that I have now, but not take on contracting projects that are either too big or too small out of necessity. Sure, this works out to be a lot lower than my contracting rate, but I could hack entirely on open source projects, maybe write some documentation and articles, and still be able to afford a class or two a semester. Sounds beautiful to me, though I’m sure it’s just a fantasy.

Indulging me for the moment, how would I remain accountable to anyone who supported such a venture? I’d make it transparent as possible. I’d record public hours, with links to changesets, tickets, blog posts, whatever. Though people would have to accept good faith (with at least a roughly outlined plan) as to ‘where I direct the time’, they’d get to see every bit of ‘where the hours went’.

What prevents this from being a total scam? You do. Though I don’t have some A-List reputation, I still make my living based on my reputation as a developer and a contractor. If I somehow totally screwed people who supported such an effort, all it would take would be enough negative feedback from the community to prevent me from getting away with dishonesty.

What would indicate a great success? If after 6 months, this all worked out, and I was interested in doing it for another 6 months, if people funded it, we’d know they actually liked what I did the first time around.

Finally, this doesn’t have to be me. It could be any old hacker you choose, someone you trust that’s working on things you’re interested in. They’d tell you how much it’d cost to have them quit their day job for 6 months, and hopefully people could pool resources. Though the open source community is kept alive by small day to day contributions, we all know the power of having someone dedicated to a project with copious free time.

I’m talking in theory, because obviously there are some complications. If I personally were to do this, I’d need to cycle out of some projects, and figure out to what extent it’d piss of the people I work with. Still, I am sort of curious, is this an idea that belongs in the trashbin, or should I open up a pledgie account for donations? :)

Maybe this is something that could be done on a trial basis, such as ‘40 hrs over 1 month’. This is something I could do without putting a close to all my work. Given that, based on my needs (not my billable rate), that’d be um… 10 dollars from 100 people?

On the one hand, this seems almost like a joke to me, a sort of ‘wouldn’t it be nice if…’. Still, if some respected Rubyist wanted to steal this idea, undercut me on the price, and ask people to start donating, would I be among them? You bet ya.

Let me know what you think. I’ve tried so hard over the last few years to find ethical and practical ways to work in open source development, and they pretty much work. But because of that, I’ve mostly ignored the idealistic ones, and this is just a shot in the dark at one of those.

AddThis Social Bookmark Button

The Problem

I find Ruby’s current warning system, if you can call it that, lacking. Warnings are controlled by the -W flag on the command line, and are generated via the Kernel#warn method within code. There are a host of problems with this approach to warnings.