Rubyholic and hCal Microformat

Eric Hodel | Fri, 31 Mar 2006 11:17:00 GMT

At SXSW I attended a panel on microformats which are a way of embedding other formats into HTML using semantic classes.

When we first wrote Rubyholic we talked about adding iCal support, but thought it would be a big pain to implement. The hCal microformat along with Technorati’s Events Feed Service made it nearly painless, so now Rubyholic groups now have calendars!

You can subscribe to a Rubyholic calendar on any group page from the link at the bottom of the schedule. For example, here’s the calendar for the Seattle Ruby Brigade.

Posted in , ,  | 1 comment

IMAPCleanse

Eric Hodel | Wed, 29 Mar 2006 06:38:40 GMT

I am a lazy person. I don’t like to delete my mailing list mail. I don’t need any of them, there’s a copy of all the mailing list mails somewhere on the internet. But since I’m lazy I never clean out my mailing list mail boxes.

So I used Net::IMAP and wrote IMAPCleanse to automatically clean out my mailing list mailboxes of messages older than a threshold that are read and not flagged. (So if I flag a message it’ll stay around forever.)

You can install IMAPCleanse as a gem:

$ sudo gem install IMAPCleanse

And read all about how to use it in the RDoc.

The only problem I had was that Net::IMAP didn’t support PLAIN authentication over SSL, so I added that. (I need to whip up some patches for Net::IMAP and fold it back in.)

Posted in , ,  | no comments

Ruby Obfuscator update

Eric Hodel | Tue, 21 Mar 2006 08:06:00 GMT

Ryan writes about our accomplishments in our most recent Ruby obfuscator hacking session.

I must add that making blocks work will continue to be a pain the way we’ve implemented obfuscation. The interpreter gets to cheat because it has the AST lying around. We don’t so we’d either have to rebuild it (too fragile to consider) or build a chunk of AST that calls back to C (still fragile). We went with a simple to implement approach that isn’t as forgiving for users but won’t fail when you switch Ruby versions.

Posted in , , ,  | no comments

attr vs method vs define_method

Eric Hodel | Tue, 07 Mar 2006 00:59:00 GMT

There are four different ways to define a method in Ruby. The two most common is the def keyword and the Module#attr family of methods. The last two ways use Module#define_method, define_method with a block and define_method with a Method object.

Ruby's interpreter handles methods created with each of these constructs differently and you can really notice it when benchmarking them:

                             user     system      total        real
attr_writer              0.880000   0.010000   0.890000 (  0.919265)
regular method           1.370000   0.000000   1.370000 (  1.485922)
define_method w/method   2.470000   0.010000   2.480000 (  2.636708)
define_method w/block    3.030000   0.020000   3.050000 (  3.268494)
Read more...

Posted in

String interpolation in ruby2c

Eric Hodel | Sat, 04 Mar 2006 07:27:00 GMT

The toolset zenspider and I built into ParseTree for rewriting Ruby’s AST allows us to make features work that otherwise would be very difficult by rewriting them into easier to implement features.

One feature that makes Ruby so clean is string interpolation but currently ruby2c doesn’t support it. In Ruby there are two types of String nodes, a plain :str node ([:str, "mystring"]) for regular strings and a :dstr node that contains all the parts of the dynamic string which the interpreter concatenates ([:dstr, "val: ", [:vcall, :val]]).

Implementing :dstr in a runtime would be too hard to be worthwhile so I used SexpProcessor to rewrite a :dstr into a series of calls to #<< and #to_s that append to the leading :str node.

Now a dynamic string like:

[:dstr,
 "a",
 [:vcall, :x],
 [:str, "b"],
 [:vcall, :y],
 [:str, "c"]]

Gets transformed into this ugly sexp:

s(:call,
  s(:call,
    s(:call,
      s(:call,
        s(:str, "a"),
          :<<,
          s(:arglist,
            s(:call, s(:call, nil, :x, nil), :to_s, nil))),
        :<<,
        s(:arglist,
          s(:call, s(:str, "b"), :to_s, nil))),
      :<<,
      s(:arglist,
        s(:call, s(:call, nil, :y, nil), :to_s, nil))),
    :<<,
    s(:arglist,
      s(:call, s(:str, "c"), :to_s, nil)))

I don’t know about the inside-outness of it though, I may have to fix that.

Posted in , ,

Bob's Favorite Scripting Language

Eric Hodel | Sun, 26 Feb 2006 00:39:00 GMT

Perl is so incomprehensible. I definitely like Ruby better than Perl as my favorite scripting language….

Bob

Posted in

Rubygems + ri

Eric Hodel | Thu, 23 Feb 2006 11:42:00 GMT

I’ve almost finished doing what has previously been claimed as impossible. I’ve cleanly integrated ri and Rubygems so that you can use ri to search your installed gems’ documentation.

The first part was simple, tell Rubygems to generate ri data for its gems. Rather than have Rubygems install a gem’s ri data mixed-in with the standard library’s data it installs it into a per-gem directory.

The unfinished part is getting a patch into Ruby that makes ri go looking in the gem ri data directories. That patch is in [ruby-core:7423]. Hopefully I can push it into 1.8 so it will be usable with Rubygems 0.9.

Posted in , ,

Undefined method for Symbol on OS X

Eric Hodel | Mon, 20 Feb 2006 02:02:00 GMT

For the past few months people have been getting messages looking like undefined method `push’ for :compact!:Symbol (NoMethodError) when using DRb on OS X.

Eventually a simpler example of the problem showed up and in [ruby-core:7305] Mauricio Fernandez thought it could be either OS X’s malloc() alignment or the address at which malloc() first returns memory.

Today I decided to figure out what the real problem was. Apple’s documentation showed that malloc() gives you regions of memory aligned on 16 byte boundaries removing the possibility of an alignment problem.

That left only the second possibility, that malloc() on OS X returns memory lower than on most *NIX platforms.

It turns out that low addresses returned by OS X’s malloc() is the culprit. In Ruby a Symbol’s ID is mapped onto a VALUE in memory by sym = ID << 8 | 0x0e so a Symbol’s object_id ends up being a low address, typically outside the range of valid VALUEs.

On FreeBSD it takes many Symbols for a Symbol to overlap a real VALUE since malloc() first returns addresses up around 0×400000. OS X, however, returns addresses around 0xd0000 so it is already overlapping the built-in set of symbols:

p :x.object_id.to_s(16)
p Object.new.object_id.to_s(16)

On OS X:

<samp>"26e90e" 
"e7bce"</samp>

The object_id of a newly created objects is already less than the first newly created Symbol. (New objects will first decrease in object_id, then jump up when the next Ruby heap section is allocated.)

On FreeBSD:

<samp>"26910e" 
"403b536"</samp>

Here the first object is well above the first Symbol, so we won’t have to worry about anything until we’ve generated a lot of Symbols.

The full example is in [ruby-core:7401].

Posted in ,

I was right!

Eric Hodel | Fri, 17 Feb 2006 10:28:00 GMT

Super-easy!

Except that Rubygems has methods that don’t get called when you think they should.

And that there’s a strange bug in RDoc when you run it twice.

Posted in , , ,

ri for Rubygems will be easy!

Eric Hodel | Fri, 17 Feb 2006 08:44:00 GMT

Something simple as:

begin
  require 'rubygems'
  Dir["#{Gem.path}/gems/*/ri"].each do |path|
    RI::Paths::PATH << path
  end
rescue LoadError
end

Posted in , ,

Older posts: 1 ... 5 6 7 8