What is Toluu?
Toluu is a free service for sharing the feeds you read and discovering new ones.
Get Invite

hackety org

filling your pockets & hat with code


A Costly ParadeToday

Adam Wiggins: First, Rubyists love elegance.

Daniel Lyons: Every programmer worth a damn thinks they love elegance.

Rubyists love life. Boy, I tell you. They love humans. They love cars!! They looooooove dishes of real, actual food. You don’t even know. Airplanes in mid-air, refueling? They love that!

But, more importantly, Rubyists love pups. Baby dogs, man! Ever heard of em? Little dogs rock!!

Okay, wait, no. No, please hold, I can’t seem to find a citation for that. I mean, speaking for myself, I definitely like dogs. And I’ve heard tell of dogs in other places… Okay, well, how about, yeah, yeah here, let’s say a tentative yellow light interest in dogs. And we’ll green light that puppy if the blogosphere goes all taggy on us and there’s like a thousand delicious tags on this post that say rooby-roo!


Rich Kilmer: I propose that we demand civility in the Ruby and Rails community.

Matt Todd: When we’

Something Like PyArg_ParseTuple For RubyNovember 17

Calling into Ruby from C is great, but I’ve noticed that I spend a lot of time casting arguments coming into each function.

rb_scan_args(argc, argv, "11", &port, &opts); if (rb_respond_to(port, rb_intern("to_str")) StringValue(port); else if (!rb_respond_to(port, rb_intern("read"))) rb_raise(rb_eArgError, "a String or IO object only, please"); if (TYPE(opts) != T_HASH && !NIL_P(opts)) rb_raise(rb_eArgError, "options must be a hash");

Ruby is dynamically typed, but object types are a bit more reified in C. The TYPE macro can check an object to see if it’s a T_FIXNUM, T_HASH, T_STRING, T_ICLASS, etc. You can duck type all you want, but when you’re inside an extension, you’ll need to know the type before calling rb_str_cat or rb_hash_aref.

And StringValue does this, it’ll cast using to_str and then make sure you’ve actually a real T_STRING.


I’m disappointed with rb_scan_args. It’s wimpy. The function signatures it uses aren’t very expressive. It’s basically describing arity and that’s it.

One thing I like better in Python’s API, though, is the PyArg_ParseTuple function and its cousins.

const char *file; const char *mode = "r"; int bufsize = 0; ok = PyArg_ParseTuple(args, "s|si", &file, &mode, &bufsize); /* A string, and optionally another string and an integer */ /* Possible Python calls:
Hpricot Strikes BackNovember 3

My my. How the sensationalist press does carry on.

Peter Cooper: On an Hpricot vs Nokogiri benchmark, Nokogiri clocked in at 7 times faster at initially loading an XML document, 5 times faster at searching for content based on an XPath, and 1.62 times faster at searching for content via a CSS-based search. These are impressive results, since Hpricot was previously considered to be quite speedy itself.

I feel just awful (just supreeeeemely lousy) that these benchmarks were only good for four days. Nokogiri is no longer seven times faster than Hpricot.

And that means these guys have to go back through all their docs and promotional materials and… wow, what a job it’s going be. It’s just a tough situation, folks. My heart goes out to all the fine young lads who worked so hard to bring Hpricot down, only to discover, hey, boss, there she goes! Hpricot is strolling right along the boardwalk, smiling, waving, checking its watch, fit as a fiddle.

This fruit is tiny, shiny and can be spit-polished in a single weekend.


Before we get to the news… Here’s the XML those Nokogiri benchmarks are based on:

Mixing Our Way Out Of Instance Eval?October 6

The lynchpin of Ruby’s pidgins and so-called DSLs (Douchebaggery as a Second Language) is the method known as instance_eval.

From an article titled Ruby DSL Blocks:

def self.order(&block) order = Order.new order.instance_eval(&block) return order.drinks end

And another one Implementing an internal DSL in Ruby:

def Expectations(&block) Expectations::Suite.instance.instance_eval(&block) end

From Creating DSLs with Ruby:

class MyDSL def define_parameters yield self end def self.load(filename) dsl = new dsl.instance_eval(File.read(filename), filename) dsl end end#class MyDSL

So far, so good? Most often instance_eval is used, but you’ll see module_eval, too.


Now, the reason for this.

Jim Weirich: Within the builder code blocks, any method call with an implicit object target needs to be sent to our builder. To achieve this, the code blocks are evaluated with instance_eval which changes the value of self to be the builder.

He goes on to say why this could be troubling.

This

Textarea Resize And Curly Quotes For ConkerorSeptember 27

People say Google Chrome is a step behind Firefox because Firefox has addons. Well, excuse me, but Firefox was already a step behind Conkeror and Vimperator! Making Google Chrome a whopping TWO steps behind. (But I’m sure we’re all another full step behind some completely obscure browser which only runs on Plan 9 and is being ported to the Erlang VM.)

Here are a few Conkeror hacks that can be easily dropped into your ~/.conkerorrc. (If you need a introduction to Conkeror, see Conkeror Comes Unstuck.)


function resize_textarea_up(field) { var h = field.offsetHeight; if (h > 120) field.style.height = (h - 60) + "px"; } function resize_textarea_down(field) { field.style.height = (parseInt(field.offsetHeight) + 60) + "px"; } interactive( "resize-textarea-up", "Resize a textarea to be smaller.", function (I) call_on_focused_field(I, resize_textarea_up) ); interactive( "resize-textarea-down", "Resize a textarea to be taller.", function (I) call_on_focused_field(I, resize_textarea_down) ); define_key(content_buffer_textarea_keymap, "C-up", "resize-textarea-up", $category = "Movement"); define_key(content_buffer_textarea_keymap, "C-down", "resize-textarea-down", $category = "Movement");

This one enables Ctrl-Up and Ctrl-Down inside a textarea. So you can stretch the box without reaching for the mouse. How about that!